Skip to content

Commit

Permalink
diff: futureproof "stop feeding the backend early" logic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed May 31, 2011
1 parent af7b41c commit 28b9264
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 1 addition & 3 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
struct cache_entry *ce = active_cache[i];
int changed;

if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
!revs->diffopt.filter &&
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
if (diff_can_quit_early(&revs->diffopt))
break;

if (!ce_path_match(ce, revs->prune_data))
Expand Down
7 changes: 7 additions & 0 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3513,6 +3513,13 @@ int diff_result_code(struct diff_options *opt, int status)
return result;
}

int diff_can_quit_early(struct diff_options *opt)
{
return (DIFF_OPT_TST(opt, QUICK) &&
!opt->filter &&
DIFF_OPT_TST(opt, HAS_CHANGES));
}

void diff_addremove(struct diff_options *options,
int addremove, unsigned mode,
const unsigned char *sha1,
Expand Down
2 changes: 2 additions & 0 deletions diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_

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

extern int diff_can_quit_early(struct diff_options *);

extern void diff_addremove(struct diff_options *,
int addremove,
unsigned mode,
Expand Down
4 changes: 1 addition & 3 deletions tree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
int baselen = strlen(base);

for (;;) {
if (DIFF_OPT_TST(opt, QUICK) &&
!opt->filter &&
DIFF_OPT_TST(opt, HAS_CHANGES))
if (diff_can_quit_early(opt))
break;
if (opt->nr_paths) {
skip_uninteresting(t1, base, baselen, opt);
Expand Down

0 comments on commit 28b9264

Please sign in to comment.