@matheusbsbs / matheus-bagliano / commits / 1b9e059d35
Fork 0

git-rev-list: add "--dense" flag

This is what the recent git-rev-list changes have all been gearing up for. When we use a path filter to git-rev-list, the new "--dense" flag asks git-rev-list to compress the history so that it _only_ contains commits that change files in the path filter. It also rewrites the parent information so that tools like "gitk" will see the result as a dense history tree. For example, on the current kernel archive: [torvalds@g5 linux]$ git-rev-list HEAD | wc -l 9904 [torvalds@g5 linux]$ git-rev-list HEAD -- kernel | wc -l 5442 [torvalds@g5 linux]$ git-rev-list --dense HEAD -- kernel | wc -l 356 which shows that while we have almost ten thousand commits, we can prune down the work to slightly more than half by only following the merges that are interesting. But further, we can then compress the history to just 356 entries that actually make changes to the kernel subdirectory. To see this in action, try something like gitk --dense -- gitk to see just the history that affects gitk. Or, to show that true parallel development still remains parallel, do gitk --dense -- daemon.c which shows some parallel commits in the current git tree. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 21, 2005 at 16:40 UTC 1b9e059d3503f935bb3eebb073cfb0f0401e2adf
1 file changed +63 -5
rev-list.c
+63 -5
@@ -11,6 +11,7 @@
11 #define INTERESTING (1u << 1)
12 #define COUNTED (1u << 2)
13 #define SHOWN (1u << 3)
14 +#define TREECHANGE (1u << 4)
15
16 static const char rev_list_usage[] =
17 "git-rev-list [OPTION] commit-id <commit-id>\n"
@@ -27,6 +28,7 @@ static const char rev_list_usage[] =
28 " --merge-order [ --show-breaks ]\n"
29 " --topo-order";
30
31 +static int dense = 0;
32 static int unpacked = 0;
33 static int bisect_list = 0;
34 static int tag_objects = 0;
@@ -79,6 +81,26 @@ static void show_commit(struct commit *commit)
81 fflush(stdout);
82 }
83
84 +static void 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 */
91 + *pp = p->parents->item;
92 + }
93 +}
94 +
95 +static void rewrite_parents(struct commit *commit)
96 +{
97 + struct commit_list *parent = commit->parents;
98 + while (parent) {
99 + rewrite_one(&parent->item);
100 + parent = parent->next;
101 + }
102 +}
103 +
104 static int filter_commit(struct commit * commit)
105 {
106 if (stop_traversal && (commit->object.flags & BOUNDARY))
@@ -95,6 +117,11 @@ static int filter_commit(struct commit * commit)
117 return STOP;
118 if (no_merges && (commit->parents && commit->parents->next))
119 return CONTINUE;
120 + if (paths && dense) {
121 + if (!(commit->object.flags & TREECHANGE))
122 + return CONTINUE;
123 + rewrite_parents(commit);
124 + }
125 return DO;
126 }
127
@@ -404,6 +431,14 @@ static struct diff_options diff_opt = {
431 .change = file_change,
432 };
433
434 +static int same_tree(struct tree *t1, struct tree *t2)
435 +{
436 + is_different = 0;
437 + if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", &diff_opt) < 0)
438 + return 0;
439 + return !is_different;
440 +}
441 +
442 static struct commit *try_to_simplify_merge(struct commit *commit, struct commit_list *parent)
443 {
444 if (!commit->tree)
@@ -415,11 +450,7 @@ static struct commit *try_to_simplify_merge(struct commit *commit, struct commit
450 parse_commit(p);
451 if (!p->tree)
452 continue;
418 - is_different = 0;
419 - if (diff_tree_sha1(commit->tree->object.sha1,
420 - p->tree->object.sha1, "", &diff_opt) < 0)
421 - continue;
422 - if (!is_different)
453 + if (same_tree(commit->tree, p->tree))
454 return p;
455 }
456 return NULL;
@@ -485,6 +516,27 @@ static void add_parents_to_list(struct commit *commit, struct commit_list **list
516 }
517 }
518
519 +static void compress_list(struct commit_list *list)
520 +{
521 + while (list) {
522 + struct commit *commit = list->item;
523 + struct commit_list *parent = commit->parents;
524 + list = list->next;
525 +
526 + /*
527 + * Exactly one parent? Check if it leaves the tree
528 + * unchanged
529 + */
530 + if (parent && !parent->next) {
531 + struct tree *t1 = commit->tree;
532 + struct tree *t2 = parent->item->tree;
533 + if (!t1 || !t2 || same_tree(t1, t2))
534 + continue;
535 + }
536 + commit->object.flags |= TREECHANGE;
537 + }
538 +}
539 +
540 static struct commit_list *limit_list(struct commit_list *list)
541 {
542 struct commit_list *newlist = NULL;
@@ -514,6 +566,8 @@ static struct commit_list *limit_list(struct commit_list *list)
566 }
567 if (tree_objects)
568 mark_edges_uninteresting(newlist);
569 + if (paths && dense)
570 + compress_list(newlist);
571 if (bisect_list)
572 newlist = find_bisection(newlist);
573 return newlist;
@@ -700,6 +754,10 @@ int main(int argc, const char **argv)
754 limited = 1;
755 continue;
756 }
757 + if (!strcmp(arg, "--dense")) {
758 + dense = 1;
759 + continue;
760 + }
761 if (!strcmp(arg, "--")) {
762 paths = get_pathspec(prefix, argv + i + 1);
763 if (paths) {