Skip to content

Commit 76fc990

Browse files
pks-tgitster
authored andcommitted
config: pass repo to functions that rename or copy sections
Refactor functions that rename or copy config sections to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the functions accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0c2c37d commit 76fc990

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

builtin/branch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void delete_branch_config(const char *branchname)
210210
{
211211
struct strbuf buf = STRBUF_INIT;
212212
strbuf_addf(&buf, "branch.%s", branchname);
213-
if (git_config_rename_section(buf.buf, NULL) < 0)
213+
if (repo_config_rename_section(the_repository, buf.buf, NULL) < 0)
214214
warning(_("update of config-file failed"));
215215
strbuf_release(&buf);
216216
}
@@ -659,9 +659,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
659659

660660
strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
661661
strbuf_addf(&newsection, "branch.%s", interpreted_newname);
662-
if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
662+
if (!copy && repo_config_rename_section(the_repository, oldsection.buf, newsection.buf) < 0)
663663
die(_("branch is renamed, but update of config-file failed"));
664-
if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
664+
if (copy && strcmp(interpreted_oldname, interpreted_newname) &&
665+
repo_config_copy_section(the_repository, oldsection.buf, newsection.buf) < 0)
665666
die(_("branch is copied, but update of config-file failed"));
666667
strbuf_release(&oldref);
667668
strbuf_release(&newref);

builtin/config.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr
10261026
location_options_init(&location_opts, prefix);
10271027
check_write(&location_opts.source);
10281028

1029-
ret = git_config_rename_section_in_file(location_opts.source.file,
1030-
argv[0], argv[1]);
1029+
ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
1030+
argv[0], argv[1]);
10311031
if (ret < 0)
10321032
goto out;
10331033
else if (!ret)
@@ -1055,8 +1055,8 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr
10551055
location_options_init(&location_opts, prefix);
10561056
check_write(&location_opts.source);
10571057

1058-
ret = git_config_rename_section_in_file(location_opts.source.file,
1059-
argv[0], NULL);
1058+
ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
1059+
argv[0], NULL);
10601060
if (ret < 0)
10611061
goto out;
10621062
else if (!ret)
@@ -1353,8 +1353,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13531353
else if (actions == ACTION_RENAME_SECTION) {
13541354
check_write(&location_opts.source);
13551355
check_argc(argc, 2, 2);
1356-
ret = git_config_rename_section_in_file(location_opts.source.file,
1357-
argv[0], argv[1]);
1356+
ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
1357+
argv[0], argv[1]);
13581358
if (ret < 0)
13591359
goto out;
13601360
else if (!ret)
@@ -1365,8 +1365,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13651365
else if (actions == ACTION_REMOVE_SECTION) {
13661366
check_write(&location_opts.source);
13671367
check_argc(argc, 1, 1);
1368-
ret = git_config_rename_section_in_file(location_opts.source.file,
1369-
argv[0], NULL);
1368+
ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
1369+
argv[0], NULL);
13701370
if (ret < 0)
13711371
goto out;
13721372
else if (!ret)

builtin/remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ static int mv(int argc, const char **argv, const char *prefix)
736736

737737
strbuf_addf(&buf, "remote.%s", rename.old_name);
738738
strbuf_addf(&buf2, "remote.%s", rename.new_name);
739-
if (git_config_rename_section(buf.buf, buf2.buf) < 1)
739+
if (repo_config_rename_section(the_repository, buf.buf, buf2.buf) < 1)
740740
return error(_("Could not rename config section '%s' to '%s'"),
741741
buf.buf, buf2.buf);
742742

@@ -944,7 +944,7 @@ static int rm(int argc, const char **argv, const char *prefix)
944944

