Skip to content

Commit b805ef0

Browse files
committed
Merge branch 'tr/rev-list-reverse'
* tr/rev-list-reverse: t6013: replace use of 'tac' with equivalent Perl rev-list: fix --reverse interaction with --parents
2 parents cb2c7da + 9d13dec commit b805ef0

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

revision.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,26 +1793,6 @@ static struct commit *get_revision_internal(struct rev_info *revs)
17931793
return c;
17941794
}
17951795

1796-
if (revs->reverse) {
1797-
int limit = -1;
1798-
1799-
if (0 <= revs->max_count) {
1800-
limit = revs->max_count;
1801-
if (0 < revs->skip_count)
1802-
limit += revs->skip_count;
1803-
}
1804-
l = NULL;
1805-
while ((c = get_revision_1(revs))) {
1806-
commit_list_insert(c, &l);
1807-
if ((0 < limit) && !--limit)
1808-
break;
1809-
}
1810-
revs->commits = l;
1811-
revs->reverse = 0;
1812-
revs->max_count = -1;
1813-
c = NULL;
1814-
}
1815-
18161796
/*
18171797
* Now pick up what they want to give us
18181798
*/
@@ -1885,7 +1865,23 @@ static struct commit *get_revision_internal(struct rev_info *revs)
18851865

18861866
struct commit *get_revision(struct rev_info *revs)
18871867
{
1888-
struct commit *c = get_revision_internal(revs);
1868+
struct commit *c;
1869+
struct commit_list *reversed;
1870+
1871+
if (revs->reverse) {
1872+
reversed = NULL;
1873+
while ((c = get_revision_internal(revs))) {
1874+
commit_list_insert(c, &reversed);
1875+
}
1876+
revs->commits = reversed;
1877+
revs->reverse = 0;
1878+
revs->reverse_output_stage = 1;
1879+
}
1880+
1881+
if (revs->reverse_output_stage)
1882+
return pop_commit(&revs->commits);
1883+
1884+
c = get_revision_internal(revs);
18891885
if (c && revs->graph)
18901886
graph_update(revs->graph, c);
18911887
return c;

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct rev_info {
5454
rewrite_parents:1,
5555
print_parents:1,
5656
reverse:1,
57+
reverse_output_stage:1,
5758
cherry_pick:1,
5859
first_parent_only:1;
5960

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
test_description='--reverse combines with --parents'
4+
5+
. ./test-lib.sh
6+
7+
8+
commit () {
9+
test_tick &&
10+
echo $1 > foo &&
11+
git add foo &&
12+
git commit -m "$1"
13+
}
14+
15+
test_expect_success 'set up --reverse example' '
16+
commit one &&
17+
git tag root &&
18+
commit two &&
19+
git checkout -b side HEAD^ &&
20+
commit three &&
21+
git checkout master &&
22+
git merge -s ours side &&
23+
commit five
24+
'
25+
26+
test_expect_success '--reverse --parents --full-history combines correctly' '
27+
git rev-list --parents --full-history master -- foo |
28+
perl -e "print reverse <>" > expected &&
29+
git rev-list --reverse --parents --full-history master -- foo \
30+
> actual &&
31+
test_cmp actual expected
32+
'
33+
34+
test_expect_success '--boundary does too' '
35+
git rev-list --boundary --parents --full-history master ^root -- foo |
36+
perl -e "print reverse <>" > expected &&
37+
git rev-list --boundary --reverse --parents --full-history \
38+
master ^root -- foo > actual &&
39+
test_cmp actual expected
40+
'
41+
42+
test_done

0 commit comments

Comments
 (0)