handle_revision_arg: hoist ".." check out of range parsing

Since 003c84f6d (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>

Jeff King committed May 19, 2017 at 08:51 UTC d89797feff053bba939b62ee442f56e3fc98062b
1 file changed +10 -14
revision.c
+10 -14
@@ -1443,6 +1443,14 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1443
1444 flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
1445
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 +
1454 dotdot = strstr(arg, "..");
1455 if (dotdot) {
1456 unsigned char from_sha1[20];
@@ -1450,27 +1458,15 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1458 const char *this = arg;
1459 int symmetric = *next == '.';
1460 unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
1453 - static const char head_by_default[] = "HEAD";
1461 unsigned int a_flags;
1462
1463 *dotdot = 0;
1464 next += symmetric;
1465
1466 if (!*next)
1460 - next = head_by_default;
1467 + next = "HEAD";
1468 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";
1470 if (!get_sha1_committish(this, from_sha1) &&
1471 !get_sha1_committish(next, sha1)) {
1472 struct object *a_obj, *b_obj;