]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: teach git_config_set_multivar_in_file a default path
authorJeff King <peff@peff.net>
Thu, 16 Feb 2012 08:04:05 +0000 (03:04 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Feb 2012 15:52:41 +0000 (07:52 -0800)
The git_config_set_multivar_in_file function takes a
filename argument to specify the file into which the values
should be written. Currently, this value must be non-NULL.
Callers which want to write to the default location must use
the regular, non-"in_file" version, which will either write
to config_exclusive_filename, or to the repo config if the
exclusive filename is NULL.

Let's migrate the "default to using repo config" logic into
the "in_file" form. That will let callers get the same
default-if-NULL behavior as one gets with
config_exclusive_filename, but without having to use the
global variable.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c

index 40f9c6d10317ed47f7786e5c328df3ab6f167e7c..351ae0b62e23e12eb08046bbe02a93195b62240c 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1233,6 +1233,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
        int fd = -1, in_fd;
        int ret;
        struct lock_file *lock = NULL;
+       char *filename_buf = NULL;
 
        /* parse-key returns negative; flip the sign to feed exit(3) */
        ret = 0 - git_config_parse_key(key, &store.key, &store.baselen);
@@ -1241,6 +1242,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
 
        store.multi_replace = multi_replace;
 
+       if (!config_filename)
+               config_filename = filename_buf = git_pathdup("config");
 
        /*
         * The lock serves a purpose in addition to locking: the new
@@ -1410,6 +1413,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
 out_free:
        if (lock)
                rollback_lock_file(lock);
+       free(filename_buf);
        return ret;
 
 write_err_out:
@@ -1421,19 +1425,9 @@ write_err_out:
 int git_config_set_multivar(const char *key, const char *value,
                        const char *value_regex, int multi_replace)
 {
-       const char *config_filename;
-       char *buf = NULL;
-       int ret;
-
-       if (config_exclusive_filename)
-               config_filename = config_exclusive_filename;
-       else
-               config_filename = buf = git_pathdup("config");
-
-       ret = git_config_set_multivar_in_file(config_filename, key, value,
-                                       value_regex, multi_replace);
-       free(buf);
-       return ret;
+       return git_config_set_multivar_in_file(config_exclusive_filename,
+                                              key, value, value_regex,
+                                              multi_replace);
 }
 
 static int section_name_match (const char *buf, const char *name)