diff: futureproof "stop feeding the backend early" logic

Refactor the "do not stop feeding the backend early" logic into a small helper function and use it in both run_diff_files() and diff_tree() that has the stop-early optimization. We may later add other types of diffcore transformation that require to look at the whole result like diff-filter does, and having the logic in a single place is essential for longer term maintainability. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 31, 2011 at 09:14 UTC 28b9264dd6cbadcef8b3e48c24ffcb2893b668b3
4 files changed +11 -6
diff-lib.c
+1 -3
@@ -73,9 +73,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
73 struct cache_entry *ce = active_cache[i];
74 int changed;
75
76 - if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
77 - !revs->diffopt.filter &&
78 - DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
76 + if (diff_can_quit_early(&revs->diffopt))
77 break;
78
79 if (!ce_path_match(ce, revs->prune_data))
diff.c
+7
@@ -3513,6 +3513,13 @@ int diff_result_code(struct diff_options *opt, int status)
3513 return result;
3514 }
3515
3516 +int diff_can_quit_early(struct diff_options *opt)
3517 +{
3518 + return (DIFF_OPT_TST(opt, QUICK) &&
3519 + !opt->filter &&
3520 + DIFF_OPT_TST(opt, HAS_CHANGES));
3521 +}
3522 +
3523 void diff_addremove(struct diff_options *options,
3524 int addremove, unsigned mode,
3525 const unsigned char *sha1,
diff.h
+2
@@ -170,6 +170,8 @@ extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_
170
171 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
172
173 +extern int diff_can_quit_early(struct diff_options *);
174 +
175 extern void diff_addremove(struct diff_options *,
176 int addremove,
177 unsigned mode,
tree-diff.c
+1 -3
@@ -286,9 +286,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
286 int baselen = strlen(base);
287
288 for (;;) {
289 - if (DIFF_OPT_TST(opt, QUICK) &&
290 - !opt->filter &&
291 - DIFF_OPT_TST(opt, HAS_CHANGES))
289 + if (diff_can_quit_early(opt))
290 break;
291 if (opt->nr_paths) {
292 skip_uninteresting(t1, base, baselen, opt);