submodule: factor out a config_set_in_gitmodules_file_gently function
authorAntonio Ospite <ao2@ao2.it>
Fri, 5 Oct 2018 13:05:53 +0000 (15:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Oct 2018 03:40:20 +0000 (12:40 +0900)
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 <ao2@ao2.it>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule-config.c
submodule-config.h
submodule.c
index 5aaf7ac00ed34deed969fdee0c12dbc2e2749988..9faf141e47a921af7628f4ad58ee6edf051e5957 100644 (file)
@@ -707,6 +707,18 @@ int print_config_from_gitmodules(struct repository *repo, const char *key)
        return 0;
 }
 
+int config_set_in_gitmodules_file_gently(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;
+}
+
 struct fetch_config {
        int *max_children;
        int *recurse_submodules;
index 031747ccf8a219748b713dcb1be2e246db50e6f6..4dc9b0771c3c2c745d737ad228423e06d55e84c0 100644 (file)
@@ -49,6 +49,7 @@ const struct submodule *submodule_from_path(struct repository *r,
                                            const char *path);
 void submodule_free(struct repository *r);
 int print_config_from_gitmodules(struct repository *repo, const char *key);
+int config_set_in_gitmodules_file_gently(const char *key, const char *value);
 
 /*
  * Returns 0 if the name is syntactically acceptable as a submodule "name"
index a2b266fbfae2cd89b00a11008fbcd28bf09777e2..2e97032f864a20174657f477045d9855c9afe44d 100644 (file)
@@ -89,6 +89,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 +105,9 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
        strbuf_addstr(&entry, "submodule.");
        strbuf_addstr(&entry, submodule->name);
        strbuf_addstr(&entry, ".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(&entry);
-               return -1;
-       }
+       ret = config_set_in_gitmodules_file_gently(entry.buf, newpath);
        strbuf_release(&entry);
-       return 0;
+       return ret;
 }
 
 /*