Merge branch 'mm/include-userpath' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 May 2012 17:33:05 +0000 (10:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 May 2012 17:33:05 +0000 (10:33 -0700)
By Jeff King
* mm/include-userpath:
config: expand tildes in include.path variable

1  2 
config.c
diff --combined config.c
index 9ef947e073f487c035d0317572fe3733de8f0ad5,2bbf02d1e8c2c05f9fba1149c307c1b3b06517fd..ac69cb62935cfe86fec4b557ad6546366e6b7d70
+++ b/config.c
@@@ -37,6 -37,11 +37,11 @@@ static int handle_path_include(const ch
  {
        int ret = 0;
        struct strbuf buf = STRBUF_INIT;
+       char *expanded = expand_user_path(path);
+       if (!expanded)
+               return error("Could not expand include path '%s'", path);
+       path = expanded;
  
        /*
         * Use an absolute path as-is, but interpret relative paths
@@@ -63,6 -68,7 +68,7 @@@
                inc->depth--;
        }
        strbuf_release(&buf);
+       free(expanded);
        return ret;
  }
  
@@@ -1552,42 -1558,20 +1558,42 @@@ static int section_name_match (const ch
        return 0;
  }
  
 +static int section_name_is_ok(const char *name)
 +{
 +      /* Empty section names are bogus. */
 +      if (!*name)
 +              return 0;
 +
 +      /*
 +       * Before a dot, we must be alphanumeric or dash. After the first dot,
 +       * anything goes, so we can stop checking.
 +       */
 +      for (; *name && *name != '.'; name++)
 +              if (*name != '-' && !isalnum(*name))
 +                      return 0;
 +      return 1;
 +}
 +
  /* if new_name == NULL, the section is removed instead */
  int git_config_rename_section_in_file(const char *config_filename,
                                      const char *old_name, const char *new_name)
  {
        int ret = 0, remove = 0;
        char *filename_buf = NULL;
 -      struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1);
 +      struct lock_file *lock;
        int out_fd;
        char buf[1024];
        FILE *config_file;
  
 +      if (new_name && !section_name_is_ok(new_name)) {
 +              ret = error("invalid section name: %s", new_name);
 +              goto out;
 +      }
 +
        if (!config_filename)
                config_filename = filename_buf = git_pathdup("config");
  
 +      lock = xcalloc(sizeof(struct lock_file), 1);
        out_fd = hold_lock_file_for_update(lock, config_filename, 0);
        if (out_fd < 0) {
                ret = error("could not lock config file %s", config_filename);