Skip to content

Commit 28b9264

Browse files
committed
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 <[email protected]>
1 parent af7b41c commit 28b9264

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

diff-lib.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
7373
struct cache_entry *ce = active_cache[i];
7474
int changed;
7575

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))
7977
break;
8078

8179
if (!ce_path_match(ce, revs->prune_data))

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,6 +3513,13 @@ int diff_result_code(struct diff_options *opt, int status)
35133513
return result;
35143514
}
35153515

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+
35163523
void diff_addremove(struct diff_options *options,
35173524
int addremove, unsigned mode,
35183525
const unsigned char *sha1,

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_
170170

171171
void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
172172

173+
extern int diff_can_quit_early(struct diff_options *);
174+
173175
extern void diff_addremove(struct diff_options *,
174176
int addremove,
175177
unsigned mode,

tree-diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
286286
int baselen = strlen(base);
287287

288288
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))
292290
break;
293291
if (opt->nr_paths) {
294292
skip_uninteresting(t1, base, baselen, opt);

0 commit comments

Comments
 (0)