Skip to content

Commit 24343c6

Browse files
committed
Merge branch 'as/maint-graph-interesting-fix'
* as/maint-graph-interesting-fix: Add tests for rev-list --graph with options that simplify history graph API: fix bug in graph_is_interesting()
2 parents adc5423 + b97c470 commit 24343c6

File tree

5 files changed

+325
-5
lines changed

5 files changed

+325
-5
lines changed

graph.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,10 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
291291
}
292292

293293
/*
294-
* Uninteresting and pruned commits won't be printed
294+
* Otherwise, use get_commit_action() to see if this commit is
295+
* interesting
295296
*/
296-
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
297+
return get_commit_action(graph->revs, commit) == commit_show;
297298
}
298299

299300
static struct commit_list *next_interesting_parent(struct git_graph *graph,

revision.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ static inline int want_ancestry(struct rev_info *revs)
16641664
return (revs->rewrite_parents || revs->children.name);
16651665
}
16661666

1667-
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1667+
enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit)
16681668
{
16691669
if (commit->object.flags & SHOWN)
16701670
return commit_ignore;
@@ -1692,12 +1692,23 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
16921692
if (!commit->parents || !commit->parents->next)
16931693
return commit_ignore;
16941694
}
1695-
if (want_ancestry(revs) && rewrite_parents(revs, commit) < 0)
1696-
return commit_error;
16971695
}
16981696
return commit_show;
16991697
}
17001698

