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 <artagnon@gmail.com> Bug-spotted-and-fixed-by: Thomas Rast Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
17bf4ff3cd
commit
305ebea06d
11
sha1_name.c
11
sha1_name.c
@ -517,12 +517,21 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
|
||||
}
|
||||
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
|
||||
&co_time, &co_tz, &co_cnt)) {
|
||||
if (!len) {
|
||||
if (!prefixcmp(real_ref, "refs/heads/")) {
|
||||
str = real_ref + 11;
|
||||
len = strlen(real_ref + 11);
|
||||
} else {
|
||||
/* detached HEAD */
|
||||
str = "HEAD";
|
||||
len = 4;
|
||||
}
|
||||
}
|
||||
if (at_time)
|
||||
warning("Log for '%.*s' only goes "
|
||||
"back to %s.", len, str,
|
||||
show_date(co_time, co_tz, DATE_RFC2822));
|
||||
else {
|
||||
free(real_ref);
|
||||
die("Log for '%.*s' only has %d entries.",
|
||||
len, str, co_cnt);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user