git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sundararajan R <dyoucme@gmail.com>
To: git@vger.kernel.org
Cc: Sundararajan R <dyoucme@gmail.com>
Subject: [PATCH] [GSoC Microproject]Adding "-" shorthand for "@{-1}" in RESET command
Date: Sat,  7 Mar 2015 07:27:36 +0530	[thread overview]
Message-ID: <1425693456-21163-1-git-send-email-dyoucme@gmail.com> (raw)

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

             reply	other threads:[~2015-03-07  1:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-07  1:57 Sundararajan R [this message]
2015-03-08  7:34 ` [PATCH] [GSoC Microproject]Adding "-" shorthand for "@{-1}" in RESET command Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2015-03-08 11:09 Sundararajan R
2015-03-08 21:59 ` Junio C Hamano

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=1425693456-21163-1-git-send-email-dyoucme@gmail.com \
    --to=dyoucme@gmail.com \
    --cc=git@vger.kernel.org \
    /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).