@matheusbsbs / matheus-bagliano / commits / 11ee57bc4c
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 11ee57bc4c44763b7ea92c5f583e27a5fbbff76b
3 files changed +65 -8
commit.c
+6 -7
@@ -428,8 +428,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
428 /* Mark them and clear the indegree */
429 for (next = orig; next; next = next->next) {
430 struct commit *commit = next->item;
431 - commit->object.flags |= TOPOSORT;
432 - commit->indegree = 0;
431 + commit->indegree = 1;
432 }
433
434 /* update the indegree */
@@ -438,7 +437,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
437 while (parents) {
438 struct commit *parent = parents->item;
439
441 - if (parent->object.flags & TOPOSORT)
440 + if (parent->indegree)
441 parent->indegree++;
442 parents = parents->next;
443 }
@@ -456,7 +455,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
455 for (next = orig; next; next = next->next) {
456 struct commit *commit = next->item;
457
459 - if (!commit->indegree)
458 + if (commit->indegree == 1)
459 insert = &commit_list_insert(commit, insert)->next;
460 }
461
@@ -478,7 +477,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
477 for (parents = commit->parents; parents ; parents = parents->next) {
478 struct commit *parent=parents->item;
479
481 - if (!(parent->object.flags & TOPOSORT))
480 + if (!parent->indegree)
481 continue;
482
483 /*
@@ -486,7 +485,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
485 * when all their children have been emitted thereby
486 * guaranteeing topological order.
487 */
489 - if (!--parent->indegree) {
488 + if (--parent->indegree == 1) {
489 if (!lifo)
490 insert_by_date(parent, &work);
491 else
@@ -497,7 +496,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
496 * work_item is a commit all of whose children
497 * have already been emitted. we can emit it now.
498 */
500 - commit->object.flags &= ~TOPOSORT;
499 + commit->indegree = 0;
500 *pptr = work_item;
501 pptr = &work_item->next;
502 }
revision.h
-1
@@ -10,7 +10,6 @@
10 #define CHILD_SHOWN (1u<<6)
11 #define ADDED (1u<<7) /* Parents already parsed and added? */
12 #define SYMMETRIC_LEFT (1u<<8)
13 -#define TOPOSORT (1u<<9) /* In the active toposort list.. */
13
14 struct rev_info;
15 struct log_info;
t/t3202-show-branch-octopus.sh new
+59
@@ -0,0 +1,59 @@
1 +#!/bin/sh
2 +
3 +test_description='test show-branch with more than 8 heads'
4 +
5 +. ./test-lib.sh
6 +
7 +numbers="1 2 3 4 5 6 7 8 9 10"
8 +
9 +test_expect_success 'setup' '
10 +
11 + > file &&
12 + git add file &&
13 + test_tick &&
14 + git commit -m initial &&
15 +
16 + for i in $numbers
17 + do
18 + git checkout -b branch$i master &&
19 + > file$i &&
20 + git add file$i &&
21 + test_tick &&
22 + git commit -m branch$i || break
23 + done
24 +
25 +'
26 +
27 +cat > expect << EOF
28 +! [branch1] branch1
29 + ! [branch2] branch2
30 + ! [branch3] branch3
31 + ! [branch4] branch4
32 + ! [branch5] branch5
33 + ! [branch6] branch6
34 + ! [branch7] branch7
35 + ! [branch8] branch8
36 + ! [branch9] branch9
37 + * [branch10] branch10
38 +----------
39 + * [branch10] branch10
40 + + [branch9] branch9
41 + + [branch8] branch8
42 + + [branch7] branch7
43 + + [branch6] branch6
44 + + [branch5] branch5
45 + + [branch4] branch4
46 + + [branch3] branch3
47 + + [branch2] branch2
48 ++ [branch1] branch1
49 ++++++++++* [branch10^] initial
50 +EOF
51 +
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
56 +
57 +'
58 +
59 +test_done