git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kenny Lee Sin Cheong <kenny.lee28@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Kenny Lee Sin Cheong <kenny.lee28@gmail.com>
Subject: [PATCH/RFC 1/4] Add "-" as @{-1} support for the rev-parse command
Date: Mon, 30 Mar 2015 13:41:52 -0400	[thread overview]
Message-ID: <1427737315-7229-2-git-send-email-kenny.lee28@gmail.com> (raw)
In-Reply-To: <1427737315-7229-1-git-send-email-kenny.lee28@gmail.com>

Allows the use of the "-" shorthand notation, including
use with revision ranges. If we plan to allow "-" as a stand in every
where a revision is allowed, then "-" would also need to be usable in
plumbing commands, for writing tests, for example.

Checks if the argument can be interpreted as a revision range first
before checking for flags. This saves us from having to check that
something that begins with "-" does not get checked as a possible flag.

Signed-off-by: Kenny Lee Sin Cheong <kenny.lee28@gmail.com>
---
 builtin/rev-parse.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 3626c61..8da95b5 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -553,6 +553,25 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
+		/* Not a flag argument */
+		if (try_difference(arg))
+			continue;
+		if (try_parent_shorthands(arg))
+			continue;
+		name = arg;
+		type = NORMAL;
+		if (*arg == '^') {
+			name++;
+			type = REVERSED;
+		}
+		if (!get_sha1_with_context(name, flags, sha1, &unused)) {
+			if (verify)
+				revs_count++;
+			else
+				show_rev(type, sha1, name);
+			continue;
+		}
+
 		if (*arg == '-') {
 			if (!strcmp(arg, "--")) {
 				as_is = 2;
@@ -810,24 +829,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
-		/* Not a flag argument */
-		if (try_difference(arg))
-			continue;
-		if (try_parent_shorthands(arg))
-			continue;
-		name = arg;
-		type = NORMAL;
-		if (*arg == '^') {
-			name++;
-			type = REVERSED;
-		}
-		if (!get_sha1_with_context(name, flags, sha1, &unused)) {
-			if (verify)
-				revs_count++;
-			else
-				show_rev(type, sha1, name);
-			continue;
-		}
 		if (verify)
 			die_no_single_rev(quiet);
 		if (has_dashdash)
-- 
2.3.3.203.g8ffb468.dirty

  reply	other threads:[~2015-03-30 17:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30 17:41 [PATCH/RFC 0/4] Adding '-' notation as @{-1} (pu, d40f108) Kenny Lee Sin Cheong
2015-03-30 17:41 ` Kenny Lee Sin Cheong [this message]
2015-03-30 19:46   ` [PATCH/RFC 1/4] Add "-" as @{-1} support for the rev-parse command Junio C Hamano
2015-03-30 17:41 ` [PATCH/RFC 2/4] t1505: add tests for '-' notation in rev-parse Kenny Lee Sin Cheong
2015-03-31  4:55   ` Torsten Bögershausen
2015-03-30 17:41 ` [PATCH/RFC 3/4] Handle arg as revision first, then option Kenny Lee Sin Cheong
2015-03-30 17:41 ` [PATCH/RFC 4/4] t0102: add tests for '-' notation Kenny Lee Sin Cheong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427737315-7229-2-git-send-email-kenny.lee28@gmail.com \
    --to=kenny.lee28@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).