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

[PATCH 2/2] checkout: do not write full sha1 to reflog

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 15, 2013, 17:38 UTC
Message-ID
<1371317906-3991-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371317906-3991-1-git-send-email-artagnon@gmail.com>
A snippet from a typical git session may look like this:
  $ git checkout @~3
  ...
  $ git checkout -
The reflog entries corresponding to the two checkouts look like:
  f855138: checkout: moving from bdff0e3a374617dce784f801b97500d9ba2e4705 to co-reflog
  bdff0e3: checkout: moving from co-reflog to HEAD~3

There is no need to write the full SHA-1 to the user-visible reflog; use find_unique_abbrev() to shorten the first line like:

  f855138: checkout: moving from bdff0e3 to co-reflog
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/checkout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f5b50e5..41b1929 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -619,7 +619,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 
 	old_desc = old->name;
 	if (!old_desc && old->commit)
-		old_desc = sha1_to_hex(old->commit->object.sha1);
+		old_desc = find_unique_abbrev(old->commit->object.sha1, DEFAULT_ABBREV);
 	strbuf_addf(&msg, "checkout: moving from %s to %s",
 		    old_desc ? old_desc : "(invalid)", new->name);
 
-- 
1.8.3.1.438.g96d34e8
Previous: Junio C HamanoNext: Ramkumar Ramachandra
Message 6 of 10 in “Slightly prettier reflog message from checkout”
  1. 0/2 Slightly prettier reflog message from checkoutRamkumar Ramachandra, Jun 15, 2013
  2. 1/2 sha1_name: stop hard-coding 40-character hex checksRamkumar Ramachandra, Jun 15, 2013
  3. Phil HordJun 16, 2013
  4. Ramkumar RamachandraJun 18, 2013
  5. Junio C HamanoJun 18, 2013
  6. 2/2 checkout: do not write full sha1 to reflogRamkumar Ramachandra, Jun 15, 2013
  7. Ramkumar RamachandraJun 15, 2013
  8. Junio C HamanoJun 16, 2013
  9. Ramkumar RamachandraJun 16, 2013
  10. Junio C HamanoJun 17, 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.