Skip to content

Commit 305ebea

Browse files
artagnongitster
authored andcommitted
sha1_name: fix error message for @{<N>}, @{<date>}
Currently, when we try to resolve @{<N>} or @{<date>} when the reflog doesn't go back far enough, we get errors like: # on branch master $ git show @{10000} fatal: Log for '' only has 7 entries. $ git show @{10000.days.ago} warning: Log for '' only goes back to Tue, 21 May 2013 14:14:45 +0530. ... # detached HEAD case $ git show @{10000} fatal: Log for '' only has 2005 entries. $ git show master@{10000} fatal: Log for 'master' only has 7 entries. The empty string '' is confusing and does not convey information about whose logs we are inspecting. Change this so that we get: # on branch master $ git show @{10000} fatal: Log for 'master' only has 7 entries. $ git show @{10000.days.ago} warning: Log for 'master' only goes back to Tue, 21 May 2013 14:14:45 +0530. ... # detached HEAD case $ git show @{10000} fatal: Log for 'HEAD' only has 2005 entries. $ git show master@{10000} fatal: Log for 'master' only has 7 entries. Also one of the message strings given to die() now points into real_ref that was not used in that fashion, so stop freeing the underlying storage for it. Signed-off-by: Ramkumar Ramachandra <[email protected]> Bug-spotted-and-fixed-by: Thomas Rast Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17bf4ff commit 305ebea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sha1_name.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,21 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
517517
}
518518
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
519519
&co_time, &co_tz, &co_cnt)) {
520+
if (!len) {
521+
if (!prefixcmp(real_ref, "refs/heads/")) {
522+
str = real_ref + 11;
523+
len = strlen(real_ref + 11);
524+
} else {
525+
/* detached HEAD */
526+
str = "HEAD";
527+
len = 4;
528+
}
529+
}
520530
if (at_time)
521531
warning("Log for '%.*s' only goes "
522532
"back to %s.", len, str,
523533
show_date(co_time, co_tz, DATE_RFC2822));
524534
else {
525-
free(real_ref);
526535
die("Log for '%.*s' only has %d entries.",
527536
len, str, co_cnt);
528537
}

0 commit comments

Comments
 (0)