config: rename git_config_set to git_config_set_gently
The desired default behavior for `git_config_set` is to die whenever an error occurs. Dying is the default for a lot of internal functions when failures occur and is in this case the right thing to do for most callers as otherwise we might run into inconsistent repositories without noticing. As some code may rely on the actual return values for `git_config_set` we still require the ability to invoke these functions without aborting. Rename the existing `git_config_set` functions to `git_config_set_gently` to keep them available for those callers. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 22, 2016 at 12:23 UTC
30598ad06f2adfef1f74d6348677358865cbf373
7 files changed
+40
-39
branch.c
+3
-3
@@ -70,18 +70,18 @@ int install_branch_config(int flag, const char *local, const char *origin, const
70
}
71
72
strbuf_addf(&key, "branch.%s.remote", local);
73
- if (git_config_set(key.buf, origin ? origin : ".") < 0)
73
+ if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
74
goto out_err;
75
76
strbuf_reset(&key);
77
strbuf_addf(&key, "branch.%s.merge", local);
78
- if (git_config_set(key.buf, remote) < 0)
78
+ if (git_config_set_gently(key.buf, remote) < 0)
79
goto out_err;
80
81
if (rebasing) {
82
strbuf_reset(&key);
83
strbuf_addf(&key, "branch.%s.rebase", local);
84
- if (git_config_set(key.buf, "true") < 0)
84
+ if (git_config_set_gently(key.buf, "true") < 0)
85
goto out_err;
86
}
87
strbuf_release(&key);
builtin/clone.c
+1
-1
@@ -732,7 +732,7 @@ static int checkout(void)
732
733
static int write_one_config(const char *key, const char *value, void *data)
734
{
735
- return git_config_set_multivar(key, value ? value : "true", "^$", 0);
735
+ return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
736
}
737
738
static void write_config(struct string_list *config)
builtin/config.c
+14
-14
@@ -582,7 +582,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
582
check_write();
583
check_argc(argc, 2, 2);
584
value = normalize_value(argv[0], argv[1]);
585
- ret = git_config_set_in_file(given_config_source.file, argv[0], value);
585
+ ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
586
if (ret == CONFIG_NOTHING_SET)
587
error("cannot overwrite multiple values with a single value\n"
588
" Use a regexp, --add or --replace-all to change %s.", argv[0]);
@@ -592,23 +592,23 @@ int cmd_config(int argc, const char **argv, const char *prefix)
592
check_write();
593
check_argc(argc, 2, 3);
594
value = normalize_value(argv[0], argv[1]);
595
- return git_config_set_multivar_in_file(given_config_source.file,
596
- argv[0], value, argv[2], 0);
595
+ return git_config_set_multivar_in_file_gently(given_config_source.file,
596
+ argv[0], value, argv[2], 0);
597
}
598
else if (actions == ACTION_ADD) {
599
check_write();
600
check_argc(argc, 2, 2);
601
value = normalize_value(argv[0], argv[1]);
602
- return git_config_set_multivar_in_file(given_config_source.file,
603
- argv[0], value,
604
- CONFIG_REGEX_NONE, 0);
602
+ return git_config_set_multivar_in_file_gently(given_config_source.file,
603
+ argv[0], value,
604
+ CONFIG_REGEX_NONE, 0);
605
}
606
else if (actions == ACTION_REPLACE_ALL) {
607
check_write();
608
check_argc(argc, 2, 3);
609
value = normalize_value(argv[0], argv[1]);
610
- return git_config_set_multivar_in_file(given_config_source.file,
611
- argv[0], value, argv[2], 1);
610
+ return git_config_set_multivar_in_file_gently(given_config_source.file,
611
+ argv[0], value, argv[2], 1);
612
}
613
else if (actions == ACTION_GET) {
614
check_argc(argc, 1, 2);
@@ -634,17 +634,17 @@ int cmd_config(int argc, const char **argv, const char *prefix)
634
check_write();
635
check_argc(argc, 1, 2);
636
if (argc == 2)
637
- return git_config_set_multivar_in_file(given_config_source.file,
638
- argv[0], NULL, argv[1], 0);
637
+ return git_config_set_multivar_in_file_gently(given_config_source.file,
638
+ argv[0], NULL, argv[1], 0);
639
else
640
- return git_config_set_in_file(given_config_source.file,
641
- argv[0], NULL);
640
+ return git_config_set_in_file_gently(given_config_source.file,
641
+ argv[0], NULL);
642
}
643
else if (actions == ACTION_UNSET_ALL) {
644
check_write();
645
check_argc(argc, 1, 2);
646
- return git_config_set_multivar_in_file(given_config_source.file,
647
- argv[0], NULL, argv[1], 1);
646
+ return git_config_set_multivar_in_file_gently(given_config_source.file,
647
+ argv[0], NULL, argv[1], 1);
648
}
649
else if (actions == ACTION_RENAME_SECTION) {
650
int ret;
builtin/remote.c
+1
-1
@@ -1393,7 +1393,7 @@ static int update(int argc, const char **argv)
1393
1394
static int remove_all_fetch_refspecs(const char *remote, const char *key)
1395
{
1396
- return git_config_set_multivar(key, NULL, NULL, 1);
1396
+ return git_config_set_multivar_gently(key, NULL, NULL, 1);
1397
}
1398
1399
static void add_branches(struct remote *remote, const char **branches,
cache.h
+5
-5
@@ -1484,7 +1484,7 @@ extern int update_server_info(int);
1484
/* git_config_parse_key() returns these negated: */
1485
#define CONFIG_INVALID_KEY 1
1486
#define CONFIG_NO_SECTION_OR_NAME 2
1487
-/* git_config_set(), git_config_set_multivar() return the above or these: */
1487
+/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
1488
#define CONFIG_NO_LOCK -1
1489
#define CONFIG_INVALID_FILE 3
1490
#define CONFIG_NO_WRITE 4
@@ -1522,15 +1522,15 @@ extern int git_config_bool(const char *, const char *);
1522
extern int git_config_maybe_bool(const char *, const char *);
1523
extern int git_config_string(const char **, const char *, const char *);
1524
extern int git_config_pathname(const char **, const char *, const char *);
1525
-extern int git_config_set_in_file(const char *, const char *, const char *);
1525
+extern int git_config_set_in_file_gently(const char *, const char *, const char *);
1526
extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
1527
-extern int git_config_set(const char *, const char *);
1527
+extern int git_config_set_gently(const char *, const char *);
1528
extern void git_config_set_or_die(const char *, const char *);
1529
extern int git_config_parse_key(const char *, char **, int *);
1530
extern int git_config_key_is_valid(const char *key);
1531
-extern int git_config_set_multivar(const char *, const char *, const char *, int);
1531
+extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
1532
extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
1533
-extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
1533
+extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
1534
extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
1535
extern int git_config_rename_section(const char *, const char *);
1536
extern int git_config_rename_section_in_file(const char *, const char *, const char *);
config.c
+15
-14
@@ -1825,10 +1825,10 @@ contline:
1825
return offset;
1826
}
1827
1828
-int git_config_set_in_file(const char *config_filename,
1829
- const char *key, const char *value)
1828
+int git_config_set_in_file_gently(const char *config_filename,
1829
+ const char *key, const char *value)
1830
{
1831
- return git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
1831
+ return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0);
1832
}
1833
1834
void git_config_set_in_file_or_die(const char *config_filename,
@@ -1837,9 +1837,9 @@ void git_config_set_in_file_or_die(const char *config_filename,
1837
git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
1838
}
1839
1840
-int git_config_set(const char *key, const char *value)
1840
+int git_config_set_gently(const char *key, const char *value)
1841
{
1842
- return git_config_set_multivar(key, value, NULL, 0);
1842
+ return git_config_set_multivar_gently(key, value, NULL, 0);
1843
}
1844
1845
void git_config_set_or_die(const char *key, const char *value)
@@ -1961,9 +1961,10 @@ int git_config_key_is_valid(const char *key)
1961
* - the config file is removed and the lock file rename()d to it.
1962
*
1963
*/
1964
-int git_config_set_multivar_in_file(const char *config_filename,
1965
- const char *key, const char *value,
1966
- const char *value_regex, int multi_replace)
1964
+int git_config_set_multivar_in_file_gently(const char *config_filename,
1965
+ const char *key, const char *value,
1966
+ const char *value_regex,
1967
+ int multi_replace)
1968
{
1969
int fd = -1, in_fd = -1;
1970
int ret;
@@ -2194,16 +2195,16 @@ void git_config_set_multivar_in_file_or_die(const char *config_filename,
2195
const char *key, const char *value,
2196
const char *value_regex, int multi_replace)
2197
{
2197
- if (git_config_set_multivar_in_file(config_filename, key, value,
2198
- value_regex, multi_replace) < 0)
2198
+ if (git_config_set_multivar_in_file_gently(config_filename, key, value,
2199
+ value_regex, multi_replace) < 0)
2200
die(_("Could not set '%s' to '%s'"), key, value);
2201
}
2202
2202
-int git_config_set_multivar(const char *key, const char *value,
2203
- const char *value_regex, int multi_replace)
2203
+int git_config_set_multivar_gently(const char *key, const char *value,
2204
+ const char *value_regex, int multi_replace)
2205
{
2205
- return git_config_set_multivar_in_file(NULL, key, value, value_regex,
2206
- multi_replace);
2206
+ return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex,
2207
+ multi_replace);
2208
}
2209
2210
void git_config_set_multivar_or_die(const char *key, const char *value,
submodule.c
+1
-1
@@ -68,7 +68,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
68
strbuf_addstr(&entry, "submodule.");
69
strbuf_addstr(&entry, submodule->name);
70
strbuf_addstr(&entry, ".path");
71
- if (git_config_set_in_file(".gitmodules", entry.buf, newpath) < 0) {
71
+ if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) {
72
/* Maybe the user already did that, don't error out here */
73
warning(_("Could not update .gitmodules entry %s"), entry.buf);
74
strbuf_release(&entry);