1699+
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1700+
{
1701+
enum commit_action action = get_commit_action(revs, commit);
1702+
1703+
if (action == commit_show &&
1704+
!revs->show_all &&
1705+
revs->prune && revs->dense && want_ancestry(revs)) {
1706+
if (rewrite_parents(revs, commit) < 0)
1707+
return commit_error;
1708+
}
1709+
return action;
1710+
}
1711+
17011712
static struct commit *get_revision_1(struct rev_info *revs)
17021713
{
17031714
if (!revs->commits)

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ enum commit_action {
168168
commit_error
169169
};
170170

171+
extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
171172
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
172173

173174
#endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
test_description='--show-all --parents does not rewrite TREESAME commits'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'set up --show-all --parents test' '
8+
test_commit one foo.txt &&
9+
commit1=`git rev-list -1 HEAD` &&
10+
test_commit two bar.txt &&
11+
commit2=`git rev-list -1 HEAD` &&
12+
test_commit three foo.txt &&
13+
commit3=`git rev-list -1 HEAD`
14+
'
15+
16+
test_expect_success '--parents rewrites TREESAME parents correctly' '
17+
echo $commit3 $commit1 > expected &&
18+
echo $commit1 >> expected &&
19+
git rev-list --parents HEAD -- foo.txt > actual &&
20+
test_cmp expected actual
21+
'
22+
23+
test_expect_success '--parents --show-all does not rewrites TREESAME parents' '
24+
echo $commit3 $commit2 > expected &&
25+
echo $commit2 $commit1 >> expected &&
26+
echo $commit1 >> expected &&
27+
git rev-list --parents --show-all HEAD -- foo.txt > actual &&
28+
test_cmp expected actual
29+
'
30+
31+
test_done
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
#!/bin/sh
2+
3+
# There's more than one "correct" way to represent the history graphically.
4+
# These tests depend on the current behavior of the graphing code. If the
5+
# graphing code is ever changed to draw the output differently, these tests
6+
# cases will need to be updated to know about the new layout.
7+
8+
test_description='--graph and simplified history'
9+
10+
. ./test-lib.sh
11+
12+
test_expect_success 'set up rev-list --graph test' '
13+
# 3 commits on branch A
14+
test_commit A1 foo.txt &&
15+
test_commit A2 bar.txt &&
16+
test_commit A3 bar.txt &&
17+
git branch -m master A &&
18+
19+
# 2 commits on branch B, started from A1
20+
git checkout -b B A1 &&
21+
test_commit B1 foo.txt &&
22+
test_commit B2 abc.txt &&
23+
24+
# 2 commits on branch C, started from A2
25+
git checkout -b C A2 &&
26+
test_commit C1 xyz.txt &&
27+
test_commit C2 xyz.txt &&
28+
29+
# Octopus merge B and C into branch A
30+
git checkout A &&
31+
git merge B C &&
32+
git tag A4
33+
34+
test_commit A5 bar.txt &&
35+
36+
# More commits on C, then merge C into A
37+
git checkout C &&
38+
test_commit C3 foo.txt &&
39+
test_commit C4 bar.txt &&
40+
git checkout A &&
41+
git merge -s ours C &&
42+
git tag A6
43+
44+
test_commit A7 bar.txt &&
45+
46+
# Store commit names in variables for later use
47+
A1=$(git rev-parse --verify A1) &&
48+
A2=$(git rev-parse --verify A2) &&
49+
A3=$(git rev-parse --verify A3) &&
50+
A4=$(git rev-parse --verify A4) &&
51+
A5=$(git rev-parse --verify A5) &&
52+
A6=$(git rev-parse --verify A6) &&
53+
A7=$(git rev-parse --verify A7) &&
54+
B1=$(git rev-parse --verify B1) &&
55+
B2=$(git rev-parse --verify B2) &&
56+
C1=$(git rev-parse --verify C1) &&
57+
C2=$(git rev-parse --verify C2) &&
58+
C3=$(git rev-parse --verify C3) &&
59+
C4=$(git rev-parse --verify C4)
60+
'
61+
62+
test_expect_success '--graph --all' '
63+
rm -f expected &&
64+
echo "* $A7" >> expected &&
65+
echo "* $A6" >> expected &&
66+
echo "|\\ " >> expected &&
67+
echo "| * $C4" >> expected &&
68+
echo "| * $C3" >> expected &&
69+
echo "* | $A5" >> expected &&
70+
echo "| | " >> expected &&
71+
echo "| \\ " >> expected &&
72+
echo "*-. \\ $A4" >> expected &&
73+
echo "|\\ \\ \\ " >> expected &&
74+
echo "| | |/ " >> expected &&
75+
echo "| | * $C2" >> expected &&
76+
echo "| | * $C1" >> expected &&
77+
echo "| * | $B2" >> expected &&
78+
echo "| * | $B1" >> expected &&
79+
echo "* | | $A3" >> expected &&
80+
echo "| |/ " >> expected &&
81+
echo "|/| " >> expected &&
82+
echo "* | $A2" >> expected &&
83+
echo "|/ " >> expected &&
84+
echo "* $A1" >> expected &&
85+
git rev-list --graph --all > actual &&
86+
test_cmp expected actual
87+
'
88+
89+
# Make sure the graph_is_interesting() code still realizes
90+
# that undecorated merges are interesting, even with --simplify-by-decoration
91+
test_expect_success '--graph --simplify-by-decoration' '
92+
rm -f expected &&
93+
git tag -d A4
94+
echo "* $A7" >> expected &&
95+
echo "* $A6" >> expected &&
96+
echo "|\\ " >> expected &&
97+
echo "| * $C4" >> expected &&
98+
echo "| * $C3" >> expected &&
99+
echo "* | $A5" >> expected &&
100+
echo "| | " >> expected &&
101+
echo "| \\ " >> expected &&
102+
echo "*-. \\ $A4" >> expected &&
103+
echo "|\\ \\ \\ " >> expected &&
104+
echo "| | |/ " >> expected &&
105+
echo "| | * $C2" >> expected &&
106+
echo "| | * $C1" >> expected &&
107+
echo "| * | $B2" >> expected &&
108+
echo "| * | $B1" >> expected &&
109+
echo "* | | $A3" >> expected &&
110+
echo "| |/ " >> expected &&
111+
echo "|/| " >> expected &&
112+
echo "* | $A2" >> expected &&
113+
echo "|/ " >> expected &&
114+
echo "* $A1" >> expected &&
115+
git rev-list --graph --all --simplify-by-decoration > actual &&
116+
test_cmp expected actual
117+
'
118+
119+
# Get rid of all decorations on branch B, and graph with it simplified away
120+
test_expect_success '--graph --simplify-by-decoration prune branch B' '
121+
rm -f expected &&
122+
git tag -d B2
123+
git tag -d B1
124+
git branch -d B
125+
echo "* $A7" >> expected &&
126+
echo "* $A6" >> expected &&
127+
echo "|\\ " >> expected &&
128+
echo "| * $C4" >> expected &&
129+
echo "| * $C3" >> expected &&
130+
echo "* | $A5" >> expected &&
131+
echo "* | $A4" >> expected &&
132+
echo "|\\ \\ " >> expected &&
133+
echo "| |/ " >> expected &&
134+
echo "| * $C2" >> expected &&
135+
echo "| * $C1" >> expected &&
136+
echo "* | $A3" >> expected &&
137+
echo "|/ " >> expected &&
138+
echo "* $A2" >> expected &&
139+
echo "* $A1" >> expected &&
140+
git rev-list --graph --simplify-by-decoration --all > actual &&
141+
test_cmp expected actual
142+
'
143+
144+
test_expect_success '--graph --full-history -- bar.txt' '
145+
rm -f expected &&
146+
git tag -d B2
147+
git tag -d B1
148+
git branch -d B
149+
echo "* $A7" >> expected &&
150+
echo "* $A6" >> expected &&
151+
echo "|\\ " >> expected &&
152+
echo "| * $C4" >> expected &&
153+
echo "* | $A5" >> expected &&
154+
echo "* | $A4" >> expected &&
155+
echo "|\\ \\ " >> expected &&
156+
echo "| |/ " >> expected &&
157+
echo "* | $A3" >> expected &&
158+
echo "|/ " >> expected &&
159+
echo "* $A2" >> expected &&
160+
git rev-list --graph --full-history --all -- bar.txt > actual &&
161+
test_cmp expected actual
162+
'
163+
164+
test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
165+
rm -f expected &&
166+
git tag -d B2
167+
git tag -d B1
168+
git branch -d B
169+
echo "* $A7" >> expected &&
170+
echo "* $A6" >> expected &&
171+
echo "|\\ " >> expected &&
172+
echo "| * $C4" >> expected &&
173+
echo "* | $A5" >> expected &&
174+
echo "* | $A3" >> expected &&
175+
echo "|/ " >> expected &&
176+
echo "* $A2" >> expected &&
177+
git rev-list --graph --full-history --simplify-merges --all \
178+
-- bar.txt > actual &&
179+
test_cmp expected actual
180+
'
181+
182+
test_expect_success '--graph -- bar.txt' '
183+
rm -f expected &&
184+
git tag -d B2
185+
git tag -d B1
186+
git branch -d B
187+
echo "* $A7" >> expected &&
188+
echo "* $A5" >> expected &&
189+
echo "* $A3" >> expected &&
190+
echo "| * $C4" >> expected &&
191+
echo "|/ " >> expected &&
192+
echo "* $A2" >> expected &&
193+
git rev-list --graph --all -- bar.txt > actual &&
194+
test_cmp expected actual
195+
'
196+
197+
test_expect_success '--graph --sparse -- bar.txt' '
198+
rm -f expected &&
199+
git tag -d B2
200+
git tag -d B1
201+
git branch -d B
202+
echo "* $A7" >> expected &&
203+
echo "* $A6" >> expected &&
204+
echo "* $A5" >> expected &&
205+
echo "* $A4" >> expected &&
206+
echo "* $A3" >> expected &&
207+
echo "| * $C4" >> expected &&
208+
echo "| * $C3" >> expected &&
209+
echo "| * $C2" >> expected &&
210+
echo "| * $C1" >> expected &&
211+
echo "|/ " >> expected &&
212+
echo "* $A2" >> expected &&
213+
echo "* $A1" >> expected &&
214+
git rev-list --graph --sparse --all -- bar.txt > actual &&
215+
test_cmp expected actual
216+
'
217+
218+
test_expect_success '--graph ^C4' '
219+
rm -f expected &&
220+
echo "* $A7" >> expected &&
221+
echo "* $A6" >> expected &&
222+
echo "* $A5" >> expected &&
223+
echo "* $A4" >> expected &&
224+
echo "|\\ " >> expected &&
225+
echo "| * $B2" >> expected &&
226+
echo "| * $B1" >> expected &&
227+
echo "* $A3" >> expected &&
228+
git rev-list --graph --all ^C4 > actual &&
229+
test_cmp expected actual
230+
'
231+
232+
test_expect_success '--graph ^C3' '
233+
rm -f expected &&
234+
echo "* $A7" >> expected &&
235+
echo "* $A6" >> expected &&
236+
echo "|\\ " >> expected &&
237+
echo "| * $C4" >> expected &&
238+
echo "* $A5" >> expected &&
239+
echo "* $A4" >> expected &&
240+
echo "|\\ " >> expected &&
241+
echo "| * $B2" >> expected &&
242+
echo "| * $B1" >> expected &&
243+
echo "* $A3" >> expected &&
244+
git rev-list --graph --all ^C3 > actual &&
245+
test_cmp expected actual
246+
'
247+
248+
# I don't think the ordering of the boundary commits is really
249+
# that important, but this test depends on it. If the ordering ever changes
250+
# in the code, we'll need to update this test.
251+
test_expect_success '--graph --boundary ^C3' '
252+
rm -f expected &&
253+
echo "* $A7" >> expected &&
254+
echo "* $A6" >> expected &&
255+
echo "|\\ " >> expected &&
256+
echo "| * $C4" >> expected &&
257+
echo "* | $A5" >> expected &&
258+
echo "| | " >> expected &&
259+
echo "| \\ " >> expected &&
260+
echo "*-. \\ $A4" >> expected &&
261+
echo "|\\ \\ \\ " >> expected &&
262+
echo "| * | | $B2" >> expected &&
263+
echo "| * | | $B1" >> expected &&
264+
echo "* | | | $A3" >> expected &&
265+
echo "o | | | $A2" >> expected &&
266+
echo "|/ / / " >> expected &&
267+
echo "o | | $A1" >> expected &&
268+
echo " / / " >> expected &&
269+
echo "| o $C3" >> expected &&
270+
echo "|/ " >> expected &&
271+
echo "o $C2" >> expected &&
272+
git rev-list --graph --boundary --all ^C3 > actual &&
273+
test_cmp expected actual
274+
'
275+
276+
test_done

0 commit comments

Comments
 (0)