core.abbrev=no disables abbreviations

This allows users to write hash-agnostic scripts and configs by disabling abbreviations. Using "-c core.abbrev=40" will be insufficient with SHA-256, and "-c core.abbrev=64" won't work with SHA-1 repos today. Signed-off-by: Eric Wong <e@80x24.org> [jc: tweaked implementation, added doc and a test] Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Sep 1, 2020 at 07:43 UTC a9ecaa06a7235e62a9cf4703a19463fcee4449c7
3 files changed +6
Documentation/config/core.txt
+2
@@ -625,4 +625,6 @@ core.abbrev::
625 computed based on the approximate number of packed objects
626 in your repository, which hopefully is enough for
627 abbreviated object names to stay unique for some time.
628 + If set to "no", no abbreviation is made and the object names
629 + are shown in their full length.
630 The minimum length is 4.
config.c
+2
@@ -1217,6 +1217,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
1217 return config_error_nonbool(var);
1218 if (!strcasecmp(value, "auto"))
1219 default_abbrev = -1;
1220 + else if (!git_parse_maybe_bool_text(value))
1221 + default_abbrev = the_hash_algo->hexsz;
1222 else {
1223 int abbrev = git_config_int(var, value);
1224 if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
t/t3200-branch.sh
+2
@@ -305,7 +305,9 @@ test_expect_success 'git branch --list -v with --abbrev' '
305
306 git branch -v --list --no-abbrev t >actual.noabbrev &&
307 git branch -v --list --abbrev=0 t >actual.0abbrev &&
308 + git -c core.abbrev=no branch -v --list t >actual.noabbrev-conf &&
309 test_cmp actual.noabbrev actual.0abbrev &&
310 + test_cmp actual.noabbrev actual.noabbrev-conf &&
311
312 git branch -v --list --abbrev=36 t >actual.36abbrev &&
313 # how many hexdigits are used?