Skip to content

Commit cb49e1e

Browse files
chooglengitster
authored andcommitted
submodule--helper: don't recreate recursive prefix
update_submodule() uses duplicated code to compute update_data->displaypath and next.recursive_prefix. The latter is just the former with "/" appended to it, and since update_data->displaypath not changed outside of this statement, we can just reuse the already computed result. We can go one step further and remove the reference to next.recursive_prefix altogether. Since it is only used in update_data_to_args() (to compute the "--recursive-prefix" flag for the recursive update child process) we can just use the already computed .displaypath value of there. Delete the duplicated code, and remove the unnecessary reference to next.recursive_prefix. As a bonus, this fixes a memory leak where prefixed_path was never freed (this leak was first reported in [1]). [1] https://lore.kernel.org/git/877a45867ae368bf9e053caedcb6cf421e02344d.1655336146.git.gitgitgadget@gmail.com Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 618b844 commit cb49e1e

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

builtin/submodule--helper.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,9 +2417,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24172417

24182418
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
24192419
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
2420-
if (update_data->recursive_prefix)
2421-
strvec_pushl(args, "--recursive-prefix",
2422-
update_data->recursive_prefix, NULL);
2420+
if (update_data->displaypath) {
2421+
strvec_push(args, "--recursive-prefix");
2422+
strvec_pushf(args, "%s/", update_data->displaypath);
2423+
}
24232424
if (update_data->quiet)
24242425
strvec_push(args, "--quiet");
24252426
if (update_data->force)
@@ -2515,14 +2516,6 @@ static int update_submodule(struct update_data *update_data)
25152516
struct update_data next = *update_data;
25162517
int res;
25172518

2518-
if (update_data->recursive_prefix)
2519-
prefixed_path = xstrfmt("%s%s/", update_data->recursive_prefix,
2520-
update_data->sm_path);
2521-
else
2522-
prefixed_path = xstrfmt("%s/", update_data->sm_path);
2523-
2524-
next.recursive_prefix = get_submodule_displaypath(prefixed_path,
2525-
update_data->prefix);
25262519
next.prefix = NULL;
25272520
oidcpy(&next.oid, null_oid());
25282521
oidcpy(&next.suboid, null_oid());

0 commit comments

Comments
 (0)