Skip to content

Commit 30598ad

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f29c1b commit 30598ad

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

branch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ int install_branch_config(int flag, const char *local, const char *origin, const
7070
}
7171

7272
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)
7474
goto out_err;
7575

7676
strbuf_reset(&key);
7777
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)
7979
goto out_err;
8080

8181
if (rebasing) {
8282
strbuf_reset(&key);
8383
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)
8585
goto out_err;
8686
}
8787
strbuf_release(&key);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static int checkout(void)
732732

733733
static int write_one_config(const char *key, const char *value, void *data)
734734
{
735-
return git_config_set_multivar(key, value ? value : "true", "^$", 0);
735+
return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
736736
}
737737

738738
static void write_config(struct string_list *config)

builtin/config.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
582582
check_write();
583583
check_argc(argc, 2, 2);
584584
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);
586586
if (ret == CONFIG_NOTHING_SET)
587587
error("cannot overwrite multiple values with a single value\n"
588588
" 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)
592592
check_write();
593593
check_argc(argc, 2, 3);
594594
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);
597597
}
598598
else if (actions == ACTION_ADD) {
599599
check_write();
600600
check_argc(argc, 2, 2);
601601
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);
605605
}
606606
else if (actions == ACTION_REPLACE_ALL) {
607607
check_write();
608608
check_argc(argc, 2, 3);
609609
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);
612612
}
613613
else if (actions == ACTION_GET) {
614614
check_argc(argc, 1, 2);
@@ -634,17 +634,17 @@ int cmd_config(int argc, const char **argv, const char *prefix)
634634
check_write();
635635
check_argc(argc, 1, 2);
636636
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);
639639
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);
642642
}
643643
else if (actions == ACTION_UNSET_ALL) {
644644
check_write();
645645
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);
648648
}
649649
else if (actions == ACTION_RENAME_SECTION) {
650650
int ret;

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ static int update(int argc, const char **argv)
13931393

13941394
static int remove_all_fetch_refspecs(const char *remote, const char *key)
13951395
{
1396-
return git_config_set_multivar(key, NULL, NULL, 1);
1396+
return git_config_set_multivar_gently(key, NULL, NULL, 1);
13971397
}
13981398

13991399
static void add_branches(struct remote *remote, const char **branches,

cache.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ extern int update_server_info(int);
14841484
/* git_config_parse_key() returns these negated: */
14851485
#define CONFIG_INVALID_KEY 1
14861486
#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: */
14881488
#define CONFIG_NO_LOCK -1
14891489
#define CONFIG_INVALID_FILE 3
14901490
#define CONFIG_NO_WRITE 4
@@ -1522,15 +1522,15 @@ extern int git_config_bool(const char *, const char *);
15221522
extern int git_config_maybe_bool(const char *, const char *);
15231523
extern int git_config_string(const char **, const char *, const char *);
15241524
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 *);
15261526
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 *);
15281528
extern void git_config_set_or_die(const char *, const char *);
15291529
extern int git_config_parse_key(const char *, char **, int *);
15301530
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);
15321532
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);
15341534
extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
15351535
extern int git_config_rename_section(const char *, const char *);
15361536
extern int git_config_rename_section_in_file(const char *, const char *, const char *);

config.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,10 +1825,10 @@ static ssize_t find_beginning_of_line(const char *contents, size_t size,
18251825
return offset;
18261826
}
18271827

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)
18301830
{
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);
18321832
}
18331833

18341834
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,
18371837
git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
18381838
}
18391839

1840-
int git_config_set(const char *key, const char *value)
1840+
int git_config_set_gently(const char *key, const char *value)
18411841
{
1842-
return git_config_set_multivar(key, value, NULL, 0);
1842+
return git_config_set_multivar_gently(key, value, NULL, 0);
18431843
}
18441844

18451845
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)
19611961
* - the config file is removed and the lock file rename()d to it.
19621962
*
19631963
*/
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)
19671968
{
19681969
int fd = -1, in_fd = -1;
19691970
int ret;
@@ -2194,16 +2195,16 @@ void git_config_set_multivar_in_file_or_die(const char *config_filename,
21942195
const char *key, const char *value,
21952196
const char *value_regex, int multi_replace)
21962197
{
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)
21992200
die(_("Could not set '%s' to '%s'"), key, value);
22002201
}
22012202

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)
22042205
{
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);
22072208
}
22082209

22092210
void git_config_set_multivar_or_die(const char *key, const char *value,

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
6868
strbuf_addstr(&entry, "submodule.");
6969
strbuf_addstr(&entry, submodule->name);
7070
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) {
7272
/* Maybe the user already did that, don't error out here */
7373
warning(_("Could not update .gitmodules entry %s"), entry.buf);
7474
strbuf_release(&entry);

0 commit comments

Comments
 (0)