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

[PATCH 2/3] blame: handle --no-abbrev

From
Jeff King <peff@peff.net>
Date
Jan 6, 2017, 04:18 UTC
Message-ID
<20170106041808.bd6ts7tkhjqyju7r@sigill.intra.peff.net>
In-Reply-To
<20170106041541.rjzzofal5hscv6yi@sigill.intra.peff.net>

You can already ask blame for full sha1s with "-l" or with "--abbrev=40". But for consistency with other parts of Git, we should support "--no-abbrev".

Worse, blame already accepts --no-abbrev, but it's totally broken. When we see --no-abbrev, the abbrev variable is set to 0, which is then used as a printf precision. For regular sha1s, that means we print nothing at all (which is very wrong). For boundary commits we decrement it to "-1", which printf interprets as "no limit" (which is almost correct, except it misses the 39-length magic explained in the previous commit).

Let's detect --no-abbrev and behave as if --abbrev=40 was given.

Signed-off-by: Jeff King <peff@peff.net>
---
I also wondered if we needed to clamp this within MINIMUM_ABBREV, but
that is done for us already by the parseopt handler.
 builtin/blame.c  | 2 ++
 t/t8002-blame.sh | 4 ++++
 2 files changed, 6 insertions(+)
diff --git a/builtin/blame.c b/builtin/blame.c
index 1d312542de..c6170fed81 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2659,6 +2659,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	if (0 < abbrev && abbrev < GIT_SHA1_HEXSZ)
 		/* one more abbrev length is needed for the boundary commit */
 		abbrev++;
+	else if (!abbrev)
+		abbrev = GIT_SHA1_HEXSZ;
 
 	if (revs_file && read_ancestry(revs_file))
 		die_errno("reading graft file '%s' failed", revs_file);
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index c6347ad8fd..380e1c1054 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -114,4 +114,8 @@ test_expect_success 'blame --abbrev=40 behaves like -l' '
 	check_abbrev 39 --abbrev=40 ^HEAD
 '
 
+test_expect_success '--no-abbrev works like --abbrev=40' '
+	check_abbrev 40 --no-abbrev
+'
+
 test_done
-- 
2.11.0.519.g31435224cf
Previous: Jeff KingNext: Jeff King
Message 2 of 8 in “fixing some random blame corner cases”
  1. 0/3 fixing some random blame corner casesJeff King, Jan 6, 2017
  2. 2/3 blame: handle --no-abbrevJeff King, Jan 6, 2017
  3. 1/3 blame: fix alignment with --abbrev=40Jeff King, Jan 6, 2017
  4. 3/3 blame: output porcelain "previous" header for each fileJeff King, Jan 6, 2017
  5. Junio C HamanoJan 9, 2017
  6. Ævar Arnfjörð BjarmasonMar 27, 2017
  7. Jeff KingMar 27, 2017
  8. Junio C HamanoJan 8, 2017

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.