git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] sha1_name: fix error message for @{<N>}, @{<date>}

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 22, 2013, 10:39 UTC
Message-ID
<1369219195-20096-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1369219195-20096-1-git-send-email-artagnon@gmail.com>

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 ugly, inconsistent, and failing to 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.

Simple, consistent, and informative; suitable for output even from plumbing commands like rev-parse.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sha1_name.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/sha1_name.c b/sha1_name.c
index 416a673..b7e008a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -517,6 +517,16 @@ 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,
-- 
1.8.3.rc3.10.g6f8d616
Previous: Ramkumar RamachandraNext: Eric Sunshine
Message 5 of 6 in “Fix invalid revision error messages”
  1. 0/2 Fix invalid revision error messagesRamkumar Ramachandra, May 22, 2013
  2. 1/2 sha1_name: fix error message for @{u}Ramkumar Ramachandra, May 22, 2013
  3. Junio C HamanoMay 22, 2013
  4. Ramkumar RamachandraMay 23, 2013
  5. 2/2 sha1_name: fix error message for @{<N>}, @{<date>}Ramkumar Ramachandra, May 22, 2013
  6. Eric SunshineMay 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.