Skip to content

Commit 62c1ed3

Browse files
pks-tgitster
authored andcommitted
config: drop git_config_set_in_file_gently() wrapper
In 036876a (config: hide functions using `the_repository` by default, 2024-08-13) we have moved around a bunch of functions in the config subsystem that depend on `the_repository`. Those function have been converted into mere wrappers around their equivalent function that takes in a repository as parameter, and the intent was that we'll eventually remove those wrappers to make the dependency on the global repository variable explicit at the callsite. Follow through with that intent and remove `git_config_set_in_file_gently()`. All callsites are adjusted so that they use `repo_config_set_in_file_gently(the_repository, ...)` instead. While some callsites might already have a repository available, this mechanical conversion is the exact same as the current situation and thus cannot cause any regression. Those sites should eventually be cleaned up in a later patch series. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e957ed2 commit 62c1ed3

File tree

8 files changed

+28
-38
lines changed

8 files changed

+28
-38
lines changed

builtin/config.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix,
970970
argv[0], value, value_pattern,
971971
comment, flags);
972972
} else {
973-
ret = git_config_set_in_file_gently(location_opts.source.file,
974-
argv[0], comment, value);
973+
ret = repo_config_set_in_file_gently(the_repository, location_opts.source.file,
974+
argv[0], comment, value);
975975
if (ret == CONFIG_NOTHING_SET)
976976
error(_("cannot overwrite multiple values with a single value\n"
977977
" Use a regexp, --add or --replace-all to change %s."), argv[0]);
@@ -1014,8 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix,
10141014
argv[0], NULL, value_pattern,
10151015
NULL, flags);
10161016
else
1017-
ret = git_config_set_in_file_gently(location_opts.source.file, argv[0],
1018-
NULL, NULL);
1017+
ret = repo_config_set_in_file_gently(the_repository, location_opts.source.file, argv[0],
1018+
NULL, NULL);
10191019

10201020
location_options_release(&location_opts);
10211021
return ret;
@@ -1296,7 +1296,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
12961296
check_write(&location_opts.source);
12971297
check_argc(argc, 2, 2);
12981298
value = normalize_value(argv[0], argv[1], display_opts.type, &default_kvi);
1299-
ret = git_config_set_in_file_gently(location_opts.source.file, argv[0], comment, value);
1299+
ret = repo_config_set_in_file_gently(the_repository, location_opts.source.file, argv[0], comment, value);
13001300
if (ret == CONFIG_NOTHING_SET)
13011301
error(_("cannot overwrite multiple values with a single value\n"
13021302
" Use a regexp, --add or --replace-all to change %s."), argv[0]);
@@ -1354,8 +1354,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13541354
argv[0], NULL, argv[1],
13551355
NULL, flags);
13561356
else
1357-
ret = git_config_set_in_file_gently(location_opts.source.file,
1358-
argv[0], NULL, NULL);
1357+
ret = repo_config_set_in_file_gently(the_repository, location_opts.source.file,
1358+
argv[0], NULL, NULL);
13591359
}
13601360
else if (actions == ACTION_UNSET_ALL) {
13611361
check_write(&location_opts.source);

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ static void sync_submodule(const char *path, const char *prefix,
12801280
submodule_to_gitdir(the_repository, &sb, path);
12811281
strbuf_addstr(&sb, "/config");
12821282

1283-
if (git_config_set_in_file_gently(sb.buf, remote_key, NULL, sub_origin_url))
1283+
if (repo_config_set_in_file_gently(the_repository, sb.buf, remote_key, NULL, sub_origin_url))
12841284
die(_("failed to update remote for submodule '%s'"),
12851285
path);
12861286

builtin/worktree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ static void copy_filtered_worktree_config(const char *worktree_git_dir)
384384
error(_("failed to unset '%s' in '%s'"),
385385
"core.bare", to_file);
386386
if (!git_configset_get(&cs, "core.worktree") &&
387-
git_config_set_in_file_gently(to_file,
388-
"core.worktree", NULL, NULL))
387+
repo_config_set_in_file_gently(the_repository, to_file,
388+
"core.worktree", NULL, NULL))
389389
error(_("failed to unset '%s' in '%s'"),
390390
"core.worktree", to_file);
391391

config.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,6 @@ static inline int git_config_get_pathname(const char *key, char **dest)
734734
return repo_config_get_pathname(the_repository, key, dest);
735735
}
736736

