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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 16, 2012 at 03:04 UTC
0a5f57592728e7667d9e60e309f6270db9fdb67b
1 file changed
+7
-13
config.c
+7
-13
@@ -1233,6 +1233,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
1233
int fd = -1, in_fd;
1234
int ret;
1235
struct lock_file *lock = NULL;
1236
+ char *filename_buf = NULL;
1237
1238
/* parse-key returns negative; flip the sign to feed exit(3) */
1239
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,
1242
1243
store.multi_replace = multi_replace;
1244
1245
+ if (!config_filename)
1246
+ config_filename = filename_buf = git_pathdup("config");
1247
1248
/*
1249
* 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,
1413
out_free:
1414
if (lock)
1415
rollback_lock_file(lock);
1416
+ free(filename_buf);
1417
return ret;
1418
1419
write_err_out:
@@ -1421,19 +1425,9 @@ write_err_out:
1425
int git_config_set_multivar(const char *key, const char *value,
1426
const char *value_regex, int multi_replace)
1427
{
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);
1431
}
1432
1433
static int section_name_match (const char *buf, const char *name)