revision: make tree comparison functions take commits rather than trees
This will make it easier to do various clever things that don't depend on the pure tree contents. It also makes the parameter passing much simpler - the callers doesn't really look at trees anywhere else, and it's really the function that should look at the low-level details. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Nov 3, 2008 at 10:45 UTC
3a5e860815010e362c746aedf7981e9b3b9a69e8
1 file changed
+9
-5
revision.c
+9
-5
@@ -294,8 +294,11 @@ static void file_change(struct diff_options *options,
294
DIFF_OPT_SET(options, HAS_CHANGES);
295
}
296
297
-static int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
297
+static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct commit *commit)
298
{
299
+ struct tree *t1 = parent->tree;
300
+ struct tree *t2 = commit->tree;
301
+
302
if (!t1)
303
return REV_TREE_NEW;
304
if (!t2)
@@ -308,12 +311,13 @@ static int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree
311
return tree_difference;
312
}
313
311
-static int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
314
+static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
315
{
316
int retval;
317
void *tree;
318
unsigned long size;
319
struct tree_desc empty, real;
320
+ struct tree *t1 = commit->tree;
321
322
if (!t1)
323
return 0;
@@ -347,7 +351,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
351
return;
352
353
if (!commit->parents) {
350
- if (rev_same_tree_as_empty(revs, commit->tree))
354
+ if (rev_same_tree_as_empty(revs, commit))
355
commit->object.flags |= TREESAME;
356
return;
357
}
@@ -367,7 +371,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
371
die("cannot simplify commit %s (because of %s)",
372
sha1_to_hex(commit->object.sha1),
373
sha1_to_hex(p->object.sha1));
370
- switch (rev_compare_tree(revs, p->tree, commit->tree)) {
374
+ switch (rev_compare_tree(revs, p, commit)) {
375
case REV_TREE_SAME:
376
tree_same = 1;
377
if (!revs->simplify_history || (p->object.flags & UNINTERESTING)) {
@@ -387,7 +391,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
391
392
case REV_TREE_NEW:
393
if (revs->remove_empty_trees &&
390
- rev_same_tree_as_empty(revs, p->tree)) {
394
+ rev_same_tree_as_empty(revs, p)) {
395
/* We are adding all the specified
396
* paths from this parent, so the
397
* history beyond this parent is not