Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 2d99baa

Browse files
committed
Merge branch 'jc/revision-range-unpeel'
"git rev-list --objects ^v1.0^ v1.0" gave v1.0 tag itself in the output, but "git rev-list --objects v1.0^..v1.0" did not. * jc/revision-range-unpeel: revision: do not peel tags used in range notation
2 parents e22c1c7 + 895c5ba commit 2d99baa

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

revision.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,44 +1419,59 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
14191419
}
14201420
if (!get_sha1_committish(this, from_sha1) &&
14211421
!get_sha1_committish(next, sha1)) {
1422-
struct commit *a, *b;
1423-
struct commit_list *exclude;
1424-
1425-
a = lookup_commit_reference(from_sha1);
1426-
b = lookup_commit_reference(sha1);
1427-
if (!a || !b) {
1428-
if (revs->ignore_missing)
1429-
return 0;
1430-
die(symmetric ?
1431-
"Invalid symmetric difference expression %s...%s" :
1432-
"Invalid revision range %s..%s",
1433-
arg, next);
1434-
}
1422+
struct object *a_obj, *b_obj;
14351423

14361424
if (!cant_be_filename) {
14371425
*dotdot = '.';
14381426
verify_non_filename(revs->prefix, arg);
14391427
}
14401428

1441-
if (symmetric) {
1429+
a_obj = parse_object(from_sha1);
1430+
b_obj = parse_object(sha1);
1431+
if (!a_obj || !b_obj) {
1432+
missing:
1433+
if (revs->ignore_missing)
1434+
return 0;
1435+
die(symmetric
1436+
? "Invalid symmetric difference expression %s"
1437+
: "Invalid revision range %s", arg);
1438+
}
1439+
1440+
if (!symmetric) {
1441+
/* just A..B */
1442+
a_flags = flags_exclude;
1443+
} else {
1444+
/* A...B -- find merge bases between the two */
1445+
struct commit *a, *b;
1446+
struct commit_list *exclude;
1447+
1448+
a = (a_obj->type == OBJ_COMMIT
1449+
? (struct commit *)a_obj
1450+
: lookup_commit_reference(a_obj->sha1));
1451+
b = (b_obj->type == OBJ_COMMIT
1452+
? (struct commit *)b_obj
1453+
: lookup_commit_reference(b_obj->sha1));
1454+
if (!a || !b)
1455+
goto missing;
14421456
exclude = get_merge_bases(a, b, 1);
14431457
add_rev_cmdline_list(revs, exclude,
14441458
REV_CMD_MERGE_BASE,
14451459
flags_exclude);
14461460
add_pending_commit_list(revs, exclude,
14471461
flags_exclude);
14481462
free_commit_list(exclude);
1463+
14491464
a_flags = flags | SYMMETRIC_LEFT;
1450-
} else
1451-
a_flags = flags_exclude;
1452-
a->object.flags |= a_flags;
1453-
b->object.flags |= flags;
1454-
add_rev_cmdline(revs, &a->object, this,
1465+
}
1466+
1467+
a_obj->flags |= a_flags;
1468+
b_obj->flags |= flags;
1469+
add_rev_cmdline(revs, a_obj, this,
14551470
REV_CMD_LEFT, a_flags);
1456-
add_rev_cmdline(revs, &b->object, next,
1471+
add_rev_cmdline(revs, b_obj, next,
14571472
REV_CMD_RIGHT, flags);
1458-
add_pending_object(revs, &a->object, this);
1459-
add_pending_object(revs, &b->object, next);
1473+
add_pending_object(revs, a_obj, this);
1474+
add_pending_object(revs, b_obj, next);
14601475
return 0;
14611476
}
14621477
*dotdot = '.';

t/t6000-rev-list-misc.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ test_expect_success 'rev-list --objects with pathspecs and copied files' '
4848
! grep one output
4949
'
5050

51+
test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
52+
git commit --allow-empty -m another &&
53+
git tag -a -m "annotated" v1.0 &&
54+
git rev-list --objects ^v1.0^ v1.0 >expect &&
55+
git rev-list --objects v1.0^..v1.0 >actual &&
56+
test_cmp expect actual
57+
'
58+
5159
test_done

0 commit comments

Comments
 (0)