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

[PATCH] [GSoC Microproject]Adding "-" shorthand for "@{-1}" in RESET command

From
SRSundararajan R <dyoucme@gmail.com>
Date
Mar 7, 2015, 01:57 UTC
Message-ID
<1425693456-21163-1-git-send-email-dyoucme@gmail.com>
Hi all, I am a GSoC '15 aspirant for git.
In this commit I have directly associated "-" to "@{-1}" except when it refers to a filename. 
All the given tests pass(except those which shouldn't).
I have to add a failsafe for the case in when there is no branch as "@{-1}". For this I have a 
rough idea that I would have to call get-sha1() on @{-1} to check if there is an object matching 
with it. But I am not able to think of the details.
Please guide me with that and give feedback for this patch.
Signed-off-by: Sundararajan R <dyoucme@gmail.com>
---
 builtin/reset.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/builtin/reset.c b/builtin/reset.c
index 4c08ddc..62764d4 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -203,8 +203,16 @@ static void parse_args(struct pathspec *pathspec,
 	 *
 	 * At this point, argv points immediately after [-opts].
 	 */
-
+	int flag=0; /* 
+		     *  "-" may refer to filename in which case we should be giving more precedence 
+		     *  to filename than equating argv[0] to "@{-1}" 
+		     */
 	if (argv[0]) {
+		if (!strcmp(argv[0], "-") && !argv[1])  /* "-" is the only argument */
+		{
+			argv[0]="@{-1}";
+			flag=1;
+		}
 		if (!strcmp(argv[0], "--")) {
 			argv++; /* reset to HEAD, possibly with paths */
 		} else if (argv[1] && !strcmp(argv[1], "--")) {
@@ -226,6 +234,8 @@ static void parse_args(struct pathspec *pathspec,
 			rev = *argv++;
 		} else {
 			/* Otherwise we treat this as a filename */
+			if(flag)
+				argv[0]="-";
 			verify_filename(prefix, argv[0], 1);
 		}
 	}
-- 
2.1.0
Next: Junio C Hamano
Message 1 of 2 in “[GSoC Microproject]Adding "-" shorthand for "@{-1}" in RESET command”
  1. [GSoC Microproject]Adding "-" shorthand for "@{-1}" in RESET commandSundararajan R, Mar 7, 2015
  2. Junio C HamanoMar 8, 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.