submodule--helper: reorganize code for sh to C conversion

Introduce a function, update_submodule2(), that will implement the functionality of run-update-procedure and its surrounding shell code in submodule.sh. This name is temporary; it will replace update_submodule() when the sh to C conversion is complete. Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Glen Choo committed Mar 4, 2022 at 16:13 UTC 1a0b78c9537571c18bafc4ac6e3fc16fe6b63c84
1 file changed +21 -5
builtin/submodule--helper.c
+21 -5
@@ -2452,6 +2452,16 @@ static int do_run_update_procedure(struct update_data *ud)
2452 return run_update_command(ud, subforce);
2453 }
2454
2455 +/*
2456 + * NEEDSWORK: As we convert "git submodule update" to C,
2457 + * update_submodule2() will invoke more and more functions, making it
2458 + * difficult to preserve the function ordering without forward
2459 + * declarations.
2460 + *
2461 + * When the conversion is complete, this forward declaration will be
2462 + * unnecessary and should be removed.
2463 + */
2464 +static int update_submodule2(struct update_data *update_data);
2465 static void update_submodule(struct update_clone_data *ucd)
2466 {
2467 fprintf(stdout, "dummy %s %d\t%s\n",
@@ -2618,11 +2628,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
2628 &update_data.update_strategy);
2629
2630 free(prefixed_path);
2621 -
2622 - if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
2623 - return do_run_update_procedure(&update_data);
2624 -
2625 - return 3;
2631 + return update_submodule2(&update_data);
2632 }
2633
2634 static int resolve_relative_path(int argc, const char **argv, const char *prefix)
@@ -3022,6 +3028,16 @@ static int module_create_branch(int argc, const char **argv, const char *prefix)
3028 force, reflog, quiet, track, dry_run);
3029 return 0;
3030 }
3031 +
3032 +/* NEEDSWORK: this is a temporary name until we delete update_submodule() */
3033 +static int update_submodule2(struct update_data *update_data)
3034 +{
3035 + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force)
3036 + return do_run_update_procedure(update_data);
3037 +
3038 + return 3;
3039 +}
3040 +
3041 struct add_data {
3042 const char *prefix;
3043 const char *branch;