Skip to content

Commit be57695

Browse files
committed
Merge branch 'lt/default-abbrev' into maint
* lt/default-abbrev: Rename core.abbrevlength back to core.abbrev Make the default abbrev length configurable
2 parents 3967c99 + a71f09f commit be57695

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ core.sparseCheckout::
558558
Enable "sparse checkout" feature. See section "Sparse checkout" in
559559
linkgit:git-read-tree[1] for more information.
560560

561+
core.abbrev::
562+
Set the length object names are abbreviated to. If unspecified,
563+
many commands abbreviate to 7 hexdigits, which may not be enough
564+
for abbreviated object names to stay unique for sufficiently long
565+
time.
566+
561567
add.ignore-errors::
562568
add.ignoreErrors::
563569
Tells 'git add' to continue adding files when some files cannot be

builtin/describe.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int debug; /* Display lots of verbose info */
2121
static int all; /* Any valid ref can be used */
2222
static int tags; /* Allow lightweight tags */
2323
static int longformat;
24-
static int abbrev = DEFAULT_ABBREV;
24+
static int abbrev = -1; /* unspecified */
2525
static int max_candidates = 10;
2626
static struct hash_table names;
2727
static int have_util;
@@ -420,7 +420,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
420420
OPT_END(),
421421
};
422422

423+
git_config(git_default_config, NULL);
423424
argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
425+
if (abbrev < 0)
426+
abbrev = DEFAULT_ABBREV;
427+
424428
if (max_candidates < 0)
425429
max_candidates = 0;
426430
else if (max_candidates > MAX_TAGS)

cache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ extern int trust_executable_bit;
540540
extern int trust_ctime;
541541
extern int quote_path_fully;
542542
extern int has_symlinks;
543+
extern int minimum_abbrev, default_abbrev;
543544
extern int ignore_case;
544545
extern int assume_unchanged;
545546
extern int prefer_symlink_refs;
@@ -759,8 +760,8 @@ static inline unsigned int hexval(unsigned char c)
759760
}
760761

761762
/* Convert to/from hex/sha1 representation */
762-
#define MINIMUM_ABBREV 4
763-
#define DEFAULT_ABBREV 7
763+
#define MINIMUM_ABBREV minimum_abbrev
764+
#define DEFAULT_ABBREV default_abbrev
764765

765766
struct object_context {
766767
unsigned char tree[20];

config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ static int git_default_core_config(const char *var, const char *value)
523523
return 0;
524524
}
525525

526+
if (!strcmp(var, "core.abbrev")) {
527+
int abbrev = git_config_int(var, value);
528+
if (abbrev < minimum_abbrev || abbrev > 40)
529+
return -1;
530+
default_abbrev = abbrev;
531+
return 0;
532+
}
533+
526534
if (!strcmp(var, "core.loosecompression")) {
527535
int level = git_config_int(var, value);
528536
if (level == -1)

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ int user_ident_explicitly_given;
1515
int trust_executable_bit = 1;
1616
int trust_ctime = 1;
1717
int has_symlinks = 1;
18+
int minimum_abbrev = 4, default_abbrev = 7;
1819
int ignore_case;
1920
int assume_unchanged;
2021
int prefer_symlink_refs;

0 commit comments

Comments
 (0)