@matheusbsbs / matheus-bagliano / commits / dce9648916
Fork 0

Make the default abbrev length configurable

The default of 7 comes from fairly early in git development, when seven hex digits was a lot (it covers about 250+ million hash values). Back then I thought that 65k revisions was a lot (it was what we were about to hit in BK), and each revision tends to be about 5-10 new objects or so, so a million objects was a big number. These days, the kernel isn't even the largest git project, and even the kernel has about 220k revisions (_much_ bigger than the BK tree ever was) and we are approaching two million objects. At that point, seven hex digits is still unique for a lot of them, but when we're talking about just two orders of magnitude difference between number of objects and the hash size, there _will_ be collisions in truncated hash values. It's no longer even close to unrealistic - it happens all the time. We should both increase the default abbrev that was unrealistically small, _and_ add a way for people to set their own default per-project in the git config file. This is the first step to first make it configurable; the default of 7 is not raised yet. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Oct 28, 2010 at 11:28 UTC dce96489162b05ae3463741f7f0365ff56f0de36
5 files changed +23 -3
Documentation/config.txt
+6
@@ -567,6 +567,12 @@ core.sparseCheckout::
567 Enable "sparse checkout" feature. See section "Sparse checkout" in
568 linkgit:git-read-tree[1] for more information.
569
570 +core.abbrevLength::
571 + Set the length object names are abbreviated to. If unspecified,
572 + many commands abbreviate to 7 hexdigits, which may not be enough
573 + for abbreviated object names to stay unique for sufficiently long
574 + time.
575 +
576 add.ignore-errors::
577 add.ignoreErrors::
578 Tells 'git add' to continue adding files when some files cannot be
builtin/describe.c
+5 -1
@@ -21,7 +21,7 @@ static int debug; /* Display lots of verbose info */
21 static int all; /* Any valid ref can be used */
22 static int tags; /* Allow lightweight tags */
23 static int longformat;
24 -static int abbrev = DEFAULT_ABBREV;
24 +static int abbrev = -1; /* unspecified */
25 static int max_candidates = 10;
26 static struct hash_table names;
27 static int have_util;
@@ -420,7 +420,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
420 OPT_END(),
421 };
422
423 + git_config(git_default_config, NULL);
424 argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
425 + if (abbrev < 0)
426 + abbrev = DEFAULT_ABBREV;
427 +
428 if (max_candidates < 0)
429 max_candidates = 0;
430 else if (max_candidates > MAX_TAGS)
cache.h
+3 -2
@@ -540,6 +540,7 @@ extern int trust_executable_bit;
540 extern int trust_ctime;
541 extern int quote_path_fully;
542 extern int has_symlinks;
543 +extern int minimum_abbrev, default_abbrev;
544 extern int ignore_case;
545 extern int assume_unchanged;
546 extern int prefer_symlink_refs;
@@ -758,8 +759,8 @@ static inline unsigned int hexval(unsigned char c)
759 }
760
761 /* Convert to/from hex/sha1 representation */
761 -#define MINIMUM_ABBREV 4
762 -#define DEFAULT_ABBREV 7
762 +#define MINIMUM_ABBREV minimum_abbrev
763 +#define DEFAULT_ABBREV default_abbrev
764
765 struct object_context {
766 unsigned char tree[20];
config.c
+8
@@ -531,6 +531,14 @@ static int git_default_core_config(const char *var, const char *value)
531 return 0;
532 }
533
534 + if (!strcmp(var, "core.abbrevlength")) {
535 + int abbrev = git_config_int(var, value);
536 + if (abbrev < minimum_abbrev || abbrev > 40)
537 + return -1;
538 + default_abbrev = abbrev;
539 + return 0;
540 + }
541 +
542 if (!strcmp(var, "core.loosecompression")) {
543 int level = git_config_int(var, value);
544 if (level == -1)
environment.c
+1
@@ -15,6 +15,7 @@ int user_ident_explicitly_given;
15 int trust_executable_bit = 1;
16 int trust_ctime = 1;
17 int has_symlinks = 1;
18 +int minimum_abbrev = 4, default_abbrev = 7;
19 int ignore_case;
20 int assume_unchanged;
21 int prefer_symlink_refs;