Skip to content

Commit ed58d80

Browse files
peffgitster
authored andcommitted
blame: handle --no-abbrev
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9122983 commit ed58d80

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

builtin/blame.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26092609
if (0 < abbrev && abbrev < GIT_SHA1_HEXSZ)
26102610
/* one more abbrev length is needed for the boundary commit */
26112611
abbrev++;
2612+
else if (!abbrev)
2613+
abbrev = GIT_SHA1_HEXSZ;
26122614

26132615
if (revs_file && read_ancestry(revs_file))
26142616
die_errno("reading graft file '%s' failed", revs_file);

t/t8002-blame.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@ test_expect_success 'blame --abbrev=40 behaves like -l' '
114114
check_abbrev 39 --abbrev=40 ^HEAD
115115
'
116116

117+
test_expect_success '--no-abbrev works like --abbrev=40' '
118+
check_abbrev 40 --no-abbrev
119+
'
120+
117121
test_done

0 commit comments

Comments
 (0)