path: root/builtin/rev-parse.c
diff options
authorJunio C Hamano <>2016-10-01 00:19:36 (GMT)
committerJunio C Hamano <>2016-10-03 19:54:22 (GMT)
commit7b5b7721affae7040cac77d647a5ec8628f0f845 (patch)
tree1eff2af4b3ac3ac51a7f193ca8b4f656ccf15de6 /builtin/rev-parse.c
parent65acfeacaa6e50c92a6ac18dc08356026a99b3f3 (diff)
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 <>
Diffstat (limited to 'builtin/rev-parse.c')
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 76cf05e..17cbfab 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -643,8 +643,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
filter &= ~(DO_FLAGS|DO_NOREV);
verify = 1;
- if (arg[7] == '=')
- abbrev = strtoul(arg + 8, NULL, 10);
+ if (!arg[7])
+ continue;
+ abbrev = strtoul(arg + 8, NULL, 10);
if (abbrev < MINIMUM_ABBREV)
else if (40 <= abbrev)