submodule--helper: convert "{update,clone}" to their own "--super-prefix"

As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper status" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git". We need to convert both of these away from the global "--super-prefix" at the same time, because "update" will call "clone", but "clone" itself didn't make use of the global "--super-prefix" for displaying paths. It was only on the list of sub-commands that accepted it because "update"'s use of it would set it in its environment. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Dec 20, 2022 at 13:39 UTC f5a6be9d547700b7bd3018f1c0daf3d257cb2762
2 files changed +14 -20
builtin/submodule--helper.c
+13 -19
@@ -437,11 +437,13 @@ static int starts_with_dot_dot_slash(const char *const path)
437
438 struct init_cb {
439 const char *prefix;
440 + const char *super_prefix;
441 unsigned int flags;
442 };
443 #define INIT_CB_INIT { 0 }
444
445 static void init_submodule(const char *path, const char *prefix,
446 + const char *super_prefix,
447 unsigned int flags)
448 {
449 const struct submodule *sub;
@@ -449,8 +451,7 @@ static void init_submodule(const char *path, const char *prefix,
451 const char *upd;
452 char *url = NULL, *displaypath;
453
452 - displaypath = get_submodule_displaypath(path, prefix,
453 - get_super_prefix());
454 + displaypath = get_submodule_displaypath(path, prefix, super_prefix);
455
456 sub = submodule_from_path(the_repository, null_oid(), path);
457
@@ -526,7 +527,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data
527 {
528 struct init_cb *info = cb_data;
529
529 - init_submodule(list_item->name, info->prefix, info->flags);
530 + init_submodule(list_item->name, info->prefix, info->super_prefix,
531 + info->flags);
532 }
533
534 static int module_init(int argc, const char **argv, const char *prefix)
@@ -792,6 +794,7 @@ struct summary_cb {
794 int argc;
795 const char **argv;
796 const char *prefix;
797 + const char *super_prefix;
798 unsigned int cached: 1;
799 unsigned int for_status: 1;
800 unsigned int files: 1;
@@ -954,7 +957,7 @@ static void generate_submodule_summary(struct summary_cb *info,
957 }
958
959 displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
957 - get_super_prefix());
960 + info->super_prefix);
961
962 if (!missing_src && !missing_dst) {
963 struct child_process cp_rev_list = CHILD_PROCESS_INIT;
@@ -1893,6 +1896,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc)
1896
1897 struct update_data {
1898 const char *prefix;
1899 + const char *super_prefix;
1900 char *displaypath;
1901 enum submodule_update_type update_default;
1902 struct object_id suboid;
@@ -1969,7 +1973,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1973 char *key;
1974 const struct update_data *ud = suc->update_data;
1975 char *displaypath = get_submodule_displaypath(ce->name, ud->prefix,
1972 - get_super_prefix());
1976 + ud->super_prefix);
1977 struct strbuf sb = STRBUF_INIT;
1978 int needs_cloning = 0;
1979 int need_free_url = 0;
@@ -2449,11 +2453,11 @@ static void update_data_to_args(const struct update_data *update_data,
2453 {
2454 enum submodule_update_type update_type = update_data->update_default;
2455
2456 + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
2457 if (update_data->displaypath) {
2458 strvec_push(args, "--super-prefix");
2459 strvec_pushf(args, "%s/", update_data->displaypath);
2460 }
2456 - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
2461 strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
2462 if (update_data->quiet)
2463 strvec_push(args, "--quiet");
@@ -2620,7 +2624,7 @@ static int update_submodules(struct update_data *update_data)
2624
2625 update_data->displaypath = get_submodule_displaypath(
2626 update_data->sm_path, update_data->prefix,
2623 - get_super_prefix());
2627 + update_data->super_prefix);
2628 code = update_submodule(update_data);
2629 FREE_AND_NULL(update_data->displaypath);
2630 fail:
@@ -2646,6 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2650 LIST_OBJECTS_FILTER_INIT;
2651 int ret;
2652 struct option module_update_options[] = {
2653 + OPT__SUPER_PREFIX(&opt.super_prefix),
2654 OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
2655 OPT_BOOL(0, "init", &opt.init,
2656 N_("initialize uninitialized submodules before update")),
@@ -2742,6 +2747,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2747 module_list_active(&list);
2748
2749 info.prefix = opt.prefix;
2750 + info.super_prefix = opt.super_prefix;
2751 if (opt.quiet)
2752 info.flags |= OPT_QUIET;
2753
@@ -3368,8 +3374,6 @@ cleanup:
3374
3375 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
3376 {
3371 - const char *cmd = argv[0];
3372 - const char *subcmd;
3377 parse_opt_subcommand_fn *fn = NULL;
3378 const char *const usage[] = {
3379 N_("git submodule--helper <command>"),
@@ -3393,16 +3397,6 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
3397 OPT_END()
3398 };
3399 argc = parse_options(argc, argv, prefix, options, usage, 0);
3396 - subcmd = argv[0];
3397 -
3398 - if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") &&
3399 - get_super_prefix())
3400 - /*
3401 - * xstrfmt() rather than "%s %s" to keep the translated
3402 - * string identical to git.c's.
3403 - */
3404 - die(_("%s doesn't support --super-prefix"),
3405 - xstrfmt("'%s %s'", cmd, subcmd));
3400
3401 return fn(argc, argv, prefix);
3402 }
git.c
+1 -1
@@ -610,7 +610,7 @@ static struct cmd_struct commands[] = {
610 { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
611 { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
612 { "stripspace", cmd_stripspace },
613 - { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX },
613 + { "submodule--helper", cmd_submodule__helper, RUN_SETUP },
614 { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
615 { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
616 { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },