Skip to content

Commit 11cf880

Browse files
Nicolas PitreJunio C Hamano
authored andcommitted
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>
1 parent fe55851 commit 11cf880

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

sha1_name.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
279279
/* basic@{time or number} format to query ref-log */
280280
reflog_len = at = 0;
281281
if (str[len-1] == '}') {
282-
for (at = 1; at < len - 1; at++) {
282+
for (at = 0; at < len - 1; at++) {
283283
if (str[at] == '@' && str[at+1] == '{') {
284284
reflog_len = (len-1) - (at+2);
285285
len = at;
@@ -289,10 +289,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
289289
}
290290

291291
/* Accept only unambiguous ref paths. */
292-
if (ambiguous_path(str, len))
292+
if (len && ambiguous_path(str, len))
293293
return -1;
294294

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);
296300

297301
if (!refs_found)
298302
return -1;
@@ -312,11 +316,12 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
312316
* In the mean time prevent people from getting used to
313317
* such a synonym until the work is completed.
314318
*/
315-
if (!strncmp("HEAD", str, len) &&
319+
if (len && !strncmp("HEAD", str, len) &&
316320
!strncmp(real_ref, "refs/", 5)) {
317321
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);
320325
exit(-1);
321326
}
322327

0 commit comments

Comments
 (0)