Re: [RFC PATCH 02/10] submodule: factor out a config_gitmodules_set function
On Mon, 14 May 2018 18:20:21 -0700 Stefan Beller wrote: > On Mon, May 14, 2018 at 3:58 AM, Antonio Ospite wrote: > > Introduce a new config_gitmodules_set 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". > > > > Signed-off-by: Antonio Ospite > > --- > > > > Not sure about the name, and maybe it can go in config.c for symmetry with > > config_from_gitmodules? > > What is the function about (in the end state and now) ? > is it more of a > * configure_submodules_config() > which would convey it is a generic function to configure submodules > (i.e. it may not even write to *the* .gitmodules file but somewhere else, > such as a helper ref) > This doesn't sound like it as we make use of the function in > update_path_in_gitmodules() that is used from git-mv, which would want > to ensure that the specific .gitmodules file is changed. > * gitmodules_file_set() > that focuses on the specific file that we want to modify? > * ... > > Let's continue reading the series to see the end state for > a good name. > OK, that helped to clarify one point: eventually there will be some asymmetry between reading the submodule config and writing it. 1. reading will be either form .gitmodules or HEAD:.gitmodules; 2. writing will be only to .gitmodules. I'll try to consider that when naming the functions. If a more generic mechanism to write the submodules configuration is added in the future (e.g. the special ref you were mentioning) the functions can always be renamed accordingly. Thanks, Antonio -- Antonio Ospite https://ao2.it https://twitter.com/ao2it A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
Re: [RFC PATCH 02/10] submodule: factor out a config_gitmodules_set function
On Mon, May 14, 2018 at 3:58 AM, Antonio Ospitewrote: > Introduce a new config_gitmodules_set 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". > > Signed-off-by: Antonio Ospite > --- > > Not sure about the name, and maybe it can go in config.c for symmetry with > config_from_gitmodules? What is the function about (in the end state and now) ? is it more of a * configure_submodules_config() which would convey it is a generic function to configure submodules (i.e. it may not even write to *the* .gitmodules file but somewhere else, such as a helper ref) This doesn't sound like it as we make use of the function in update_path_in_gitmodules() that is used from git-mv, which would want to ensure that the specific .gitmodules file is changed. * gitmodules_file_set() that focuses on the specific file that we want to modify? * ... Let's continue reading the series to see the end state for a good name. Stefan
[RFC PATCH 02/10] submodule: factor out a config_gitmodules_set function
Introduce a new config_gitmodules_set 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". Signed-off-by: Antonio Ospite--- Not sure about the name, and maybe it can go in config.c for symmetry with config_from_gitmodules? submodule.c | 22 +++--- submodule.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/submodule.c b/submodule.c index 74d35b257..7cfae89b6 100644 --- a/submodule.c +++ b/submodule.c @@ -80,6 +80,18 @@ static int for_each_remote_ref_submodule(const char *submodule, fn, cb_data); } +int config_gitmodules_set(const char *key, const char *value) +{ + int ret; + + ret = git_config_set_in_file_gently(GITMODULES_FILE, key, value); + if (ret < 0) + /* Maybe the user already did that, don't error out here */ + warning(_("Could not update .gitmodules entry %s"), key); + + return ret; +} + /* * Try to update the "path" entry in the "submodule." section of the * .gitmodules file. Return 0 only if a .gitmodules file was found, a section @@ -89,6 +101,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath) { struct strbuf entry = STRBUF_INIT; const struct submodule *submodule; + int ret; if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */ return -1; @@ -104,14 +117,9 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath) strbuf_addstr(, "submodule."); strbuf_addstr(, submodule->name); strbuf_addstr(, ".path"); - if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) { - /* Maybe the user already did that, don't error out here */ - warning(_("Could not update .gitmodules entry %s"), entry.buf); - strbuf_release(); - return -1; - } + ret = config_gitmodules_set(entry.buf, newpath); strbuf_release(); - return 0; + return ret; } /* diff --git a/submodule.h b/submodule.h index e5526f6aa..8a252e514 100644 --- a/submodule.h +++ b/submodule.h @@ -35,6 +35,7 @@ struct submodule_update_strategy { extern int is_gitmodules_unmerged(const struct index_state *istate); extern int is_staging_gitmodules_ok(struct index_state *istate); +extern int config_gitmodules_set(const char *key, const char *value); extern int update_path_in_gitmodules(const char *oldpath, const char *newpath); extern int remove_path_from_gitmodules(const char *path); extern void stage_updated_gitmodules(struct index_state *istate); -- 2.17.0