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>
This commit is contained in:
parent
b1264da863
commit
11ee57bc4c
13
commit.c
13
commit.c
@ -428,8 +428,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
/* Mark them and clear the indegree */
|
/* Mark them and clear the indegree */
|
||||||
for (next = orig; next; next = next->next) {
|
for (next = orig; next; next = next->next) {
|
||||||
struct commit *commit = next->item;
|
struct commit *commit = next->item;
|
||||||
commit->object.flags |= TOPOSORT;
|
commit->indegree = 1;
|
||||||
commit->indegree = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update the indegree */
|
/* update the indegree */
|
||||||
@ -438,7 +437,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
while (parents) {
|
while (parents) {
|
||||||
struct commit *parent = parents->item;
|
struct commit *parent = parents->item;
|
||||||
|
|
||||||
if (parent->object.flags & TOPOSORT)
|
if (parent->indegree)
|
||||||
parent->indegree++;
|
parent->indegree++;
|
||||||
parents = parents->next;
|
parents = parents->next;
|
||||||
}
|
}
|
||||||
@ -456,7 +455,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
for (next = orig; next; next = next->next) {
|
for (next = orig; next; next = next->next) {
|
||||||
struct commit *commit = next->item;
|
struct commit *commit = next->item;
|
||||||
|
|
||||||
if (!commit->indegree)
|
if (commit->indegree == 1)
|
||||||
insert = &commit_list_insert(commit, insert)->next;
|
insert = &commit_list_insert(commit, insert)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +477,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
for (parents = commit->parents; parents ; parents = parents->next) {
|
for (parents = commit->parents; parents ; parents = parents->next) {
|
||||||
struct commit *parent=parents->item;
|
struct commit *parent=parents->item;
|
||||||
|
|
||||||
if (!(parent->object.flags & TOPOSORT))
|
if (!parent->indegree)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -486,7 +485,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
* when all their children have been emitted thereby
|
* when all their children have been emitted thereby
|
||||||
* guaranteeing topological order.
|
* guaranteeing topological order.
|
||||||
*/
|
*/
|
||||||
if (!--parent->indegree) {
|
if (--parent->indegree == 1) {
|
||||||
if (!lifo)
|
if (!lifo)
|
||||||
insert_by_date(parent, &work);
|
insert_by_date(parent, &work);
|
||||||
else
|
else
|
||||||
@ -497,7 +496,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
|
|||||||
* work_item is a commit all of whose children
|
* work_item is a commit all of whose children
|
||||||
* have already been emitted. we can emit it now.
|
* have already been emitted. we can emit it now.
|
||||||
*/
|
*/
|
||||||
commit->object.flags &= ~TOPOSORT;
|
commit->indegree = 0;
|
||||||
*pptr = work_item;
|
*pptr = work_item;
|
||||||
pptr = &work_item->next;
|
pptr = &work_item->next;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#define CHILD_SHOWN (1u<<6)
|
#define CHILD_SHOWN (1u<<6)
|
||||||
#define ADDED (1u<<7) /* Parents already parsed and added? */
|
#define ADDED (1u<<7) /* Parents already parsed and added? */
|
||||||
#define SYMMETRIC_LEFT (1u<<8)
|
#define SYMMETRIC_LEFT (1u<<8)
|
||||||
#define TOPOSORT (1u<<9) /* In the active toposort list.. */
|
|
||||||
|
|
||||||
struct rev_info;
|
struct rev_info;
|
||||||
struct log_info;
|
struct log_info;
|
||||||
|
59
t/t3202-show-branch-octopus.sh
Executable file
59
t/t3202-show-branch-octopus.sh
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test show-branch with more than 8 heads'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
numbers="1 2 3 4 5 6 7 8 9 10"
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
|
||||||
|
> file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m initial &&
|
||||||
|
|
||||||
|
for i in $numbers
|
||||||
|
do
|
||||||
|
git checkout -b branch$i master &&
|
||||||
|
> file$i &&
|
||||||
|
git add file$i &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m branch$i || break
|
||||||
|
done
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect << EOF
|
||||||
|
! [branch1] branch1
|
||||||
|
! [branch2] branch2
|
||||||
|
! [branch3] branch3
|
||||||
|
! [branch4] branch4
|
||||||
|
! [branch5] branch5
|
||||||
|
! [branch6] branch6
|
||||||
|
! [branch7] branch7
|
||||||
|
! [branch8] branch8
|
||||||
|
! [branch9] branch9
|
||||||
|
* [branch10] branch10
|
||||||
|
----------
|
||||||
|
* [branch10] branch10
|
||||||
|
+ [branch9] branch9
|
||||||
|
+ [branch8] branch8
|
||||||
|
+ [branch7] branch7
|
||||||
|
+ [branch6] branch6
|
||||||
|
+ [branch5] branch5
|
||||||
|
+ [branch4] branch4
|
||||||
|
+ [branch3] branch3
|
||||||
|
+ [branch2] branch2
|
||||||
|
+ [branch1] branch1
|
||||||
|
+++++++++* [branch10^] initial
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'show-branch with more than 8 branches' '
|
||||||
|
|
||||||
|
git show-branch $(for i in $numbers; do echo branch$i; done) > out &&
|
||||||
|
test_cmp expect out
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user