]> git.ipfire.org Git - thirdparty/git.git/blobdiff - config.c
wildmatch: remove unused wildopts parameter
[thirdparty/git.git] / config.c
index a30056ec7e9a0cca87dea494a92a4671a19b7643..260caf27b87809363aa5ee4d1ffe4fd95ddb8874 100644 (file)
--- a/config.c
+++ b/config.c
@@ -214,6 +214,7 @@ static int include_by_gitdir(const struct config_options *opts,
        struct strbuf pattern = STRBUF_INIT;
        int ret = 0, prefix;
        const char *git_dir;
+       int already_tried_absolute = 0;
 
        if (opts->git_dir)
                git_dir = opts->git_dir;
@@ -226,6 +227,7 @@ static int include_by_gitdir(const struct config_options *opts,
        strbuf_add(&pattern, cond, cond_len);
        prefix = prepare_include_condition_pattern(&pattern);
 
+again:
        if (prefix < 0)
                goto done;
 
@@ -243,8 +245,22 @@ static int include_by_gitdir(const struct config_options *opts,
        }
 
        ret = !wildmatch(pattern.buf + prefix, text.buf + prefix,
-                        icase ? WM_CASEFOLD : 0, NULL);
+                        icase ? WM_CASEFOLD : 0);
 
+       if (!ret && !already_tried_absolute) {
+               /*
+                * We've tried e.g. matching gitdir:~/work, but if
+                * ~/work is a symlink to /mnt/storage/work
+                * strbuf_realpath() will expand it, so the rule won't
+                * match. Let's match against a
+                * strbuf_add_absolute_path() version of the path,
+                * which'll do the right thing
+                */
+               strbuf_reset(&text);
+               strbuf_add_absolute_path(&text, git_dir);
+               already_tried_absolute = 1;
+               goto again;
+       }
 done:
        strbuf_release(&pattern);
        strbuf_release(&text);
@@ -1422,7 +1438,7 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
        int ret = -1;
        FILE *f;
 
-       f = fopen(filename, "r");
+       f = fopen_or_warn(filename, "r");
        if (f) {
                flockfile(f);
                ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
@@ -1965,7 +1981,7 @@ int git_config_get_expiry(const char *key, const char **output)
        if (ret)
                return ret;
        if (strcmp(*output, "now")) {
-               unsigned long now = approxidate("now");
+               timestamp_t now = approxidate("now");
                if (approxidate(*output) >= now)
                        git_die_config(key, _("Invalid %s: '%s'"), key, *output);
        }
@@ -2640,6 +2656,9 @@ int git_config_rename_section_in_file(const char *config_filename,
        }
 
        if (!(config_file = fopen(config_filename, "rb"))) {
+               ret = warn_on_fopen_errors(config_filename);
+               if (ret)
+                       goto out;
                /* no config file means nothing to rename, no error */
                goto commit_and_out;
        }