Skip to content

Commit b788fc6

Browse files
chooglengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f12108 commit b788fc6

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

builtin/submodule--helper.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18181818
static void determine_submodule_update_strategy(struct repository *r,
18191819
int just_cloned,
18201820
const char *path,
1821-
const char *update,
1821+
enum submodule_update_type update,
18221822
struct submodule_update_strategy *out)
18231823
{
18241824
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r,
18281828
key = xstrfmt("submodule.%s.update", sub->name);
18291829

18301830
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;
18341832
} else if (!repo_config_get_string_tmp(r, key, &val)) {
18351833
if (parse_submodule_update_strategy(val, out) < 0)
18361834
die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,7 @@ struct update_data {
18821880
const char *prefix;
18831881
const char *recursive_prefix;
18841882
const char *displaypath;
1885-
const char *update_default;
1883+
enum submodule_update_type update_default;
18861884
struct object_id suboid;
18871885
struct string_list references;
18881886
struct submodule_update_strategy update_strategy;
@@ -2423,6 +2421,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typ
24232421

24242422
static void update_data_to_args(struct update_data *update_data, struct strvec *args)
24252423
{
2424+
enum submodule_update_type update_type = update_data->update_default;
2425+
24262426
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
24272427
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
24282428
if (update_data->recursive_prefix)
@@ -2446,8 +2446,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24462446
strvec_push(args, "--require-init");
24472447
if (update_data->depth)
24482448
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+
24512453
if (update_data->references.nr) {
24522454
struct string_list_item *item;
24532455
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)
25992601
struct update_data opt = UPDATE_DATA_INIT;
26002602
struct list_objects_filter_options filter_options;
26012603
int ret;
2602-
enum submodule_update_type update_type = SM_UPDATE_UNSPECIFIED;
26032604

26042605
struct option module_update_options[] = {
26052606
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)
26182619
N_("path"),
26192620
N_("path into the working tree, across nested "
26202621
"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,
26252623
N_("use the 'checkout' update strategy (default)"),
26262624
SM_UPDATE_CHECKOUT),
2627-
OPT_SET_INT('m', "merge", &update_type,
2625+
OPT_SET_INT('m', "merge", &opt.update_default,
26282626
N_("use the 'merge' update strategy"),
26292627
SM_UPDATE_MERGE),
2630-
OPT_SET_INT('r', "rebase", &update_type,
2628+
OPT_SET_INT('r', "rebase", &opt.update_default,
26312629
N_("use the 'rebase' update strategy"),
26322630
SM_UPDATE_REBASE),
26332631
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)
26792677

26802678
opt.filter_options = &filter_options;
26812679

2682-
if (update_type != SM_UPDATE_UNSPECIFIED)
2683-
opt.update_default = submodule_update_type_to_label(update_type);
2684-
26852680
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;
26892682

26902683
if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
26912684
list_objects_filter_release(&filter_options);

0 commit comments

Comments
 (0)