Merge branch 'lt/default-abbrev' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 3 Apr 2011 19:32:51 +0000 (12:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Apr 2011 19:32:51 +0000 (12:32 -0700)
* lt/default-abbrev:
Rename core.abbrevlength back to core.abbrev
Make the default abbrev length configurable

Documentation/config.txt
builtin/describe.c
cache.h
config.c
environment.c
index 1a571f41742af09f52cc31462f501521aacd00d9..52ffbf4efb8d17c22893112208c5864d4c19741d 100644 (file)
@@ -558,6 +558,12 @@ core.sparseCheckout::
        Enable "sparse checkout" feature. See section "Sparse checkout" in
        linkgit:git-read-tree[1] for more information.
 
+core.abbrev::
+       Set the length object names are abbreviated to.  If unspecified,
+       many commands abbreviate to 7 hexdigits, which may not be enough
+       for abbreviated object names to stay unique for sufficiently long
+       time.
+
 add.ignore-errors::
 add.ignoreErrors::
        Tells 'git add' to continue adding files when some files cannot be
index 3ba26dc8192d0a75d7e330d2f73d0d9841a6216c..4afd1504a666d670ec71bdbd61b09bc0530ed04b 100644 (file)
@@ -21,7 +21,7 @@ static int debug;     /* Display lots of verbose info */
 static int all;        /* Any valid ref can be used */
 static int tags;       /* Allow lightweight tags */
 static int longformat;
-static int abbrev = DEFAULT_ABBREV;
+static int abbrev = -1; /* unspecified */
 static int max_candidates = 10;
 static struct hash_table names;
 static int have_util;
@@ -420,7 +420,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                OPT_END(),
        };
 
+       git_config(git_default_config, NULL);
        argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
+       if (abbrev < 0)
+               abbrev = DEFAULT_ABBREV;
+
        if (max_candidates < 0)
                max_candidates = 0;
        else if (max_candidates > MAX_TAGS)
diff --git a/cache.h b/cache.h
index e637ca8e01a4a42044e217f4d2bcecabbee7c3b1..50de992c5c1d51fe6ad50c40c152bd63f84869d0 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -540,6 +540,7 @@ extern int trust_executable_bit;
 extern int trust_ctime;
 extern int quote_path_fully;
 extern int has_symlinks;
+extern int minimum_abbrev, default_abbrev;
 extern int ignore_case;
 extern int assume_unchanged;
 extern int prefer_symlink_refs;
@@ -759,8 +760,8 @@ static inline unsigned int hexval(unsigned char c)
 }
 
 /* Convert to/from hex/sha1 representation */
-#define MINIMUM_ABBREV 4
-#define DEFAULT_ABBREV 7
+#define MINIMUM_ABBREV minimum_abbrev
+#define DEFAULT_ABBREV default_abbrev
 
 struct object_context {
        unsigned char tree[20];
index fa740a6a60a49512b613f70add97d445f622afd2..749e5afc45ee17e840f0983f7c814a2c2efd6340 100644 (file)
--- a/config.c
+++ b/config.c
@@ -523,6 +523,14 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.abbrev")) {
+               int abbrev = git_config_int(var, value);
+               if (abbrev < minimum_abbrev || abbrev > 40)
+                       return -1;
+               default_abbrev = abbrev;
+               return 0;
+       }
+
        if (!strcmp(var, "core.loosecompression")) {
                int level = git_config_int(var, value);
                if (level == -1)
index c3efbb96084de04465f7eff45376cadc3ab2526b..33c806421e94257fcede0606d3d733249f447d08 100644 (file)
@@ -15,6 +15,7 @@ int user_ident_explicitly_given;
 int trust_executable_bit = 1;
 int trust_ctime = 1;
 int has_symlinks = 1;
+int minimum_abbrev = 4, default_abbrev = 7;
 int ignore_case;
 int assume_unchanged;
 int prefer_symlink_refs;