Merge branch 'jk/revision-pruning-optim'
authorJunio C Hamano <gitster@pobox.com>
Mon, 6 Nov 2017 05:24:26 +0000 (14:24 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Nov 2017 05:24:26 +0000 (14:24 +0900)
Pathspec-limited revision traversal was taught not to keep finding
unneeded differences once it knows two trees are different inside
given pathspec.

* jk/revision-pruning-optim:
revision: quit pruning diff more quickly when possible

diff.h
revision.c
diff --git a/diff.h b/diff.h
index aca150ba2e0f0b0a984e7f15c292af5f5b057d61..398b87b4cf0fe06010ed20320d55c1803dfc3331 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -180,6 +180,7 @@ struct diff_options {
        pathchange_fn_t pathchange;
        change_fn_t change;
        add_remove_fn_t add_remove;
+       void *change_fn_data;
        diff_format_fn_t format_callback;
        void *format_callback_data;
        diff_prefix_fn_t output_prefix;
index d167223e694e54626786740954454d4973e28752..99c95c19b0093094878bdae02a22944fd2aeff37 100644 (file)
@@ -395,8 +395,16 @@ static struct commit *one_relevant_parent(const struct rev_info *revs,
  * if the whole diff is removal of old data, and otherwise
  * REV_TREE_DIFFERENT (of course if the trees are the same we
  * want REV_TREE_SAME).
- * That means that once we get to REV_TREE_DIFFERENT, we do not
- * have to look any further.
+ *
+ * The only time we care about the distinction is when
+ * remove_empty_trees is in effect, in which case we care only about
+ * whether the whole change is REV_TREE_NEW, or if there's another type
+ * of change. Which means we can stop the diff early in either of these
+ * cases:
+ *
+ *   1. We're not using remove_empty_trees at all.
+ *
+ *   2. We saw anything except REV_TREE_NEW.
  */
 static int tree_difference = REV_TREE_SAME;
 
@@ -407,9 +415,10 @@ static void file_add_remove(struct diff_options *options,
                    const char *fullpath, unsigned dirty_submodule)
 {
        int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD;
+       struct rev_info *revs = options->change_fn_data;
 
        tree_difference |= diff;
-       if (tree_difference == REV_TREE_DIFFERENT)
+       if (!revs->remove_empty_trees || tree_difference != REV_TREE_NEW)
                DIFF_OPT_SET(options, HAS_CHANGES);
 }
 
@@ -1407,6 +1416,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
        DIFF_OPT_SET(&revs->pruning, QUICK);
        revs->pruning.add_remove = file_add_remove;
        revs->pruning.change = file_change;
+       revs->pruning.change_fn_data = revs;
        revs->sort_order = REV_SORT_IN_GRAPH_ORDER;
        revs->dense = 1;
        revs->prefix = prefix;