summaryrefslogtreecommitdiff
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-08-31 23:18:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-09-02 16:16:24 (GMT)
commitb9dd63ffe2842fe676f54d4d5f8f06bc04c6dd8b (patch)
treeb87de385e802e0d30b5607e50f8f785b49c6c945 /builtin/submodule--helper.c
parent08c2e778d6b16296aebfccd609ad09db9d40764a (diff)
downloadgit-b9dd63ffe2842fe676f54d4d5f8f06bc04c6dd8b.zip
git-b9dd63ffe2842fe676f54d4d5f8f06bc04c6dd8b.tar.gz
git-b9dd63ffe2842fe676f54d4d5f8f06bc04c6dd8b.tar.bz2
submodule API: don't handle SM_..{UNSPECIFIED,COMMAND} in to_string()
Change the submodule_strategy_to_string() function added in 3604242f080 (submodule: port init from shell to C, 2016-04-15) to really return a "const char *". In the "SM_UPDATE_COMMAND" case it would return a strbuf_detach(). Furthermore, this function would return NULL on SM_UPDATE_UNSPECIFIED, so it wasn't safe to xstrdup() its return value in the general case, or to use it in a sprintf() format as the code removed in the preceding commit did. But its callers would never call it with either SM_UPDATE_UNSPECIFIED or SM_UPDATE_COMMAND. Let's have its behavior reflect how its only user expects it to behave, and BUG() out on the rest. By doing this we can also stop needlessly xstrdup()-ing and free()-ing the memory for the config we're setting. We can instead always use constant strings. We can also use the *_tmp() variant of git_config_get_string(). Let's also rename this submodule_strategy_to_string() function to submodule_update_type_to_string(). Now that it's only tasked with returning a string version of the "enum submodule_update_type type". Before it would look at the "command" field in "struct submodule_update_strategy". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 44c6dfd..a050521 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -418,7 +418,8 @@ static void init_submodule(const char *path, const char *prefix,
{
const struct submodule *sub;
struct strbuf sb = STRBUF_INIT;
- char *upd = NULL, *url = NULL, *displaypath;
+ const char *upd;
+ char *url = NULL, *displaypath;
displaypath = get_submodule_displaypath(path, prefix);
@@ -474,14 +475,14 @@ static void init_submodule(const char *path, const char *prefix,
/* Copy "update" setting when it is not set yet */
strbuf_addf(&sb, "submodule.%s.update", sub->name);
- if (git_config_get_string(sb.buf, &upd) &&
+ if (git_config_get_string_tmp(sb.buf, &upd) &&
sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
if (sub->update_strategy.type == SM_UPDATE_COMMAND) {
fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"),
sub->name);
- upd = xstrdup("none");
+ upd = "none";
} else {
- upd = xstrdup(submodule_strategy_to_string(&sub->update_strategy));
+ upd = submodule_update_type_to_string(sub->update_strategy.type);
}
if (git_config_set_gently(sb.buf, upd))
@@ -490,7 +491,6 @@ static void init_submodule(const char *path, const char *prefix,
strbuf_release(&sb);
free(displaypath);
free(url);
- free(upd);
}
static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)