diff --git a/diff-cache.c b/diff-cache.c index 1d355aa028..13baaa3721 100644 --- a/diff-cache.c +++ b/diff-cache.c @@ -11,6 +11,7 @@ static const char *pickaxe = NULL; static int pickaxe_opts = 0; static int diff_break_opt = -1; static const char *orderfile = NULL; +static const char *diff_filter = NULL; /* A file entry went away or appeared */ static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode) @@ -224,6 +225,10 @@ int main(int argc, const char **argv) pickaxe = arg + 2; continue; } + if (!strncmp(arg, "--diff-filter=", 14)) { + diff_filter = arg + 14; + continue; + } if (!strncmp(arg, "-O", 2)) { orderfile = arg + 2; continue; @@ -263,7 +268,7 @@ int main(int argc, const char **argv) detect_rename, diff_score_opt, pickaxe, pickaxe_opts, diff_break_opt, - orderfile); - diff_flush(diff_output_format, 1); + orderfile, diff_filter); + diff_flush(diff_output_format); return ret; } diff --git a/diff-files.c b/diff-files.c index 5c895cca75..b6d972e062 100644 --- a/diff-files.c +++ b/diff-files.c @@ -17,6 +17,7 @@ static const char *pickaxe = NULL; static int pickaxe_opts = 0; static int diff_break_opt = -1; static const char *orderfile = NULL; +static const char *diff_filter = NULL; static int silent = 0; static void show_unmerge(const char *path) @@ -59,6 +60,8 @@ int main(int argc, const char **argv) pickaxe = argv[1] + 2; else if (!strncmp(argv[1], "-O", 2)) orderfile = argv[1] + 2; + else if (!strncmp(argv[1], "--diff-filter=", 14)) + diff_filter = argv[1] + 14; else if (!strcmp(argv[1], "--pickaxe-all")) pickaxe_opts = DIFF_PICKAXE_ALL; else if (!strncmp(argv[1], "-B", 2)) { @@ -131,7 +134,7 @@ int main(int argc, const char **argv) detect_rename, diff_score_opt, pickaxe, pickaxe_opts, diff_break_opt, - orderfile); - diff_flush(diff_output_format, 1); + orderfile, diff_filter); + diff_flush(diff_output_format); return 0; } diff --git a/diff-helper.c b/diff-helper.c index 04e6f2cd72..5a3198ac8e 100644 --- a/diff-helper.c +++ b/diff-helper.c @@ -8,17 +8,16 @@ static const char *pickaxe = NULL; static int pickaxe_opts = 0; static const char *orderfile = NULL; +static const char *diff_filter = NULL; static int line_termination = '\n'; static int inter_name_termination = '\t'; static void flush_them(int ac, const char **av) { - diffcore_std(av + 1, - 0, 0, /* no renames */ - pickaxe, pickaxe_opts, - -1, /* no breaks */ - orderfile); - diff_flush(DIFF_FORMAT_PATCH, 0); + diffcore_std_no_resolve(av + 1, + pickaxe, pickaxe_opts, + orderfile, diff_filter); + diff_flush(DIFF_FORMAT_PATCH); } static const char *diff_helper_usage = @@ -38,6 +37,10 @@ int main(int ac, const char **av) { } else if (!strcmp(av[1], "--pickaxe-all")) pickaxe_opts = DIFF_PICKAXE_ALL; + else if (!strncmp(av[1], "--diff-filter=", 14)) + diff_filter = av[1] + 14; + else if (!strncmp(av[1], "-O", 2)) + orderfile = av[1] + 2; else usage(diff_helper_usage); ac--; av++; diff --git a/diff-stages.c b/diff-stages.c index 0090ac00bb..78729d7812 100644 --- a/diff-stages.c +++ b/diff-stages.c @@ -13,6 +13,7 @@ static const char *pickaxe = NULL; static int pickaxe_opts = 0; static int diff_break_opt = -1; static const char *orderfile = NULL; +static const char *diff_filter = NULL; static char *diff_stages_usage = "git-diff-stages [-p] [-r] [-z] [-M] [-C] [-R] [-S] [-O] [...]"; @@ -50,6 +51,8 @@ int main(int ac, const char **av) pickaxe = arg + 2; else if (!strncmp(arg, "-O", 2)) orderfile = arg + 2; + else if (!strncmp(arg, "--diff-filter=", 14)) + diff_filter = arg + 14; else if (!strcmp(arg, "--pickaxe-all")) pickaxe_opts = DIFF_PICKAXE_ALL; else @@ -106,7 +109,8 @@ int main(int ac, const char **av) detect_rename, diff_score_opt, pickaxe, pickaxe_opts, diff_break_opt, - orderfile); - diff_flush(diff_output_format, 1); + orderfile, + diff_filter); + diff_flush(diff_output_format); return 0; } diff --git a/diff-tree.c b/diff-tree.c index a29c738cbe..2075715350 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -18,6 +18,7 @@ static const char *pickaxe = NULL; static int pickaxe_opts = 0; static int diff_break_opt = -1; static const char *orderfile = NULL; +static const char *diff_filter = NULL; static const char *header = NULL; static const char *header_prefix = ""; static enum cmit_fmt commit_format = CMIT_FMT_RAW; @@ -272,9 +273,10 @@ static int call_diff_flush(void) detect_rename, diff_score_opt, pickaxe, pickaxe_opts, diff_break_opt, - orderfile); + orderfile, + diff_filter); if (diff_queue_is_empty()) { - diff_flush(DIFF_FORMAT_NO_OUTPUT, 0); + diff_flush(DIFF_FORMAT_NO_OUTPUT); return 0; } if (header) { @@ -285,7 +287,7 @@ static int call_diff_flush(void) printf(fmt, header, 0); header = NULL; } - diff_flush(diff_output_format, 1); + diff_flush(diff_output_format); return 1; } @@ -468,6 +470,10 @@ int main(int argc, const char **argv) orderfile = arg + 2; continue; } + if (!strncmp(arg, "--diff-filter=", 14)) { + diff_filter = arg + 14; + continue; + } if (!strcmp(arg, "--pickaxe-all")) { pickaxe_opts = DIFF_PICKAXE_ALL; continue; diff --git a/diff.c b/diff.c index d6661f8268..e9936016c6 100644 --- a/diff.c +++ b/diff.c @@ -921,7 +921,7 @@ static void diff_resolve_rename_copy(void) diff_debug_queue("resolve-rename-copy done", q); } -void diff_flush(int diff_output_style, int resolve_rename_copy) +void diff_flush(int diff_output_style) { struct diff_queue_struct *q = &diff_queued_diff; int i; @@ -930,8 +930,6 @@ void diff_flush(int diff_output_style, int resolve_rename_copy) if (diff_output_style == DIFF_FORMAT_MACHINE) line_termination = inter_name_termination = 0; - if (resolve_rename_copy) - diff_resolve_rename_copy(); for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; @@ -958,11 +956,58 @@ void diff_flush(int diff_output_style, int resolve_rename_copy) q->nr = q->alloc = 0; } +static void diffcore_apply_filter(const char *filter) +{ + int i; + struct diff_queue_struct *q = &diff_queued_diff; + struct diff_queue_struct outq; + outq.queue = NULL; + outq.nr = outq.alloc = 0; + + if (!filter) + return; + + if (strchr(filter, 'A')) { + /* All-or-none */ + int found; + for (i = found = 0; !found && i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + if ((p->broken_pair && strchr(filter, 'B')) || + (!p->broken_pair && strchr(filter, p->status))) + found++; + } + if (found) + return; + + /* otherwise we will clear the whole queue + * by copying the empty outq at the end of this + * function, but first clear the current entries + * in the queue. + */ + for (i = 0; i < q->nr; i++) + diff_free_filepair(q->queue[i]); + } + else { + /* Only the matching ones */ + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + if ((p->broken_pair && strchr(filter, 'B')) || + (!p->broken_pair && strchr(filter, p->status))) + diff_q(&outq, p); + else + diff_free_filepair(p); + } + } + free(q->queue); + *q = outq; +} + void diffcore_std(const char **paths, int detect_rename, int rename_score, const char *pickaxe, int pickaxe_opts, int break_opt, - const char *orderfile) + const char *orderfile, + const char *filter) { if (paths && paths[0]) diffcore_pathspec(paths); @@ -976,6 +1021,23 @@ void diffcore_std(const char **paths, diffcore_pickaxe(pickaxe, pickaxe_opts); if (orderfile) diffcore_order(orderfile); + diff_resolve_rename_copy(); + diffcore_apply_filter(filter); +} + + +void diffcore_std_no_resolve(const char **paths, + const char *pickaxe, int pickaxe_opts, + const char *orderfile, + const char *filter) +{ + if (paths && paths[0]) + diffcore_pathspec(paths); + if (pickaxe) + diffcore_pickaxe(pickaxe, pickaxe_opts); + if (orderfile) + diffcore_order(orderfile); + diffcore_apply_filter(filter); } void diff_addremove(int addremove, unsigned mode, diff --git a/diff.h b/diff.h index c64880cdb1..9f0852d321 100644 --- a/diff.h +++ b/diff.h @@ -47,7 +47,11 @@ extern void diffcore_std(const char **paths, int detect_rename, int rename_score, const char *pickaxe, int pickaxe_opts, int break_opt, - const char *orderfile); + const char *orderfile, const char *filter); + +extern void diffcore_std_no_resolve(const char **paths, + const char *pickaxe, int pickaxe_opts, + const char *orderfile, const char *filter); extern int diff_queue_is_empty(void); @@ -56,6 +60,6 @@ extern int diff_queue_is_empty(void); #define DIFF_FORMAT_PATCH 2 #define DIFF_FORMAT_NO_OUTPUT 3 -extern void diff_flush(int output_style, int resolve_rename_copy); +extern void diff_flush(int output_style); #endif /* DIFF_H */