Merge branch 'lp/config-vername-check'
authorJunio C Hamano <gitster@pobox.com>
Mon, 28 Feb 2011 05:58:31 +0000 (21:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Feb 2011 05:58:31 +0000 (21:58 -0800)
* lp/config-vername-check:
  Disallow empty section and variable names
  Sanity-check config variable names

1  2 
builtin/config.c
cache.h

diff --combined builtin/config.c
index e27415df90c67c12452e8c60949bcc05462a10e5,6754da8f5e9df0156f0ac32b10724202b893a7fd..76be0b786fd52f181f91b5ad3bdef891068946f1
@@@ -52,7 -52,7 +52,7 @@@ static struct option builtin_config_opt
        OPT_BOOLEAN(0, "global", &use_global_config, "use global config file"),
        OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"),
        OPT_BOOLEAN(0, "local", &use_local_config, "use repository config file"),
 -      OPT_STRING('f', "file", &given_config_file, "FILE", "use given config file"),
 +      OPT_STRING('f', "file", &given_config_file, "file", "use given config file"),
        OPT_GROUP("Action"),
        OPT_BIT(0, "get", &actions, "get value: name [value-regex]", ACTION_GET),
        OPT_BIT(0, "get-all", &actions, "get all values: key [value-regex]", ACTION_GET_ALL),
@@@ -153,7 -153,6 +153,6 @@@ static int show_config(const char *key_
  static int get_value(const char *key_, const char *regex_)
  {
        int ret = -1;
-       char *tl;
        char *global = NULL, *repo_config = NULL;
        const char *system_wide = NULL, *local;
  
                        system_wide = git_etc_gitconfig();
        }
  
-       key = xstrdup(key_);
-       for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)
-               *tl = tolower(*tl);
-       for (tl=key; *tl && *tl != '.'; ++tl)
-               *tl = tolower(*tl);
        if (use_key_regexp) {
+               char *tl;
+               /*
+                * NEEDSWORK: this naive pattern lowercasing obviously does not
+                * work for more complex patterns like "^[^.]*Foo.*bar".
+                * Perhaps we should deprecate this altogether someday.
+                */
+               key = xstrdup(key_);
+               for (tl = key + strlen(key) - 1;
+                    tl >= key && *tl != '.';
+                    tl--)
+                       *tl = tolower(*tl);
+               for (tl = key; *tl && *tl != '.'; tl++)
+                       *tl = tolower(*tl);
                key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(key_regexp, key, REG_EXTENDED)) {
                        fprintf(stderr, "Invalid key pattern: %s\n", key_);
+                       free(key);
                        goto free_strings;
                }
+       } else {
+               if (git_config_parse_key(key_, &key, NULL))
+                       goto free_strings;
        }
  
        if (regex_) {
@@@ -500,9 -513,3 +513,9 @@@ int cmd_config(int argc, const char **a
  
        return 0;
  }
 +
 +int cmd_repo_config(int argc, const char **argv, const char *prefix)
 +{
 +      fprintf(stderr, "WARNING: git repo-config is deprecated in favor of git config.\n");
 +      return cmd_config(argc, argv, prefix);
 +}
diff --combined cache.h
index 5cc2f896dc10cfb8b432fb4b3ee97b0134f73c11,1e32d63fb585a0fd45e2512f6f74726130510f06..79723aac749ff1cd850b0933f188bd859885f8ec
+++ b/cache.h
@@@ -500,23 -500,8 +500,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;
 +      int has_wildcard:1;
 +      int recursive:1;
 +      int max_depth;
 +      struct pathspec_item {
 +              const char *match;
 +              int len;
 +              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;
@@@ -691,11 -676,9 +691,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);
  
@@@ -1014,6 -997,7 +1014,7 @@@ 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);