diff options
author | Nicolas Pitre <nico@cam.org> | 2007-02-01 17:29:33 -0500 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-01 21:49:28 -0800 |
commit | 11cf8801d7d58cc1532f11a827ce130c10d149be (patch) | |
tree | 1a7cb5b7ed3dcbee5fb0653224f4f9004168e5fc | |
parent | fe55851624bbdb4f08e17e27ef8197ed610ac586 (diff) | |
download | git-11cf8801d7d58cc1532f11a827ce130c10d149be.tar.gz git-11cf8801d7d58cc1532f11a827ce130c10d149be.tar.xz |
provide a nice @{...} syntax to always mean the current branch reflog
This is shorter than HEAD@{...} and being nameless it has no semantic
issues.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r-- | sha1_name.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/sha1_name.c b/sha1_name.c index 70c6e42b0..de8caf8cf 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -279,7 +279,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) /* basic@{time or number} format to query ref-log */ reflog_len = at = 0; if (str[len-1] == '}') { - for (at = 1; at < len - 1; at++) { + for (at = 0; at < len - 1; at++) { if (str[at] == '@' && str[at+1] == '{') { reflog_len = (len-1) - (at+2); len = at; @@ -289,10 +289,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) } /* Accept only unambiguous ref paths. */ - if (ambiguous_path(str, len)) + if (len && ambiguous_path(str, len)) return -1; - refs_found = dwim_ref(str, len, sha1, &real_ref); + if (!len && reflog_len) { + /* allow "@{...}" to mean the current branch reflog */ + refs_found = dwim_ref("HEAD", 4, sha1, &real_ref); + } else + refs_found = dwim_ref(str, len, sha1, &real_ref); if (!refs_found) return -1; @@ -312,11 +316,12 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) * In the mean time prevent people from getting used to * such a synonym until the work is completed. */ - if (!strncmp("HEAD", str, len) && + if (len && !strncmp("HEAD", str, len) && !strncmp(real_ref, "refs/", 5)) { error("reflog for HEAD has not been implemented yet\n" - "Maybe you could try %s%s instead.", - strchr(real_ref+5, '/')+1, str + len); + "Maybe you could try %s%s instead, " + "or just %s for current branch..", + strchr(real_ref+5, '/')+1, str+len, str+len); exit(-1); } |