Skip to content

Commit 45f5ef3

Browse files
ao2gitster
authored andcommitted
submodule: factor out a config_set_in_gitmodules_file_gently function
Introduce a new config_set_in_gitmodules_file_gently() function to write config values to the .gitmodules file. This is in preparation for a future change which will use the function to write to the .gitmodules file in a more controlled way instead of using "git config -f .gitmodules". The purpose of the change is mainly to centralize the code that writes to the .gitmodules file to avoid some duplication. The naming follows git_config_set_in_file_gently() but the git_ prefix is removed to communicate that this is not a generic git-config API. Signed-off-by: Antonio Ospite <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcbc780 commit 45f5ef3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

submodule-config.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,18 @@ int print_config_from_gitmodules(struct repository *repo, const char *key)
707707
return 0;
708708
}
709709

710+
int config_set_in_gitmodules_file_gently(const char *key, const char *value)
711+
{
712+
int ret;
713+
714+
ret = git_config_set_in_file_gently(GITMODULES_FILE, key, value);
715+
if (ret < 0)
716+
/* Maybe the user already did that, don't error out here */
717+
warning(_("Could not update .gitmodules entry %s"), key);
718+
719+
return ret;
720+
}
721+
710722
struct fetch_config {
711723
int *max_children;
712724
int *recurse_submodules;

submodule-config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const struct submodule *submodule_from_path(struct repository *r,
4949
const char *path);
5050
void submodule_free(struct repository *r);
5151
int print_config_from_gitmodules(struct repository *repo, const char *key);
52+
int config_set_in_gitmodules_file_gently(const char *key, const char *value);
5253

5354
/*
5455
* Returns 0 if the name is syntactically acceptable as a submodule "name"

submodule.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
8989
{
9090
struct strbuf entry = STRBUF_INIT;
9191
const struct submodule *submodule;
92+
int ret;
9293

9394
if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
9495
return -1;
@@ -104,14 +105,9 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
104105
strbuf_addstr(&entry, "submodule.");
105106
strbuf_addstr(&entry, submodule->name);
106107
strbuf_addstr(&entry, ".path");
107-
if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) {
108-
/* Maybe the user already did that, don't error out here */
109-
warning(_("Could not update .gitmodules entry %s"), entry.buf);
110-
strbuf_release(&entry);
111-
return -1;
112-
}
108+
ret = config_set_in_gitmodules_file_gently(entry.buf, newpath);
113109
strbuf_release(&entry);
114-
return 0;
110+
return ret;
115111
}
116112

117113
/*

0 commit comments

Comments
 (0)