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

sort_in_topological_order(): avoid setting a commit flag

We used to set the TOPOSORT flag of commits during the topological sorting, but we can just as well use the member "indegree" for it: indegree is now incremented by 1 in the cases where the commit used to have the TOPOSORT flag. This is the same behavior as before, since indegree could not be non-zero when TOPOSORT was unset. Incidentally, this fixes the bug in show-branch where the 8th column was not shown: show-branch sorts the commits in topological order, assuming that all the commit flags are available for show-branch's private matters. But this was not true: TOPOSORT was identical to the flag corresponding to the 8th ref. So the flags for the 8th column were unset by the topological sorting. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 23, 2008 at 01:51 UTC e358f3c31e1ae9f653e9b2a6be69f5df53b4ba7e
3 files changed +8 -10
commit.c
+6 -7
@@ -436,8 +436,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
436 /* Mark them and clear the indegree */
437 for (next = orig; next; next = next->next) {
438 struct commit *commit = next->item;
439 - commit->object.flags |= TOPOSORT;
440 - commit->indegree = 0;
439 + commit->indegree = 1;
440 }
441
442 /* update the indegree */
@@ -446,7 +445,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
445 while (parents) {
446 struct commit *parent = parents->item;
447
449 - if (parent->object.flags & TOPOSORT)
448 + if (parent->indegree)
449 parent->indegree++;
450 parents = parents->next;
451 }
@@ -464,7 +463,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
463 for (next = orig; next; next = next->next) {
464 struct commit *commit = next->item;
465
467 - if (!commit->indegree)
466 + if (commit->indegree == 1)
467 insert = &commit_list_insert(commit, insert)->next;
468 }
469
@@ -486,7 +485,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
485 for (parents = commit->parents; parents ; parents = parents->next) {
486 struct commit *parent=parents->item;
487
489 - if (!(parent->object.flags & TOPOSORT))
488 + if (!parent->indegree)
489 continue;
490
491 /*
@@ -494,7 +493,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
493 * when all their children have been emitted thereby
494 * guaranteeing topological order.
495 */
497 - if (!--parent->indegree) {
496 + if (--parent->indegree == 1) {
497 if (!lifo)
498 insert_by_date(parent, &work);
499 else
@@ -505,7 +504,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
504 * work_item is a commit all of whose children
505 * have already been emitted. we can emit it now.
506 */
508 - commit->object.flags &= ~TOPOSORT;
507 + commit->indegree = 0;
508 *pptr = work_item;
509 pptr = &work_item->next;
510 }
revision.h
+1 -2
@@ -12,8 +12,7 @@
12 #define CHILD_SHOWN (1u<<6)
13 #define ADDED (1u<<7) /* Parents already parsed and added? */
14 #define SYMMETRIC_LEFT (1u<<8)
15 -#define TOPOSORT (1u<<9) /* In the active toposort list.. */
16 -#define ALL_REV_FLAGS ((1u<<10)-1)
15 +#define ALL_REV_FLAGS ((1u<<9)-1)
16
17 struct rev_info;
18 struct log_info;
t/t3202-show-branch-octopus.sh
+1 -1
@@ -49,7 +49,7 @@ cat > expect << EOF
49 +++++++++* [branch10^] initial
50 EOF
51
52 -test_expect_failure 'show-branch with more than 8 branches' '
52 +test_expect_success 'show-branch with more than 8 branches' '
53
54 git show-branch $(for i in $numbers; do echo branch$i; done) > out &&
55 test_cmp expect out