blame: handle --no-abbrev
authorJeff King <peff@peff.net>
Fri, 6 Jan 2017 04:18:08 +0000 (23:18 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Jan 2017 03:34:54 +0000 (19:34 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
t/t8002-blame.sh
index cbb7dc2ad9e9ce1504a412cf13480fb90d31e6b7..1fccbe6bff1995e75ec0081c7db15ae8a268ccd4 100644 (file)
@@ -2609,6 +2609,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);
index c6347ad8fde4fec09d96269ef8de4bcdd3bea275..380e1c1054de5d55a80cb558fea0791884ad7f38 100755 (executable)
@@ -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