git-rev-list: fix "--dense" flag
Right now --dense will _always_ show the root commit. I didn't do the logic that does the diff against an empty tree. I was lazy. This patch does that. The first round was incorrect but this patch is even slightly tested, and might do a better job. Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Oct 25, 2005 at 11:50 UTC
129adf4d668d04c875bfd7207ba60547b066d5af
1 file changed
+43
-8
rev-list.c
+43
-8
@@ -81,23 +81,28 @@ static void show_commit(struct commit *commit)
81
fflush(stdout);
82
}
83
84
-static void rewrite_one(struct commit **pp)
84
+static int rewrite_one(struct commit **pp)
85
{
86
for (;;) {
87
struct commit *p = *pp;
88
if (p->object.flags & (TREECHANGE | UNINTERESTING))
89
- return;
90
- /* Only single-parent commits don't have TREECHANGE */
89
+ return 0;
90
+ if (!p->parents)
91
+ return -1;
92
*pp = p->parents->item;
93
}
94
}
95
96
static void rewrite_parents(struct commit *commit)
97
{
97
- struct commit_list *parent = commit->parents;
98
- while (parent) {
99
- rewrite_one(&parent->item);
100
- parent = parent->next;
98
+ struct commit_list **pp = &commit->parents;
99
+ while (*pp) {
100
+ struct commit_list *parent = *pp;
101
+ if (rewrite_one(&parent->item) < 0) {
102
+ *pp = parent->next;
103
+ continue;
104
+ }
105
+ pp = &parent->next;
106
}
107
}
108
@@ -439,6 +444,30 @@ static int same_tree(struct tree *t1, struct tree *t2)
444
return !is_different;
445
}
446
447
+static int same_tree_as_empty(struct tree *t1)
448
+{
449
+ int retval;
450
+ void *tree;
451
+ struct tree_desc empty, real;
452
+
453
+ if (!t1)
454
+ return 0;
455
+
456
+ tree = read_object_with_reference(t1->object.sha1, "tree", &real.size, NULL);
457
+ if (!tree)
458
+ return 0;
459
+ real.buf = tree;
460
+
461
+ empty.buf = "";
462
+ empty.size = 0;
463
+
464
+ is_different = 0;
465
+ retval = diff_tree(&empty, &real, "", &diff_opt);
466
+ free(tree);
467
+
468
+ return retval >= 0 && !is_different;
469
+}
470
+
471
static struct commit *try_to_simplify_merge(struct commit *commit, struct commit_list *parent)
472
{
473
if (!commit->tree)
@@ -523,11 +552,17 @@ static void compress_list(struct commit_list *list)
552
struct commit_list *parent = commit->parents;
553
list = list->next;
554
555
+ if (!parent) {
556
+ if (!same_tree_as_empty(commit->tree))
557
+ commit->object.flags |= TREECHANGE;
558
+ continue;
559
+ }
560
+
561
/*
562
* Exactly one parent? Check if it leaves the tree
563
* unchanged
564
*/
530
- if (parent && !parent->next) {
565
+ if (!parent->next) {
566
struct tree *t1 = commit->tree;
567
struct tree *t2 = parent->item->tree;
568
if (!t1 || !t2 || same_tree(t1, t2))