submodule--helper: reduce logic in run_update_procedure()
A later commit will combine the "update-clone" and "run-update-procedure" commands, so run_update_procedure() will be removed. Prepare for this by moving as much logic as possible out of run_update_procedure() and into update_submodule2(). Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Mar 15, 2022 at 14:09 UTC
75df9df0f81368816612cdb11a6c4bb054724ea3
1 file changed
+17
-13
builtin/submodule--helper.c
+17
-13
@@ -2611,7 +2611,6 @@ static int update_clone(int argc, const char **argv, const char *prefix)
2611
2612
static int run_update_procedure(int argc, const char **argv, const char *prefix)
2613
{
2614
- char *prefixed_path;
2614
struct update_data update_data = UPDATE_DATA_INIT;
2615
2616
struct option options[] = {
@@ -2653,18 +2652,6 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
2652
2653
update_data.sm_path = argv[0];
2654
2656
- if (update_data.recursive_prefix)
2657
- prefixed_path = xstrfmt("%s%s", update_data.recursive_prefix, update_data.sm_path);
2658
- else
2659
- prefixed_path = xstrdup(update_data.sm_path);
2660
-
2661
- update_data.displaypath = get_submodule_displaypath(prefixed_path, prefix);
2662
-
2663
- determine_submodule_update_strategy(the_repository, update_data.just_cloned,
2664
- update_data.sm_path, update_data.update_default,
2665
- &update_data.update_strategy);
2666
-
2667
- free(prefixed_path);
2655
return update_submodule2(&update_data);
2656
}
2657
@@ -3044,7 +3031,24 @@ static int module_create_branch(int argc, const char **argv, const char *prefix)
3031
/* NEEDSWORK: this is a temporary name until we delete update_submodule() */
3032
static int update_submodule2(struct update_data *update_data)
3033
{
3034
+ char *prefixed_path;
3035
+
3036
ensure_core_worktree(update_data->sm_path);
3037
+
3038
+ if (update_data->recursive_prefix)
3039
+ prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix,
3040
+ update_data->sm_path);
3041
+ else
3042
+ prefixed_path = xstrdup(update_data->sm_path);
3043
+
3044
+ update_data->displaypath = get_submodule_displaypath(prefixed_path,
3045
+ update_data->prefix);
3046
+ free(prefixed_path);
3047
+
3048
+ determine_submodule_update_strategy(the_repository, update_data->just_cloned,
3049
+ update_data->sm_path, update_data->update_default,
3050
+ &update_data->update_strategy);
3051
+
3052
if (update_data->just_cloned)
3053
oidcpy(&update_data->suboid, null_oid());
3054
else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))