From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Felipe Contreras <felipe.contreras@gmail.com>,
Michael Haggerty <mhagger@alum.mit.edu>,
Junio C Hamano <gitster@pobox.com>,
Duy Nguyen <pclouds@gmail.com>
Subject: [PATCH] refs.c: interpret @ as HEAD
Date: Tue, 30 Apr 2013 17:54:45 +0530 [thread overview]
Message-ID: <1367324685-22788-1-git-send-email-artagnon@gmail.com> (raw)
The rev spec forms @{}, .., ... fill in HEAD as the missing argument
automatically. Unfortunately, HEAD~<n> is a very common idiom and
there is no way to make HEAD implicit here (due the shell expansion of
~<n>).
However, there is an alternative solution to the issue: overload the
character @ to mean HEAD. Do this at the lowest possible layer of
abstraction: in dwim_ref(), substitute @ with HEAD just before calling
resolve_ref_unsafe(). The program will only reach this point after
the other specs like ~, ^ and @{} have been resolved; therefore, it is
safe to do it here.
This patch has the exact same effect as:
$ git symbolic-ref @ HEAD
It means that you can now do @~1, @^2, and even topic..@. However,
since the @-parsing happens before we ever reach the symref
resolution, @@{u} is invalid. But this is okay, since @{u} already
has an implicit HEAD in it.
Inspired-by: Felipe Contreras <felipe.contreras@gmail.com>
Inspired-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
I haven't included documentation/ tests because I want feedback on
this two-liner first.
refs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/refs.c b/refs.c
index de2d8eb..cb67b73 100644
--- a/refs.c
+++ b/refs.c
@@ -1604,6 +1604,8 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
this_result = refs_found ? sha1_from_ref : sha1;
mksnpath(fullref, sizeof(fullref), *p, len, str);
+ if (!strcmp(fullref, "@"))
+ mksnpath(fullref, sizeof(fullref), *p, 4, "HEAD");
r = resolve_ref_unsafe(fullref, this_result, 1, &flag);
if (r) {
if (!refs_found++)
--
1.8.2.1.628.gcd33b41.dirty
next reply other threads:[~2013-04-30 12:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-30 12:24 Ramkumar Ramachandra [this message]
2013-04-30 12:31 ` [PATCH] refs.c: interpret @ as HEAD Duy Nguyen
2013-04-30 13:01 ` Thomas Rast
2013-04-30 13:32 ` Ramkumar Ramachandra
2013-04-30 15:04 ` Duy Nguyen
2013-04-30 16:08 ` Michael Haggerty
2013-04-30 16:09 ` Junio C Hamano
2013-04-30 16:26 ` Duy Nguyen
2013-04-30 17:15 ` Ramkumar Ramachandra
2013-05-01 2:18 ` Duy Nguyen
2013-05-01 8:35 ` Thomas Rast
2013-04-30 17:07 ` Ramkumar Ramachandra
2013-04-30 17:23 ` Ramkumar Ramachandra
2013-04-30 17:28 ` Felipe Contreras
2013-04-30 17:32 ` Ramkumar Ramachandra
2013-04-30 18:08 ` Junio C Hamano
2013-04-30 18:22 ` Ramkumar Ramachandra
2013-04-30 18:24 ` Ramkumar Ramachandra
2013-04-30 18:40 ` Ramkumar Ramachandra
2013-04-30 18:50 ` Ramkumar Ramachandra
2013-04-30 22:00 ` Felipe Contreras
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=1367324685-22788-1-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=pclouds@gmail.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).