submodule--helper: eliminate internal "--update" option

Follow-up on the preceding commit which taught "git submodule--helper update" to understand "--merge", "--checkout" and "--rebase" and use those options instead of "--update=(rebase|merge|checkout|none)" when the command invokes itself. Unlike the preceding change this isn't strictly necessary to eventually change "git-submodule.sh" so that it invokes "git submodule--helper update" directly, but let's remove this inconsistency in the command-line interface. We shouldn't need to carry special synonyms for existing options in "git submodule--helper" when that command can use the primary documented names instead. But, as seen in the post-image this makes the control flow within "builtin/submodule--helper.c" simpler, we can now write directly to the "update_default" member of "struct update_data" when parsing the options in "module_update()". Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Glen Choo committed Jun 28, 2022 at 12:05 UTC b788fc671bf1862a72f9fe7256affd7d152b8a6f
1 file changed +13 -20
builtin/submodule--helper.c
+13 -20
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1818 static void determine_submodule_update_strategy(struct repository *r,
1819 int just_cloned,
1820 const char *path,
1821 - const char *update,
1821 + enum submodule_update_type update,
1822 struct submodule_update_strategy *out)
1823 {
1824 const struct submodule *sub = submodule_from_path(r, null_oid(), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r,
1828 key = xstrfmt("submodule.%s.update", sub->name);
1829
1830 if (update) {
1831 - if (parse_submodule_update_strategy(update, out) < 0)
1832 - die(_("Invalid update mode '%s' for submodule path '%s'"),
1833 - update, path);
1831 + out->type = update;
1832 } else if (!repo_config_get_string_tmp(r, key, &val)) {
1833 if (parse_submodule_update_strategy(val, out) < 0)
1834 die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,7 @@ struct update_data {
1880 const char *prefix;
1881 const char *recursive_prefix;
1882 const char *displaypath;
1885 - const char *update_default;
1883 + enum submodule_update_type update_default;
1884 struct object_id suboid;
1885 struct string_list references;
1886 struct submodule_update_strategy update_strategy;
@@ -2423,6 +2421,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typ
2421
2422 static void update_data_to_args(struct update_data *update_data, struct strvec *args)
2423 {
2424 + enum submodule_update_type update_type = update_data->update_default;
2425 +
2426 strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
2427 strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
2428 if (update_data->recursive_prefix)
@@ -2446,8 +2446,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
2446 strvec_push(args, "--require-init");
2447 if (update_data->depth)
2448 strvec_pushf(args, "--depth=%d", update_data->depth);
2449 - if (update_data->update_default)
2450 - strvec_pushl(args, "--update", update_data->update_default, NULL);
2449 + if (update_type != SM_UPDATE_UNSPECIFIED)
2450 + strvec_pushf(args, "--%s",
2451 + submodule_update_type_to_label(update_type));
2452 +
2453 if (update_data->references.nr) {
2454 struct string_list_item *item;
2455 for_each_string_list_item(item, &update_data->references)
@@ -2599,7 +2601,6 @@ static int module_update(int argc, const char **argv, const char *prefix)
2601 struct update_data opt = UPDATE_DATA_INIT;
2602 struct list_objects_filter_options filter_options;
2603 int ret;
2602 - enum submodule_update_type update_type = SM_UPDATE_UNSPECIFIED;
2604
2605 struct option module_update_options[] = {
2606 OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
@@ -2618,16 +2619,13 @@ static int module_update(int argc, const char **argv, const char *prefix)
2619 N_("path"),
2620 N_("path into the working tree, across nested "
2621 "submodule boundaries")),
2621 - OPT_STRING(0, "update", &opt.update_default,
2622 - N_("string"),
2623 - N_("rebase, merge, checkout or none")),
2624 - OPT_SET_INT(0, "checkout", &update_type,
2622 + OPT_SET_INT(0, "checkout", &opt.update_default,
2623 N_("use the 'checkout' update strategy (default)"),
2624 SM_UPDATE_CHECKOUT),
2627 - OPT_SET_INT('m', "merge", &update_type,
2625 + OPT_SET_INT('m', "merge", &opt.update_default,
2626 N_("use the 'merge' update strategy"),
2627 SM_UPDATE_MERGE),
2630 - OPT_SET_INT('r', "rebase", &update_type,
2628 + OPT_SET_INT('r', "rebase", &opt.update_default,
2629 N_("use the 'rebase' update strategy"),
2630 SM_UPDATE_REBASE),
2631 OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
@@ -2679,13 +2677,8 @@ static int module_update(int argc, const char **argv, const char *prefix)
2677
2678 opt.filter_options = &filter_options;
2679
2682 - if (update_type != SM_UPDATE_UNSPECIFIED)
2683 - opt.update_default = submodule_update_type_to_label(update_type);
2684 -
2680 if (opt.update_default)
2686 - if (parse_submodule_update_strategy(opt.update_default,
2687 - &opt.update_strategy) < 0)
2688 - die(_("bad value for update parameter"));
2681 + opt.update_strategy.type = opt.update_default;
2682
2683 if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
2684 list_objects_filter_release(&filter_options);