]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'lt/default-abbrev'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 21:55:40 +0000 (14:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 21:55:40 +0000 (14:55 -0700)
* lt/default-abbrev:
  Rename core.abbrevlength back to core.abbrev
  Make the default abbrev length configurable

1  2 
Documentation/config.txt
builtin/describe.c
cache.h
config.c
environment.c

diff --combined Documentation/config.txt
index 701fba92dc1cfda8982aee8b66eb39b8b1c5816b,dacbcdeb793f7803bef887c20bd1eae4bdc857a6..8ea55d46add1da6d1e810cb126a7ecc5ce456650
@@@ -376,6 -376,15 +376,6 @@@ 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,
@@@ -558,6 -567,12 +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
@@@ -1582,8 -1597,7 +1588,8 @@@ push.default:
  * `matching` - push all matching branches.
    All branches having the same name in both ends are considered to be
    matching. This is the default.
 -* `tracking` - push the current branch to its upstream branch.
 +* `upstream` - push the current branch to its upstream branch.
 +* `tracking` - deprecated synonym for `upstream`.
  * `current` - push the current branch to a branch of the same name.
  
  rebase.stat::
diff --combined builtin/describe.c
index 3ba26dc8192d0a75d7e330d2f73d0d9841a6216c,95915960d46a2e6b6f222da07b99bcaa428dde42..4afd1504a666d670ec71bdbd61b09bc0530ed04b
@@@ -21,7 -21,7 +21,7 @@@ static int debug;     /* Display lots of ve
  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;
@@@ -63,7 -63,7 +63,7 @@@ static inline struct commit_name *find_
        return n;
  }
  
 -static int set_util(void *chain)
 +static int set_util(void *chain, void *data)
  {
        struct commit_name *n;
        for (n = chain; n; n = n->next) {
@@@ -289,7 -289,7 +289,7 @@@ static void describe(const char *arg, i
                fprintf(stderr, "searching to describe %s\n", arg);
  
        if (!have_util) {
 -              for_each_hash(&names, set_util);
 +              for_each_hash(&names, set_util, NULL);
                have_util = 1;
        }
  
@@@ -420,7 -420,11 +420,11 @@@ int cmd_describe(int argc, const char *
                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 --combined cache.h
index 872bc9be11d8236673a96ea7ba9c9b77b72034b0,8d73d88962f3f1be42fa4fddb69b115b6dbf0a76..f765cf5da2af379106e0e4e2d99780a268ad21fa
+++ b/cache.h
@@@ -5,7 -5,6 +5,7 @@@
  #include "strbuf.h"
  #include "hash.h"
  #include "advice.h"
 +#include "gettext.h"
  
  #include SHA1_HEADER
  #ifndef git_SHA_CTX
@@@ -501,23 -500,8 +501,23 @@@ extern int index_name_is_other(const st
  extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  
 -extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
 -extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
 +struct pathspec {
 +      const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
 +      int nr;
 +      unsigned int has_wildcard:1;
 +      unsigned int recursive:1;
 +      int max_depth;
 +      struct pathspec_item {
 +              const char *match;
 +              int len;
 +              unsigned int has_wildcard:1;
 +      } *items;
 +};
 +
 +extern int init_pathspec(struct pathspec *, const char **);
 +extern void free_pathspec(struct pathspec *);
 +extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
 +extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path, int format_check);
  extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
  extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
  
  #define REFRESH_IGNORE_MISSING        0x0008  /* ignore non-existent */
  #define REFRESH_IGNORE_SUBMODULES     0x0010  /* ignore submodules */
  #define REFRESH_IN_PORCELAIN  0x0020  /* user friendly output, not "needs update" */
 -extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, char *header_msg);
 +extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, const char *header_msg);
  
  struct lock_file {
        struct lock_file *next;
@@@ -556,11 -540,13 +556,12 @@@ 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;
  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;
@@@ -586,7 -572,7 +587,7 @@@ extern enum safe_crlf safe_crlf
  enum auto_crlf {
        AUTO_CRLF_FALSE = 0,
        AUTO_CRLF_TRUE = 1,
 -      AUTO_CRLF_INPUT = -1,
 +      AUTO_CRLF_INPUT = -1
  };
  
  extern enum auto_crlf auto_crlf;
@@@ -623,7 -609,7 +624,7 @@@ enum rebase_setup_type 
  enum push_default_type {
        PUSH_DEFAULT_NOTHING = 0,
        PUSH_DEFAULT_MATCHING,
 -      PUSH_DEFAULT_TRACKING,
 +      PUSH_DEFAULT_UPSTREAM,
        PUSH_DEFAULT_CURRENT
  };
  
@@@ -691,11 -677,9 +692,11 @@@ static inline void hashclr(unsigned cha
  
  #define EMPTY_TREE_SHA1_HEX \
        "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
 -#define EMPTY_TREE_SHA1_BIN \
 +#define EMPTY_TREE_SHA1_BIN_LITERAL \
         "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
         "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
 +#define EMPTY_TREE_SHA1_BIN \
 +       ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
  
  int git_mkstemp(char *path, size_t n, const char *template);
  
@@@ -732,9 -716,9 +733,9 @@@ static inline int is_absolute_path(cons
        return path[0] == '/' || has_dos_drive_prefix(path);
  }
  int is_directory(const char *);
 -const char *make_absolute_path(const char *path);
 -const char *make_nonrelative_path(const char *path);
 -const char *make_relative_path(const char *abs, const char *base);
 +const char *real_path(const char *path);
 +const char *absolute_path(const char *path);
 +const char *relative_path(const char *abs, const char *base);
  int normalize_path_copy(char *dst, const char *src);
  int longest_ancestor_length(const char *path, const char *prefix_list);
  char *strip_path_suffix(const char *path, const char *suffix);
@@@ -775,8 -759,8 +776,8 @@@ static inline unsigned int hexval(unsig
  }
  
  /* 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];
@@@ -914,8 -898,7 +915,8 @@@ extern struct packed_git 
        time_t mtime;
        int pack_fd;
        unsigned pack_local:1,
 -               pack_keep:1;
 +               pack_keep:1,
 +               do_not_close:1;
        unsigned char sha1[20];
        /* something like ".git/objects/pack/xxxxx.pack" */
        char pack_name[FLEX_ARRAY]; /* more */
@@@ -1015,13 -998,13 +1016,13 @@@ extern int git_config_maybe_bool(const 
  extern int git_config_string(const char **, const char *, const char *);
  extern int git_config_pathname(const char **, const char *, const char *);
  extern int git_config_set(const char *, const char *);
 +extern int git_config_parse_key(const char *, char **, int *);
  extern int git_config_set_multivar(const char *, const char *, const char *, int);
  extern int git_config_rename_section(const char *, const char *);
  extern const char *git_etc_gitconfig(void);
  extern int check_repository_format_version(const char *var, const char *value, void *cb);
  extern int git_env_bool(const char *, int);
  extern int git_config_system(void);
 -extern int git_config_global(void);
  extern int config_error_nonbool(const char *);
  extern const char *get_log_output_encoding(void);
  extern const char *get_commit_output_encoding(void);
@@@ -1083,14 -1066,9 +1084,14 @@@ extern void alloc_report(void)
  /* trace.c */
  __attribute__((format (printf, 1, 2)))
  extern void trace_printf(const char *format, ...);
 +extern void trace_vprintf(const char *key, const char *format, va_list ap);
  __attribute__((format (printf, 2, 3)))
  extern void trace_argv_printf(const char **argv, const char *format, ...);
  extern void trace_repo_setup(const char *prefix);
 +extern int trace_want(const char *key);
 +extern void trace_strbuf(const char *key, const struct strbuf *buf);
 +
 +void packet_trace_identity(const char *prog);
  
  /* convert.c */
  /* returns 1 if *dst was used */
diff --combined config.c
index e28197a3f64cb8672f8aeef26cc0402c7c22548d,79e6c1896e5a901a3b70cefa621524275046e7ba..0abcada9381a3e6638f94bcf41bf9ee7b96f4de8
+++ b/config.c
@@@ -20,7 -20,8 +20,7 @@@ static int zlib_compression_seen
  
  const char *config_exclusive_filename = NULL;
  
 -struct config_item
 -{
 +struct config_item {
        struct config_item *next;
        char *name;
        char *value;
@@@ -498,6 -499,13 +498,6 @@@ 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;
                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)
@@@ -729,10 -745,8 +737,10 @@@ static int git_default_push_config(cons
                        push_default = PUSH_DEFAULT_NOTHING;
                else if (!strcmp(value, "matching"))
                        push_default = PUSH_DEFAULT_MATCHING;
 -              else if (!strcmp(value, "tracking"))
 -                      push_default = PUSH_DEFAULT_TRACKING;
 +              else if (!strcmp(value, "upstream"))
 +                      push_default = PUSH_DEFAULT_UPSTREAM;
 +              else if (!strcmp(value, "tracking")) /* deprecated */
 +                      push_default = PUSH_DEFAULT_UPSTREAM;
                else if (!strcmp(value, "current"))
                        push_default = PUSH_DEFAULT_CURRENT;
                else {
@@@ -825,6 -839,11 +833,6 @@@ int git_config_system(void
        return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
  }
  
 -int git_config_global(void)
 -{
 -      return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
 -}
 -
  int git_config_from_parameters(config_fn_t fn, void *data)
  {
        static int loaded_environment;
@@@ -856,7 -875,7 +864,7 @@@ int git_config_early(config_fn_t fn, vo
        }
  
        home = getenv("HOME");
 -      if (git_config_global() && home) {
 +      if (home) {
                char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
                if (!access(user_config, R_OK)) {
                        ret += git_config_from_file(fn, user_config, data);
@@@ -1087,75 -1106,6 +1095,75 @@@ int git_config_set(const char *key, con
        return git_config_set_multivar(key, value, NULL, 0);
  }
  
 +/*
 + * Auxiliary function to sanity-check and split the key into the section
 + * identifier and variable name.
 + *
 + * Returns 0 on success, -1 when there is an invalid character in the key and
 + * -2 if there is no section name in the key.
 + *
 + * store_key - pointer to char* which will hold a copy of the key with
 + *             lowercase section and variable name
 + * baselen - pointer to int which will hold the length of the
 + *           section + subsection part, can be NULL
 + */
 +int git_config_parse_key(const char *key, char **store_key, int *baselen_)
 +{
 +      int i, dot, baselen;
 +      const char *last_dot = strrchr(key, '.');
 +
 +      /*
 +       * Since "key" actually contains the section name and the real
 +       * key name separated by a dot, we have to know where the dot is.
 +       */
 +
 +      if (last_dot == NULL || last_dot == key) {
 +              error("key does not contain a section: %s", key);
 +              return -2;
 +      }
 +
 +      if (!last_dot[1]) {
 +              error("key does not contain variable name: %s", key);
 +              return -2;
 +      }
 +
 +      baselen = last_dot - key;
 +      if (baselen_)
 +              *baselen_ = baselen;
 +
 +      /*
 +       * Validate the key and while at it, lower case it for matching.
 +       */
 +      *store_key = xmalloc(strlen(key) + 1);
 +
 +      dot = 0;
 +      for (i = 0; key[i]; i++) {
 +              unsigned char c = key[i];
 +              if (c == '.')
 +                      dot = 1;
 +              /* Leave the extended basename untouched.. */
 +              if (!dot || i > baselen) {
 +                      if (!iskeychar(c) ||
 +                          (i == baselen + 1 && !isalpha(c))) {
 +                              error("invalid key: %s", key);
 +                              goto out_free_ret_1;
 +                      }
 +                      c = tolower(c);
 +              } else if (c == '\n') {
 +                      error("invalid key (newline): %s", key);
 +                      goto out_free_ret_1;
 +              }
 +              (*store_key)[i] = c;
 +      }
 +      (*store_key)[i] = 0;
 +
 +      return 0;
 +
 +out_free_ret_1:
 +      free(*store_key);
 +      return -1;
 +}
 +
  /*
   * If value==NULL, unset in (remove from) config,
   * if value_regex!=NULL, disregard key/value pairs where value does not match.
  int git_config_set_multivar(const char *key, const char *value,
        const char *value_regex, int multi_replace)
  {
 -      int i, dot;
        int fd = -1, in_fd;
        int ret;
        char *config_filename;
        struct lock_file *lock = NULL;
 -      const char *last_dot = strrchr(key, '.');
  
        if (config_exclusive_filename)
                config_filename = xstrdup(config_exclusive_filename);
        else
                config_filename = git_pathdup("config");
  
 -      /*
 -       * Since "key" actually contains the section name and the real
 -       * key name separated by a dot, we have to know where the dot is.
 -       */
 -
 -      if (last_dot == NULL) {
 -              error("key does not contain a section: %s", key);
 -              ret = 2;
 +      /* parse-key returns negative; flip the sign to feed exit(3) */
 +      ret = 0 - git_config_parse_key(key, &store.key, &store.baselen);
 +      if (ret)
                goto out_free;
 -      }
 -      store.baselen = last_dot - key;
  
        store.multi_replace = multi_replace;
  
 -      /*
 -       * Validate the key and while at it, lower case it for matching.
 -       */
 -      store.key = xmalloc(strlen(key) + 1);
 -      dot = 0;
 -      for (i = 0; key[i]; i++) {
 -              unsigned char c = key[i];
 -              if (c == '.')
 -                      dot = 1;
 -              /* Leave the extended basename untouched.. */
 -              if (!dot || i > store.baselen) {
 -                      if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {
 -                              error("invalid key: %s", key);
 -                              free(store.key);
 -                              ret = 1;
 -                              goto out_free;
 -                      }
 -                      c = tolower(c);
 -              } else if (c == '\n') {
 -                      error("invalid key (newline): %s", key);
 -                      free(store.key);
 -                      ret = 1;
 -                      goto out_free;
 -              }
 -              store.key[i] = c;
 -      }
 -      store.key[i] = 0;
  
        /*
         * The lock serves a purpose in addition to locking: the new
diff --combined environment.c
index cc670b1562504f9cfe79247d98e50c62c50eaea5,f2d90a807b7d50cc3fb6dd7a5c017d0dbc2937dc..f4549d3f7b0367b31b0fa0042fb12ff183beb081
@@@ -15,12 -15,14 +15,13 @@@ 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;
  int is_bare_repository_cfg = -1; /* unspecified */
  int log_all_ref_updates = -1; /* unspecified */
  int warn_ambiguous_refs = 1;
 -int unique_abbrev_extra_length;
  int repository_format_version;
  const char *git_commit_encoding;
  const char *git_log_output_encoding;
@@@ -139,7 -141,7 +140,7 @@@ static int git_work_tree_initialized
  void set_git_work_tree(const char *new_work_tree)
  {
        if (git_work_tree_initialized) {
 -              new_work_tree = make_absolute_path(new_work_tree);
 +              new_work_tree = real_path(new_work_tree);
                if (strcmp(new_work_tree, work_tree))
                        die("internal error: work tree has already been set\n"
                            "Current worktree: %s\nNew worktree: %s",
                return;
        }
        git_work_tree_initialized = 1;
 -      work_tree = xstrdup(make_absolute_path(new_work_tree));
 +      work_tree = xstrdup(real_path(new_work_tree));
  }
  
  const char *get_git_work_tree(void)