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>
Nicolas Pitre committed
Feb 1, 2007 at 17:29 UTC
11cf8801d7d58cc1532f11a827ce130c10d149be
1 file changed
+11
-6
sha1_name.c
+11
-6
@@ -279,7 +279,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
279
/* basic@{time or number} format to query ref-log */
280
reflog_len = at = 0;
281
if (str[len-1] == '}') {
282
- for (at = 1; at < len - 1; at++) {
282
+ for (at = 0; at < len - 1; at++) {
283
if (str[at] == '@' && str[at+1] == '{') {
284
reflog_len = (len-1) - (at+2);
285
len = at;
@@ -289,10 +289,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
289
}
290
291
/* Accept only unambiguous ref paths. */
292
- if (ambiguous_path(str, len))
292
+ if (len && ambiguous_path(str, len))
293
return -1;
294
295
- refs_found = dwim_ref(str, len, sha1, &real_ref);
295
+ if (!len && reflog_len) {
296
+ /* allow "@{...}" to mean the current branch reflog */
297
+ refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
298
+ } else
299
+ refs_found = dwim_ref(str, len, sha1, &real_ref);
300
301
if (!refs_found)
302
return -1;
@@ -312,11 +316,12 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
316
* In the mean time prevent people from getting used to
317
* such a synonym until the work is completed.
318
*/
315
- if (!strncmp("HEAD", str, len) &&
319
+ if (len && !strncmp("HEAD", str, len) &&
320
!strncmp(real_ref, "refs/", 5)) {
321
error("reflog for HEAD has not been implemented yet\n"
318
- "Maybe you could try %s%s instead.",
319
- strchr(real_ref+5, '/')+1, str + len);
322
+ "Maybe you could try %s%s instead, "
323
+ "or just %s for current branch..",
324
+ strchr(real_ref+5, '/')+1, str+len, str+len);
325
exit(-1);
326
}
327