Merge branch 'jc/abbrev-guard'
authorJunio C Hamano <gitster@pobox.com>
Sat, 4 Dec 2010 00:10:35 +0000 (16:10 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 4 Dec 2010 00:10:35 +0000 (16:10 -0800)
* jc/abbrev-guard:
core.abbrevguard: Ensure short object names stay unique a bit longer

1  2 
Documentation/config.txt
cache.h
config.c
sha1_name.c
diff --combined Documentation/config.txt
index 6b7279f88303e2d7a45baa27022cb9e53cf387be,6994338c905460da63d5266af3a9ea6af60ec636..ad5eb5f21d8cf3ea011f01a3b4bc8289877a1c89
@@@ -374,6 -374,15 +374,15 @@@ core.warnAmbiguousRefs:
        If true, git will warn you if the ref name you passed it is ambiguous
        and might match multiple refs in the .git/refs/ tree. True by default.
  
+ core.abbrevguard::
+       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.
+       Defaults to 0.
  core.compression::
        An integer -1..9, indicating a default compression level.
        -1 is the zlib default. 0 means no compression,
@@@ -554,13 -563,9 +563,13 @@@ core.sparseCheckout:
        linkgit:git-read-tree[1] for more information.
  
  add.ignore-errors::
 +add.ignoreErrors::
        Tells 'git add' to continue adding files when some files cannot be
        added due to indexing errors. Equivalent to the '--ignore-errors'
 -      option of linkgit:git-add[1].
 +      option of linkgit:git-add[1].  Older versions of git accept only
 +      `add.ignore-errors`, which does not follow the usual naming
 +      convention for configuration variables.  Newer versions of git
 +      honor `add.ignoreErrors` as well.
  
  alias.*::
        Command aliases for the linkgit:git[1] command wrapper - e.g.
@@@ -605,9 -610,8 +614,9 @@@ branch.autosetupmerge:
        this behavior can be chosen per-branch using the `--track`
        and `--no-track` options. The valid settings are: `false` -- no
        automatic setup is done; `true` -- automatic setup is done when the
 -      starting point is a remote branch; `always` -- automatic setup is
 -      done when the starting point is either a local branch or remote
 +      starting point is a remote-tracking branch; `always` --
 +      automatic setup is done when the starting point is either a
 +      local branch or remote-tracking
        branch. This option defaults to true.
  
  branch.autosetuprebase::
        When `local`, rebase is set to true for tracked branches of
        other local branches.
        When `remote`, rebase is set to true for tracked branches of
 -      remote branches.
 +      remote-tracking branches.
        When `always`, rebase will be set to true for all tracking
        branches.
        See "branch.autosetupmerge" for details on how to set up a
@@@ -685,7 -689,7 +694,7 @@@ color.branch:
  color.branch.<slot>::
        Use customized color for branch coloration. `<slot>` is one of
        `current` (the current branch), `local` (a local branch),
 -      `remote` (a tracking branch in refs/remotes/), `plain` (other
 +      `remote` (a remote-tracking branch in refs/remotes/), `plain` (other
        refs).
  +
  The value for these configuration variables is a list of colors (at most
@@@ -713,7 -717,7 +722,7 @@@ color.diff.<slot>:
  color.decorate.<slot>::
        Use customized color for 'git log --decorate' output.  `<slot>` is one
        of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local
 -      branches, remote tracking branches, tags, stash and HEAD, respectively.
 +      branches, remote-tracking branches, tags, stash and HEAD, respectively.
  
  color.grep::
        When set to `always`, always highlight matches.  When `false` (or
@@@ -1107,7 -1111,7 +1116,7 @@@ gui.newbranchtemplate:
        linkgit:git-gui[1].
  
  gui.pruneduringfetch::
 -      "true" if linkgit:git-gui[1] should prune tracking branches when
 +      "true" if linkgit:git-gui[1] should prune remote-tracking branches when
        performing a fetch. The default value is "false".
  
  gui.trustmtime::
diff --combined cache.h
index d85ce86f7fd72ee90553241316c1cf6d84a2898d,931fb597ee53be6bd8272025988da2be36b62fa3..e56a0a23ae9e81ea4b691c6d365491a6ecb41f62
+++ b/cache.h
@@@ -545,6 -545,7 +545,7 @@@ extern int assume_unchanged
  extern int prefer_symlink_refs;
  extern int log_all_ref_updates;
  extern int warn_ambiguous_refs;
+ extern int unique_abbrev_extra_length;
  extern int shared_repository;
  extern const char *apply_default_whitespace;
  extern const char *apply_default_ignorewhitespace;
@@@ -859,7 -860,7 +860,7 @@@ struct cache_def 
  
  extern int has_symlink_leading_path(const char *name, int len);
  extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
 -extern int has_symlink_or_noent_leading_path(const char *name, int len);
 +extern int check_leading_path(const char *name, int len);
  extern int has_dirs_only_path(const char *name, int len, int prefix_len);
  extern void schedule_dir_for_removal(const char *name, int len);
  extern void remove_scheduled_dirs(void);
diff --combined config.c
index c63d6834e087bbe2469cb285d3b3de475b76b972,1aa72c2c41719327b62805a38703a124da6d30be..f138c34721b4751f3e8b0a1d10680f70ebfa2741
+++ b/config.c
@@@ -489,6 -489,13 +489,13 @@@ static int git_default_core_config(cons
                return 0;
        }
  
+       if (!strcmp(var, "core.abbrevguard")) {
+               unique_abbrev_extra_length = git_config_int(var, value);
+               if (unique_abbrev_extra_length < 0)
+                       unique_abbrev_extra_length = 0;
+               return 0;
+       }
        if (!strcmp(var, "core.bare")) {
                is_bare_repository_cfg = git_config_bool(var, value);
                return 0;
@@@ -871,7 -878,9 +878,7 @@@ int git_config(config_fn_t fn, void *da
        if (config_parameters)
                found += 1;
  
 -      if (found == 0)
 -              return -1;
 -      return ret;
 +      return ret == 0 ? found : ret;
  }
  
  /*
diff --combined sha1_name.c
index 3e856b80369c289a3d9399d60ec3be22bbbc6788,4a226adeceaff62f8d10e905149a05ef3c2d894c..b48b91c507e597405274dc5aa3edc98ee5149bdc
@@@ -206,7 -206,9 +206,9 @@@ const char *find_unique_abbrev(const un
                if (exists
                    ? !status
                    : status == SHORT_NAME_NOT_FOUND) {
-                       hex[len] = 0;
+                       int cut_at = len + unique_abbrev_extra_length;
+                       cut_at = (cut_at < 40) ? cut_at : 40;
+                       hex[cut_at] = 0;
                        return hex;
                }
                len++;
@@@ -1069,7 -1071,6 +1071,7 @@@ int get_sha1_with_context_1(const char 
                struct cache_entry *ce;
                int pos;
                if (namelen > 2 && name[1] == '/')
 +                      /* don't need mode for commit */
                        return get_sha1_oneline(name + 2, sha1);
                if (namelen < 3 ||
                    name[2] != ':' ||
                                break;
                        if (ce_stage(ce) == stage) {
                                hashcpy(sha1, ce->sha1);
 +                              oc->mode = ce->ce_mode;
                                return 0;
                        }
                        pos++;