summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorRamkumar Ramachandra <artagnon@gmail.com>2013-05-22 10:39:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-06-02 19:05:36 (GMT)
commit305ebea06d5e633e3d648c798b5e6bb2b9abf361 (patch)
tree766a685b88bbc1163e74599c636bbf118345a844 /sha1_name.c
parent17bf4ff3cd3d7fd4b252b81417df8be1b3b2b128 (diff)
downloadgit-305ebea06d5e633e3d648c798b5e6bb2b9abf361.zip
git-305ebea06d5e633e3d648c798b5e6bb2b9abf361.tar.gz
git-305ebea06d5e633e3d648c798b5e6bb2b9abf361.tar.bz2
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>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 416a673..01b36ea 100644
--- a/sha1_name.c
+++ b/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);
}