945945
if (!result) {
946946
strbuf_addf(&buf, "remote.%s", remote->name);
947-
if (git_config_rename_section(buf.buf, NULL) < 1)
947+
if (repo_config_rename_section(the_repository, buf.buf, NULL) < 1)
948948
return error(_("Could not remove config section '%s'"), buf.buf);
949949

950950
handle_push_default(remote->name, NULL);

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ static void deinit_submodule(const char *path, const char *prefix,
14551455
* remove the whole section so we have a clean state when
14561456
* the user later decides to init this submodule again
14571457
*/
1458-
git_config_rename_section_in_file(NULL, sub_key, NULL);
1458+
repo_config_rename_section_in_file(the_repository, NULL, sub_key, NULL);
14591459
if (!(flags & OPT_QUIET))
14601460
printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"),
14611461
sub->name, sub->url, displaypath);

config.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,9 +3697,11 @@ static int section_name_is_ok(const char *name)
36973697
#define GIT_CONFIG_MAX_LINE_LEN (512 * 1024)
36983698

36993699
/* if new_name == NULL, the section is removed instead */
3700-
static int git_config_copy_or_rename_section_in_file(const char *config_filename,
3701-
const char *old_name,
3702-
const char *new_name, int copy)
3700+
static int repo_config_copy_or_rename_section_in_file(
3701+
struct repository *r,
3702+
const char *config_filename,
3703+
const char *old_name,
3704+
const char *new_name, int copy)
37033705
{
37043706
int ret = 0, remove = 0;
37053707
char *filename_buf = NULL;
@@ -3720,7 +3722,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
37203722
}
37213723

37223724
if (!config_filename)
3723-
config_filename = filename_buf = git_pathdup("config");
3725+
config_filename = filename_buf = repo_git_path(r, "config");
37243726

37253727
out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
37263728
if (out_fd < 0) {
@@ -3863,28 +3865,28 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
38633865
return ret;
38643866
}
38653867

3866-
int git_config_rename_section_in_file(const char *config_filename,
3867-
const char *old_name, const char *new_name)
3868+
int repo_config_rename_section_in_file(struct repository *r, const char *config_filename,
3869+
const char *old_name, const char *new_name)
38683870
{
3869-
return git_config_copy_or_rename_section_in_file(config_filename,
3871+
return repo_config_copy_or_rename_section_in_file(r, config_filename,
38703872
old_name, new_name, 0);
38713873
}
38723874

3873-
int git_config_rename_section(const char *old_name, const char *new_name)
3875+
int repo_config_rename_section(struct repository *r, const char *old_name, const char *new_name)
38743876
{
3875-
return git_config_rename_section_in_file(NULL, old_name, new_name);
3877+
return repo_config_rename_section_in_file(r, NULL, old_name, new_name);
38763878
}
38773879

3878-
int git_config_copy_section_in_file(const char *config_filename,
3879-
const char *old_name, const char *new_name)
3880+
int repo_config_copy_section_in_file(struct repository *r, const char *config_filename,
3881+
const char *old_name, const char *new_name)
38803882
{
3881-
return git_config_copy_or_rename_section_in_file(config_filename,
3883+
return repo_config_copy_or_rename_section_in_file(r, config_filename,
38823884
old_name, new_name, 1);
38833885
}
38843886

3885-
int git_config_copy_section(const char *old_name, const char *new_name)
3887+
int repo_config_copy_section(struct repository *r, const char *old_name, const char *new_name)
38863888
{
3887-
return git_config_copy_section_in_file(NULL, old_name, new_name);
3889+
return repo_config_copy_section_in_file(r, NULL, old_name, new_name);
38883890
}
38893891

38903892
/*

config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ void repo_config_set_multivar_in_file(struct repository *r,
392392
* If NULL is passed through `new_name` parameter,
393393
* the section will be removed from the config file.
394394
*/
395-
int git_config_rename_section(const char *, const char *);
395+
int repo_config_rename_section(struct repository *, const char *, const char *);
396396

397-
int git_config_rename_section_in_file(const char *, const char *, const char *);
398-
int git_config_copy_section(const char *, const char *);
399-
int git_config_copy_section_in_file(const char *, const char *, const char *);
397+
int repo_config_rename_section_in_file(struct repository *, const char *, const char *, const char *);
398+
int repo_config_copy_section(struct repository *, const char *, const char *);
399+
int repo_config_copy_section_in_file(struct repository *, const char *, const char *, const char *);
400400
int git_config_system(void);
401401
int config_error_nonbool(const char *);
402402
#if defined(__GNUC__)

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int remove_path_from_gitmodules(const char *path)
159159
}
160160
strbuf_addstr(&sect, "submodule.");
161161
strbuf_addstr(&sect, submodule->name);
162-
if (git_config_rename_section_in_file(GITMODULES_FILE, sect.buf, NULL) < 0) {
162+
if (repo_config_rename_section_in_file(the_repository, GITMODULES_FILE, sect.buf, NULL) < 0) {
163163
/* Maybe the user already did that, don't error out here */
164164
warning(_("Could not remove .gitmodules entry for %s"), path);
165165
strbuf_release(&sect);

0 commit comments

Comments
 (0)