Skip to content

Commit 0a5f575

Browse files
peffgitster
authored andcommitted
config: teach git_config_set_multivar_in_file a default path
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 839de25 commit 0a5f575

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

config.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
12331233
int fd = -1, in_fd;
12341234
int ret;
12351235
struct lock_file *lock = NULL;
1236+
char *filename_buf = NULL;
12361237

12371238
/* parse-key returns negative; flip the sign to feed exit(3) */
12381239
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,
12411242

12421243
store.multi_replace = multi_replace;
12431244

1245+
if (!config_filename)
1246+
config_filename = filename_buf = git_pathdup("config");
12441247

12451248
/*
12461249
* 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,
14101413
out_free:
14111414
if (lock)
14121415
rollback_lock_file(lock);
1416+
free(filename_buf);
14131417
return ret;
14141418

14151419
write_err_out:
@@ -1421,19 +1425,9 @@ int git_config_set_multivar_in_file(const char *config_filename,
14211425
int git_config_set_multivar(const char *key, const char *value,
14221426
const char *value_regex, int multi_replace)
14231427
{
1424-
const char *config_filename;
1425-
char *buf = NULL;
1426-
int ret;
1427-
1428-
if (config_exclusive_filename)
1429-
config_filename = config_exclusive_filename;
1430-
else
1431-
config_filename = buf = git_pathdup("config");
1432-
1433-
ret = git_config_set_multivar_in_file(config_filename, key, value,
1434-
value_regex, multi_replace);
1435-
free(buf);
1436-
return ret;
1428+
return git_config_set_multivar_in_file(config_exclusive_filename,
1429+
key, value, value_regex,
1430+
multi_replace);
14371431
}
14381432

14391433
static int section_name_match (const char *buf, const char *name)

0 commit comments

Comments
 (0)