summaryrefslogtreecommitdiffstats
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorGlen Choo <chooglen@google.com>2022-07-01 04:11:54 +0200
committerJunio C Hamano <gitster@pobox.com>2022-07-01 07:41:45 +0200
commit58cec298f1c2e55875c56afa1bcf3bbb41bc9586 (patch)
tree02f16f4ad248dfce43b78b84a9026c505437f3f7 /builtin/submodule--helper.c
parentsubmodule--helper: don't recreate recursive prefix (diff)
downloadgit-58cec298f1c2e55875c56afa1bcf3bbb41bc9586.tar.xz
git-58cec298f1c2e55875c56afa1bcf3bbb41bc9586.zip
submodule--helper: use correct display path helper
Replace a chunk of code in update_submodule() with an equivalent do_get_submodule_displaypath() invocation. This is already tested by t/t7406-submodule-update.sh:'submodule update --init --recursive from subdirectory', so no tests are added. The two are equivalent because: - Exactly one of recursive_prefix|prefix is non-NULL at a time; prefix is set at the superproject level, and recursive_prefix is set when recursing into submodules. There is also a BUG() statement in get_submodule_displaypath() that asserts that both cannot be non-NULL. - In get_submodule_displaypath(), get_super_prefix() always returns NULL because "--super-prefix" is never passed. Thus calling it is equivalent to calling do_get_submodule_displaypath() with super_prefix = NULL. Therefore: - When recursive_prefix is non-NULL, prefix is NULL, and thus get_submodule_displaypath() just returns prefixed_path. This is identical to calling do_get_submodule_displaypath() with super_prefix = recursive_prefix because the return value is still the concatenation of recursive_prefix + update_data->sm_path. - When prefix is non-NULL, prefixed_path = update_data->sm_path. Thus calling get_submodule_displaypath() with prefixed_path is equivalent to calling do_get_submodule_displaypath() with update_data->sm_path Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r--builtin/submodule--helper.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 455e6766c3..811a08ead0 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2464,19 +2464,11 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
static int update_submodule(struct update_data *update_data)
{
- char *prefixed_path;
-
ensure_core_worktree(update_data->sm_path);
- if (update_data->recursive_prefix)
- prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix,
- update_data->sm_path);
- else
- prefixed_path = xstrdup(update_data->sm_path);
-
- update_data->displaypath = get_submodule_displaypath(prefixed_path,
- update_data->prefix);
- free(prefixed_path);
+ update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path,
+ update_data->prefix,
+ update_data->recursive_prefix);
determine_submodule_update_strategy(the_repository, update_data->just_cloned,
update_data->sm_path, update_data->update_default,