Skip to content

Commit f5a6be9

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04f1fab commit f5a6be9

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

builtin/submodule--helper.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,21 @@ static int starts_with_dot_dot_slash(const char *const path)
437437

438438
struct init_cb {
439439
const char *prefix;
440+
const char *super_prefix;
440441
unsigned int flags;
441442
};
442443
#define INIT_CB_INIT { 0 }
443444

444445
static void init_submodule(const char *path, const char *prefix,
446+
const char *super_prefix,
445447
unsigned int flags)
446448
{
447449
const struct submodule *sub;
448450
struct strbuf sb = STRBUF_INIT;
449451
const char *upd;
450452
char *url = NULL, *displaypath;
451453

452-
displaypath = get_submodule_displaypath(path, prefix,
453-
get_super_prefix());
454+
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
454455

455456
sub = submodule_from_path(the_repository, null_oid(), path);
456457

@@ -526,7 +527,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data
526527
{
527528
struct init_cb *info = cb_data;
528529

529-
init_submodule(list_item->name, info->prefix, info->flags);
530+
init_submodule(list_item->name, info->prefix, info->super_prefix,
531+
info->flags);
530532
}
531533

532534
static int module_init(int argc, const char **argv, const char *prefix)
@@ -792,6 +794,7 @@ struct summary_cb {
792794
int argc;
793795
const char **argv;
794796
const char *prefix;
797+
const char *super_prefix;
795798
unsigned int cached: 1;
796799
unsigned int for_status: 1;
797800
unsigned int files: 1;
@@ -954,7 +957,7 @@ static void generate_submodule_summary(struct summary_cb *info,
954957
}
955958

956959
displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
957-
get_super_prefix());
960+
info->super_prefix);
958961

959962
if (!missing_src && !missing_dst) {
960963
struct child_process cp_rev_list = CHILD_PROCESS_INIT;
@@ -1893,6 +1896,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc)
18931896

18941897
struct update_data {
18951898
const char *prefix;
1899+
const char *super_prefix;
18961900
char *displaypath;
18971901
enum submodule_update_type update_default;
18981902
struct object_id suboid;
@@ -1969,7 +1973,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
19691973
char *key;
19701974
const struct update_data *ud = suc->update_data;
19711975
char *displaypath = get_submodule_displaypath(ce->name, ud->prefix,
1972-
get_super_prefix());
1976+
ud->super_prefix);
19731977
struct strbuf sb = STRBUF_INIT;
19741978
int needs_cloning = 0;
19751979
int need_free_url = 0;
@@ -2449,11 +2453,11 @@ static void update_data_to_args(const struct update_data *update_data,
24492453
{
24502454
enum submodule_update_type update_type = update_data->update_default;
24512455

2456+
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
24522457
if (update_data->displaypath) {
24532458
strvec_push(args, "--super-prefix");
24542459
strvec_pushf(args, "%s/", update_data->displaypath);
24552460
}
2456-
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
24572461
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
24582462
if (update_data->quiet)
24592463
strvec_push(args, "--quiet");
@@ -2620,7 +2624,7 @@ static int update_submodules(struct update_data *update_data)
26202624

26212625
update_data->displaypath = get_submodule_displaypath(
26222626
update_data->sm_path, update_data->prefix,
2623-
get_super_prefix());
2627+
update_data->super_prefix);
26242628
code = update_submodule(update_data);
26252629
FREE_AND_NULL(update_data->displaypath);
26262630
fail:
@@ -2646,6 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26462650
LIST_OBJECTS_FILTER_INIT;
26472651
int ret;
26482652
struct option module_update_options[] = {
2653+
OPT__SUPER_PREFIX(&opt.super_prefix),
26492654
OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
26502655
OPT_BOOL(0, "init", &opt.init,
26512656
N_("initialize uninitialized submodules before update")),
@@ -2742,6 +2747,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
27422747
module_list_active(&list);
27432748

27442749
info.prefix = opt.prefix;
2750+
info.super_prefix = opt.super_prefix;
27452751
if (opt.quiet)
27462752
info.flags |= OPT_QUIET;
27472753

@@ -3368,8 +3374,6 @@ static int module_add(int argc, const char **argv, const char *prefix)
33683374

33693375
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
33703376
{
3371-
const char *cmd = argv[0];
3372-
const char *subcmd;
33733377
parse_opt_subcommand_fn *fn = NULL;
33743378
const char *const usage[] = {
33753379
N_("git submodule--helper <command>"),
@@ -3393,16 +3397,6 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
33933397
OPT_END()
33943398
};
33953399
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));
34063400

34073401
return fn(argc, argv, prefix);
34083402
}

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static struct cmd_struct commands[] = {
610610
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
611611
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
612612
{ "stripspace", cmd_stripspace },
613-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX },
613+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
614614
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
615615
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
616616
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },

0 commit comments

Comments
 (0)