Skip to content

Commit 58cec29

Browse files
chooglengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb49e1e commit 58cec29

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

builtin/submodule--helper.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,19 +2464,11 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24642464

24652465
static int update_submodule(struct update_data *update_data)
24662466
{
2467-
char *prefixed_path;
2468-
24692467
ensure_core_worktree(update_data->sm_path);
24702468

2471-
if (update_data->recursive_prefix)
2472-
prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix,
2473-
update_data->sm_path);
2474-
else
2475-
prefixed_path = xstrdup(update_data->sm_path);
2476-
2477-
update_data->displaypath = get_submodule_displaypath(prefixed_path,
2478-
update_data->prefix);
2479-
free(prefixed_path);
2469+
update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path,
2470+
update_data->prefix,
2471+
update_data->recursive_prefix);
24802472

24812473
determine_submodule_update_strategy(the_repository, update_data->just_cloned,
24822474
update_data->sm_path, update_data->update_default,

0 commit comments

Comments
 (0)