Skip to content

Commit c0234b2

Browse files
committed
stat_tracking_info(): clear object flags used during counting
When left-right traversal counts the commits in a diverged history, it leaves the flags in the commits smudged, and we need to clear them before we return. Otherwise the caller cannot inspect other branches with this function again. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 94fcb73 commit c0234b2

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,10 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
12951295
else
12961296
(*num_theirs)++;
12971297
}
1298+
1299+
/* clear object flags smudged by the above traversal */
1300+
clear_commit_marks(ours, ALL_REV_FLAGS);
1301+
clear_commit_marks(theirs, ALL_REV_FLAGS);
12981302
return 1;
12991303
}
13001304

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define ADDED (1u<<7) /* Parents already parsed and added? */
1212
#define SYMMETRIC_LEFT (1u<<8)
1313
#define TOPOSORT (1u<<9) /* In the active toposort list.. */
14+
#define ALL_REV_FLAGS ((1u<<10)-1)
1415

1516
struct rev_info;
1617
struct log_info;

t/t6040-tracking-info.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
3+
test_description='remote tracking stats'
4+
5+
. ./test-lib.sh
6+
7+
advance () {
8+
echo "$1" >"$1" &&
9+
git add "$1" &&
10+
test_tick &&
11+
git commit -m "$1"
12+
}
13+
14+
test_expect_success setup '
15+
for i in a b c;
16+
do
17+
advance $i || break
18+
done &&
19+
git clone . test &&
20+
(
21+
cd test &&
22+
git checkout -b b1 origin &&
23+
git reset --hard HEAD^ &&
24+
advance d &&
25+
git checkout -b b2 origin &&
26+
git reset --hard b1 &&
27+
git checkout -b b3 origin &&
28+
git reset --hard HEAD^ &&
29+
git checkout -b b4 origin &&
30+
advance e &&
31+
advance f
32+
)
33+
'
34+
35+
script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
36+
cat >expect <<\EOF
37+
b1 ahead 1, behind 1
38+
b2 ahead 1, behind 1
39+
b3 behind 1
40+
b4 ahead 2
41+
EOF
42+
43+
test_expect_success 'branch -v' '
44+
(
45+
cd test &&
46+
git branch -v
47+
) |
48+
sed -n -e "$script" >actual &&
49+
test_cmp expect actual
50+
'
51+
52+
test_expect_success 'checkout' '
53+
(
54+
cd test && git checkout b1
55+
) >actual &&
56+
grep -e "have 1 and 1 different" actual
57+
'
58+
59+
test_expect_success 'status' '
60+
(
61+
cd test &&
62+
git checkout b1 >/dev/null &&
63+
# reports nothing to commit
64+
test_must_fail git status
65+
) >actual &&
66+
grep -e "have 1 and 1 different" actual
67+
'
68+
69+
70+
test_done

0 commit comments

Comments
 (0)