Skip to content

Commit 0faff47

Browse files
committed
Merge branch 'jc/revision-range-unpeel' into maint
"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 8447dc8 + 895c5ba commit 0faff47

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
@@ -1420,44 +1420,59 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
14201420
}
14211421
if (!get_sha1_committish(this, from_sha1) &&
14221422
!get_sha1_committish(next, sha1)) {
1423-
struct commit *a, *b;
1424-
struct commit_list *exclude;
1425-
1426-
a = lookup_commit_reference(from_sha1);
1427-
b = lookup_commit_reference(sha1);
1428-
if (!a || !b) {
1429-
if (revs->ignore_missing)
1430-
return 0;
1431-
die(symmetric ?
1432-
"Invalid symmetric difference expression %s...%s" :
1433-
"Invalid revision range %s..%s",
1434-
arg, next);
1435-
}
1423+
struct object *a_obj, *b_obj;
14361424

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

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