git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 1/4] Add "-" as @{-1} support for the rev-parse command

From
KCKenny Lee Sin Cheong <kenny.lee28@gmail.com>
Date
Mar 30, 2015, 17:41 UTC
Message-ID
<1427737315-7229-2-git-send-email-kenny.lee28@gmail.com>
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
Previous: Kenny Lee Sin CheongNext: Junio C Hamano
Message 2 of 7 in “Adding '-' notation as @{-1} (pu, d40f108)”
  1. 0/4 Adding '-' notation as @{-1} (pu, d40f108)Kenny Lee Sin Cheong, Mar 30, 2015
  2. 1/4 Add "-" as @{-1} support for the rev-parse commandKenny Lee Sin Cheong, Mar 30, 2015
  3. Junio C HamanoMar 30, 2015
  4. 2/4 t1505: add tests for '-' notation in rev-parseKenny Lee Sin Cheong, Mar 30, 2015
  5. Torsten BögershausenMar 31, 2015
  6. 3/4 Handle arg as revision first, then option.Kenny Lee Sin Cheong, Mar 30, 2015
  7. 4/4 t0102: add tests for '-' notationKenny Lee Sin Cheong, Mar 30, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.