git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add new @ shortcut for HEAD
@ 2013-04-29 19:35 Felipe Contreras
  2013-04-29 19:43 ` Ramkumar Ramachandra
                   ` (5 more replies)
  0 siblings, 6 replies; 56+ messages in thread
From: Felipe Contreras @ 2013-04-29 19:35 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Ramkumar Ramachandra, Michael J Gruber,
	Jon Seymour, Nguyễn Thái Ngọc Duy,
	Felipe Contreras

So HEAD@{0}~0^0 is too much to type, but we can remove '^0', and we can
remove '~0', and we can remove 'HEAD', but we can't remove '{0}'?

This patch allows 'HEAD@' to be the same as 'HEAD@{0}', and similarly with
'master@'.

So we can type '@' instead of 'HEAD@', or rather 'HEAD'. So now we can
use 'git show @~1', and all that goody goodness.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

People have complained about the lack of a HEAD shortcut before, and some
proposals have been made, but I think this one is a clean trick in accordance
with our current syntax.

 Documentation/revisions.txt | 3 +++
 sha1_name.c                 | 8 +++++++-
 t/t1503-rev-parse-verify.sh | 9 +++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index d477b3f..6315ce5 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -58,6 +58,9 @@ the '$GIT_DIR/refs' directory or from the '$GIT_DIR/packed-refs' file.
 While the ref name encoding is unspecified, UTF-8 is preferred as
 some output processing may assume ref names in UTF-8.
 
+'@'::
+  '@' alone is a shortcut for 'HEAD'
+
 '<refname>@\{<date>\}', e.g. 'master@\{yesterday\}', 'HEAD@\{5 minutes ago\}'::
   A ref followed by the suffix '@' with a date specification
   enclosed in a brace
diff --git a/sha1_name.c b/sha1_name.c
index 3820f28..d7c3d6f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -437,11 +437,15 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
 	char *real_ref = NULL;
 	int refs_found = 0;
-	int at, reflog_len;
+	int at, reflog_len, empty_at;
 
 	if (len == 40 && !get_sha1_hex(str, sha1))
 		return 0;
 
+	empty_at = len && str[len-1] == '@';
+	if (empty_at)
+		len = len-1;
+
 	/* basic@{time or number or -number} format to query ref-log */
 	reflog_len = at = 0;
 	if (len && str[len-1] == '}') {
@@ -475,6 +479,8 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 		refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
 	} else if (reflog_len)
 		refs_found = dwim_log(str, len, sha1, &real_ref);
+	else if (!len && empty_at)
+		refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
 	else
 		refs_found = dwim_ref(str, len, sha1, &real_ref);
 
diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
index 813cc1b..426c63f 100755
--- a/t/t1503-rev-parse-verify.sh
+++ b/t/t1503-rev-parse-verify.sh
@@ -115,4 +115,13 @@ test_expect_success 'master@{n} for various n' '
 	test_must_fail git rev-parse --verify master@{$Np1}
 '
 
+test_expect_success 'empty @' '
+	rev_hash=$(git rev-parse --verify @) &&
+	test "$rev_hash" = "$HASH4" &&
+	rev_hash=$(git rev-parse --verify HEAD@) &&
+	test "$rev_hash" = "$HASH4" &&
+	rev_hash=$(git rev-parse --verify master@) &&
+	test "$rev_hash" = "$HASH4"
+'
+
 test_done
-- 
1.8.2.1.1031.g2ee5873

^ permalink raw reply related	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2013-04-30 23:24 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-29 19:35 [PATCH] Add new @ shortcut for HEAD Felipe Contreras
2013-04-29 19:43 ` Ramkumar Ramachandra
2013-04-29 20:01 ` Junio C Hamano
2013-04-29 20:14   ` Felipe Contreras
2013-04-29 20:24     ` Junio C Hamano
2013-04-29 20:38       ` Felipe Contreras
2013-04-29 21:01         ` Junio C Hamano
2013-04-29 20:02 ` Junio C Hamano
2013-04-29 20:23   ` Felipe Contreras
2013-04-29 21:36     ` Felipe Contreras
2013-04-29 22:50       ` Junio C Hamano
2013-04-30  0:53         ` Jonathan Nieder
2013-04-30 17:54           ` Junio C Hamano
2013-04-30 18:17             ` Felipe Contreras
2013-04-29 22:38 ` Junio C Hamano
2013-04-29 22:49   ` Felipe Contreras
2013-04-29 23:06     ` Junio C Hamano
2013-04-29 23:10       ` Felipe Contreras
2013-04-30  5:54 ` Duy Nguyen
2013-04-30  6:10   ` Felipe Contreras
2013-04-30  6:17     ` Duy Nguyen
2013-04-30  6:20       ` Felipe Contreras
2013-04-30  6:30     ` Duy Nguyen
2013-04-30  7:55       ` Felipe Contreras
2013-04-30  7:09   ` Michael Haggerty
2013-04-30  7:35     ` Ramkumar Ramachandra
2013-04-30 10:16       ` Duy Nguyen
2013-04-30 11:10         ` Ramkumar Ramachandra
2013-04-30 18:54       ` Ramkumar Ramachandra
2013-04-30 10:12     ` Duy Nguyen
2013-04-30 17:22   ` Junio C Hamano
2013-04-30 17:37     ` Ramkumar Ramachandra
2013-04-30 17:40     ` Ramkumar Ramachandra
2013-04-30 17:56       ` Junio C Hamano
2013-04-30 18:04         ` Ramkumar Ramachandra
2013-04-30 18:20       ` Felipe Contreras
2013-04-30 18:45         ` Ramkumar Ramachandra
2013-04-30 22:08           ` Felipe Contreras
2013-04-30 17:47     ` Felipe Contreras
2013-04-30 17:56       ` Jeff King
2013-04-30 18:18         ` Felipe Contreras
2013-04-30 19:42     ` Junio C Hamano
2013-04-30 19:53       ` Ramkumar Ramachandra
2013-04-30 20:05         ` Junio C Hamano
2013-04-30 20:37           ` Ramkumar Ramachandra
2013-04-30 19:59       ` Junio C Hamano
2013-04-30 22:17       ` Felipe Contreras
2013-04-30 22:27         ` Junio C Hamano
2013-04-30 22:38           ` Felipe Contreras
2013-04-30 22:42             ` Junio C Hamano
2013-04-30 22:53               ` Felipe Contreras
2013-04-30 23:00                 ` Felipe Contreras
2013-04-30 23:19                   ` Felipe Contreras
2013-04-30 23:24                     ` Junio C Hamano
2013-04-30  6:07 ` Duy Nguyen
2013-04-30  6:11   ` Felipe Contreras

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).