737-
static inline int git_config_set_in_file_gently(
738-
const char *config_filename,
739-
const char *key,
740-
const char *comment,
741-
const char *value)
742-
{
743-
return repo_config_set_in_file_gently(the_repository, config_filename,
744-
key, comment, value);
745-
}
746-
747737
static inline int git_config_set_multivar_in_file_gently(
748738
const char *config_filename,
749739
const char *key, const char *value,

sequencer.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,57 +3650,57 @@ static int save_opts(struct replay_opts *opts)
36503650
int res = 0;
36513651

36523652
if (opts->no_commit)
3653-
res |= git_config_set_in_file_gently(opts_file,
3653+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36543654
"options.no-commit", NULL, "true");
36553655
if (opts->edit >= 0)
3656-
res |= git_config_set_in_file_gently(opts_file, "options.edit", NULL,
3656+
res |= repo_config_set_in_file_gently(the_repository, opts_file, "options.edit", NULL,
36573657
opts->edit ? "true" : "false");
36583658
if (opts->allow_empty)
3659-
res |= git_config_set_in_file_gently(opts_file,
3659+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36603660
"options.allow-empty", NULL, "true");
36613661
if (opts->allow_empty_message)
3662-
res |= git_config_set_in_file_gently(opts_file,
3662+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36633663
"options.allow-empty-message", NULL, "true");
36643664
if (opts->drop_redundant_commits)
3665-
res |= git_config_set_in_file_gently(opts_file,
3665+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36663666
"options.drop-redundant-commits", NULL, "true");
36673667
if (opts->keep_redundant_commits)
3668-
res |= git_config_set_in_file_gently(opts_file,
3668+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36693669
"options.keep-redundant-commits", NULL, "true");
36703670
if (opts->signoff)
3671-
res |= git_config_set_in_file_gently(opts_file,
3671+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36723672
"options.signoff", NULL, "true");
36733673
if (opts->record_origin)
3674-
res |= git_config_set_in_file_gently(opts_file,
3674+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36753675
"options.record-origin", NULL, "true");
36763676
if (opts->allow_ff)
3677-
res |= git_config_set_in_file_gently(opts_file,
3677+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36783678
"options.allow-ff", NULL, "true");
36793679
if (opts->mainline) {
36803680
struct strbuf buf = STRBUF_INIT;
36813681
strbuf_addf(&buf, "%d", opts->mainline);
3682-
res |= git_config_set_in_file_gently(opts_file,
3682+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36833683
"options.mainline", NULL, buf.buf);
36843684
strbuf_release(&buf);
36853685
}
36863686
if (opts->strategy)
3687-
res |= git_config_set_in_file_gently(opts_file,
3687+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36883688
"options.strategy", NULL, opts->strategy);
36893689
if (opts->gpg_sign)
3690-
res |= git_config_set_in_file_gently(opts_file,
3690+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36913691
"options.gpg-sign", NULL, opts->gpg_sign);
36923692
for (size_t i = 0; i < opts->xopts.nr; i++)
36933693
res |= git_config_set_multivar_in_file_gently(opts_file,
36943694
"options.strategy-option",
36953695
opts->xopts.v[i], "^$", NULL, 0);
36963696
if (opts->allow_rerere_auto)
3697-
res |= git_config_set_in_file_gently(opts_file,
3697+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
36983698
"options.allow-rerere-auto", NULL,
36993699
opts->allow_rerere_auto == RERERE_AUTOUPDATE ?
37003700
"true" : "false");
37013701

37023702
if (opts->explicit_cleanup)
3703-
res |= git_config_set_in_file_gently(opts_file,
3703+
res |= repo_config_set_in_file_gently(the_repository, opts_file,
37043704
"options.default-msg-cleanup", NULL,
37053705
describe_cleanup_mode(opts->default_msg_cleanup));
37063706
return res;

submodule-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ int config_set_in_gitmodules_file_gently(const char *key, const char *value)
983983
{
984984
int ret;
985985

986-
ret = git_config_set_in_file_gently(GITMODULES_FILE, key, NULL, value);
986+
ret = repo_config_set_in_file_gently(the_repository, GITMODULES_FILE, key, NULL, value);
987987
if (ret < 0)
988988
/* Maybe the user already did that, don't error out here */
989989
warning(_("Could not update .gitmodules entry %s"), key);

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ void submodule_unset_core_worktree(const struct submodule *sub)
20582058
submodule_name_to_gitdir(&config_path, the_repository, sub->name);
20592059
strbuf_addstr(&config_path, "/config");
20602060

2061-
if (git_config_set_in_file_gently(config_path.buf, "core.worktree", NULL, NULL))
2061+
if (repo_config_set_in_file_gently(the_repository, config_path.buf, "core.worktree", NULL, NULL))
20622062
warning(_("Could not unset core.worktree setting in submodule '%s'"),
20632063
sub->path);
20642064

worktree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,9 @@ int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath,
991991
static int move_config_setting(const char *key, const char *value,
992992
const char *from_file, const char *to_file)
993993
{
994-
if (git_config_set_in_file_gently(to_file, key, NULL, value))
994+
if (repo_config_set_in_file_gently(the_repository, to_file, key, NULL, value))
995995
return error(_("unable to set %s in '%s'"), key, to_file);
996-
if (git_config_set_in_file_gently(from_file, key, NULL, NULL))
996+
if (repo_config_set_in_file_gently(the_repository, from_file, key, NULL, NULL))
997997
return error(_("unable to unset %s in '%s'"), key, from_file);
998998
return 0;
999999
}

0 commit comments

Comments
 (0)