core.abbrevguard: Ensure short object names stay unique a bit longer
Even though git makes sure that it uses enough hexdigits to show an abbreviated object name unambiguously, as more objects are added to the repository over time, a short name that used to be unique will stop being unique. Git uses this many extra hexdigits that are more than necessary to make the object name currently unique, in the hope that its output will stay unique a bit longer. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 28, 2010 at 14:39 UTC
72a5b561fc1c4286bc7c5b0693afc076af261e1f
5 files changed
+21
-1
Documentation/config.txt
+9
@@ -374,6 +374,15 @@ core.warnAmbiguousRefs::
374
If true, git will warn you if the ref name you passed it is ambiguous
375
and might match multiple refs in the .git/refs/ tree. True by default.
376
377
+core.abbrevguard::
378
+ Even though git makes sure that it uses enough hexdigits to show
379
+ an abbreviated object name unambiguously, as more objects are
380
+ added to the repository over time, a short name that used to be
381
+ unique will stop being unique. Git uses this many extra hexdigits
382
+ that are more than necessary to make the object name currently
383
+ unique, in the hope that its output will stay unique a bit longer.
384
+ Defaults to 0.
385
+
386
core.compression::
387
An integer -1..9, indicating a default compression level.
388
-1 is the zlib default. 0 means no compression,
cache.h
+1
@@ -545,6 +545,7 @@ extern int assume_unchanged;
545
extern int prefer_symlink_refs;
546
extern int log_all_ref_updates;
547
extern int warn_ambiguous_refs;
548
+extern int unique_abbrev_extra_length;
549
extern int shared_repository;
550
extern const char *apply_default_whitespace;
551
extern const char *apply_default_ignorewhitespace;
config.c
+7
@@ -489,6 +489,13 @@ static int git_default_core_config(const char *var, const char *value)
489
return 0;
490
}
491
492
+ if (!strcmp(var, "core.abbrevguard")) {
493
+ unique_abbrev_extra_length = git_config_int(var, value);
494
+ if (unique_abbrev_extra_length < 0)
495
+ unique_abbrev_extra_length = 0;
496
+ return 0;
497
+ }
498
+
499
if (!strcmp(var, "core.bare")) {
500
is_bare_repository_cfg = git_config_bool(var, value);
501
return 0;
environment.c
+1
@@ -21,6 +21,7 @@ int prefer_symlink_refs;
21
int is_bare_repository_cfg = -1; /* unspecified */
22
int log_all_ref_updates = -1; /* unspecified */
23
int warn_ambiguous_refs = 1;
24
+int unique_abbrev_extra_length;
25
int repository_format_version;
26
const char *git_commit_encoding;
27
const char *git_log_output_encoding;
sha1_name.c
+3
-1
@@ -206,7 +206,9 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
206
if (exists
207
? !status
208
: status == SHORT_NAME_NOT_FOUND) {
209
- hex[len] = 0;
209
+ int cut_at = len + unique_abbrev_extra_length;
210
+ cut_at = (cut_at < 40) ? cut_at : 40;
211
+ hex[cut_at] = 0;
212
return hex;
213
}
214
len++;