Skip to content

Commit 7b5b772

Browse files
committed
abbrev: prepare for new world order
The code that sets custom abbreviation length, in response to command line argument, often does something like this: if (skip_prefix(arg, "--abbrev=", &arg)) abbrev = atoi(arg); else if (!strcmp("--abbrev", &arg)) abbrev = DEFAULT_ABBREV; /* make the value sane */ if (abbrev < 0 || 40 < abbrev) abbrev = ... some sane value ... However, it is pointless to sanity-check and tweak the value obtained from DEFAULT_ABBREV. We are going to allow it to be initially set to -1 to signal that the default abbreviation length must be auto sized upon the first request to abbreviate, based on the number of objects in the repository, and when that happens, rejecting or tweaking a negative value to a "saner" one will negatively interfere with the auto sizing. The codepaths for git rev-parse --short <object> git diff --raw --abbrev do exactly that; allow them to pass possibly negative abbrevs intact, that will come from DEFAULT_ABBREV in the future. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 65acfea commit 7b5b772

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

builtin/rev-parse.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
643643
filter &= ~(DO_FLAGS|DO_NOREV);
644644
verify = 1;
645645
abbrev = DEFAULT_ABBREV;
646-
if (arg[7] == '=')
647-
abbrev = strtoul(arg + 8, NULL, 10);
646+
if (!arg[7])
647+
continue;
648+
abbrev = strtoul(arg + 8, NULL, 10);
648649
if (abbrev < MINIMUM_ABBREV)
649650
abbrev = MINIMUM_ABBREV;
650651
else if (40 <= abbrev)

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3399,7 +3399,7 @@ void diff_setup_done(struct diff_options *options)
33993399
*/
34003400
read_cache();
34013401
}
3402-
if (options->abbrev <= 0 || 40 < options->abbrev)
3402+
if (40 < options->abbrev)
34033403
options->abbrev = 40; /* full */
34043404

34053405
/*

0 commit comments

Comments
 (0)