Skip to content

Commit d89797f

Browse files
peffgitster
authored andcommitted
handle_revision_arg: hoist ".." check out of range parsing
Since 003c84f (specifying ranges: we did not mean to make ".." an empty set, 2011-05-02), we treat the argument ".." specially. We detect it by noticing that both sides of the range are empty, and that this is a non-symmetric two-dot range. While correct, this makes the code overly complicated. We can just detect ".." up front before we try to do further parsing. This avoids having to de-munge the NUL from dotdot, and lets us eliminate an extra const array (which we needed only to do direct pointer comparisons). It also removes the one code path from the range-parsing conditional that requires us to return -1. That will make it simpler to pull the dotdot parsing out into its own function. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f632ded commit d89797f

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

revision.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,34 +1443,30 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
14431443

14441444
flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
14451445

1446+
if (!cant_be_filename && !strcmp(arg, "..")) {
1447+
/*
1448+
* Just ".."? That is not a range but the
1449+
* pathspec for the parent directory.
1450+
*/
1451+
return -1;
1452+
}
1453+
14461454
dotdot = strstr(arg, "..");
14471455
if (dotdot) {
14481456
unsigned char from_sha1[20];
14491457
const char *next = dotdot + 2;
14501458
const char *this = arg;
14511459
int symmetric = *next == '.';
14521460
unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
1453-
static const char head_by_default[] = "HEAD";
14541461
unsigned int a_flags;
14551462

14561463
*dotdot = 0;
14571464
next += symmetric;
14581465

14591466
if (!*next)
1460-
next = head_by_default;
1467+
next = "HEAD";
14611468
if (dotdot == arg)
1462-
this = head_by_default;
1463-
if (this == head_by_default && next == head_by_default &&
1464-
!symmetric) {
1465-
/*
1466-
* Just ".."? That is not a range but the
1467-
* pathspec for the parent directory.
1468-
*/
1469-
if (!cant_be_filename) {
1470-
*dotdot = '.';
1471-
return -1;
1472-
}
1473-
}
1469+
this = "HEAD";
14741470
if (!get_sha1_committish(this, from_sha1) &&
14751471
!get_sha1_committish(next, sha1)) {
14761472
struct object *a_obj, *b_obj;

0 commit comments

Comments
 (0)