@matheusbsbs / matheus-bagliano / commits / dd47aa3133
Fork 0

try-to-simplify-commit: use diff-tree --quiet machinery.

This uses diff-tree --quiet machinery to terminate the internal diff-tree between a commit and its parents via revs.pruning (not revs.diffopt) as soon as we find enough about the tree change. With respect to the optionally given pathspec, we are interested if the tree of commit is identical to the parent's, only adds new paths to the parent's, or there are other differences. As soon as we find out that there is one such other kind of difference, we do not have to compare the rest of the tree. Because we do not call standard diff_addremove/diff_change, we instruct the diff-tree machinery to stop early by setting has_changes when we say we found the trees to be different. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 14, 2007 at 13:18 UTC dd47aa31339d2b8acdf909fd0067544c31cd9358
1 file changed +6
revision.c
+6
@@ -243,6 +243,8 @@ static void file_add_remove(struct diff_options *options,
243 diff = REV_TREE_NEW;
244 }
245 tree_difference = diff;
246 + if (tree_difference == REV_TREE_DIFFERENT)
247 + options->has_changes = 1;
248 }
249
250 static void file_change(struct diff_options *options,
@@ -252,6 +254,7 @@ static void file_change(struct diff_options *options,
254 const char *base, const char *path)
255 {
256 tree_difference = REV_TREE_DIFFERENT;
257 + options->has_changes = 1;
258 }
259
260 int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
@@ -261,6 +264,7 @@ int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
264 if (!t2)
265 return REV_TREE_DIFFERENT;
266 tree_difference = REV_TREE_SAME;
267 + revs->pruning.has_changes = 0;
268 if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "",
269 &revs->pruning) < 0)
270 return REV_TREE_DIFFERENT;
@@ -285,6 +289,7 @@ int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
289 empty.size = 0;
290
291 tree_difference = REV_TREE_SAME;
292 + revs->pruning.has_changes = 0;
293 retval = diff_tree(&empty, &real, "", &revs->pruning);
294 free(tree);
295
@@ -552,6 +557,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
557 revs->ignore_merges = 1;
558 revs->simplify_history = 1;
559 revs->pruning.recursive = 1;
560 + revs->pruning.quiet = 1;
561 revs->pruning.add_remove = file_add_remove;
562 revs->pruning.change = file_change;
563 revs->lifo = 1;