Skip to content

Commit e358f3c

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce567d1 commit e358f3c

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

commit.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
436436
/* Mark them and clear the indegree */
437437
for (next = orig; next; next = next->next) {
438438
struct commit *commit = next->item;
439-
commit->object.flags |= TOPOSORT;
440-
commit->indegree = 0;
439+
commit->indegree = 1;
441440
}
442441

443442
/* update the indegree */
@@ -446,7 +445,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
446445
while (parents) {
447446
struct commit *parent = parents->item;
448447

449-
if (parent->object.flags & TOPOSORT)
448+
if (parent->indegree)
450449
parent->indegree++;
451450
parents = parents->next;
452451
}
@@ -464,7 +463,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
464463
for (next = orig; next; next = next->next) {
465464
struct commit *commit = next->item;
466465

467-
if (!commit->indegree)
466+
if (commit->indegree == 1)
468467
insert = &commit_list_insert(commit, insert)->next;
469468
}
470469

@@ -486,15 +485,15 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
486485
for (parents = commit->parents; parents ; parents = parents->next) {
487486
struct commit *parent=parents->item;
488487

489-
if (!(parent->object.flags & TOPOSORT))
488+
if (!parent->indegree)
490489
continue;
491490

492491
/*
493492
* parents are only enqueued for emission
494493
* when all their children have been emitted thereby
495494
* guaranteeing topological order.
496495
*/
497-
if (!--parent->indegree) {
496+
if (--parent->indegree == 1) {
498497
if (!lifo)
499498
insert_by_date(parent, &work);
500499
else
@@ -505,7 +504,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
505504
* work_item is a commit all of whose children
506505
* have already been emitted. we can emit it now.
507506
*/
508-
commit->object.flags &= ~TOPOSORT;
507+
commit->indegree = 0;
509508
*pptr = work_item;
510509
pptr = &work_item->next;
511510
}

revision.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#define CHILD_SHOWN (1u<<6)
1313
#define ADDED (1u<<7) /* Parents already parsed and added? */
1414
#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)
1716

1817
struct rev_info;
1918
struct log_info;

t/t3202-show-branch-octopus.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cat > expect << EOF
4949
+++++++++* [branch10^] initial
5050
EOF
5151

52-
test_expect_failure 'show-branch with more than 8 branches' '
52+
test_expect_success 'show-branch with more than 8 branches' '
5353
5454
git show-branch $(for i in $numbers; do echo branch$i; done) > out &&
5555
test_cmp expect out

0 commit comments

Comments
 (0)