Skip to content

Commit 0e795b2

Browse files
chooglengitster
authored andcommitted
submodule--helper update: use one param per type
git-submodule.sh accepts literal 'update types' as options, but parses them into a "--update" option for "git submodule--helper update", e.g. "--checkout" becomes "--update=checkout". Teach the 'update type' options to "git submodule--helper update" so that we no longer have to do this parsing in git-submodule.sh, and append them to `opts`. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa7c5fe commit 0e795b2

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

builtin/submodule--helper.c

Lines changed: 24 additions & 13 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,6 @@ struct update_data {
18821880
const char *prefix;
18831881
const char *recursive_prefix;
18841882
const char *displaypath;
1885-
const char *update_default;
18861883
struct object_id suboid;
18871884
struct string_list references;
18881885
struct submodule_update_strategy update_strategy;
@@ -1892,6 +1889,7 @@ struct update_data {
18921889
int max_jobs;
18931890
int single_branch;
18941891
int recommend_shallow;
1892+
enum submodule_update_type update_default;
18951893
unsigned int require_init;
18961894
unsigned int force;
18971895
unsigned int quiet;
@@ -2429,8 +2427,20 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24292427
strvec_push(args, "--require-init");
24302428
if (update_data->depth)
24312429
strvec_pushf(args, "--depth=%d", update_data->depth);
2432-
if (update_data->update_default)
2433-
strvec_pushl(args, "--update", update_data->update_default, NULL);
2430+
switch (update_data->update_default) {
2431+
case SM_UPDATE_MERGE:
2432+
strvec_push(args, "--merge");
2433+
break;
2434+
case SM_UPDATE_CHECKOUT:
2435+
strvec_push(args, "--checkout");
2436+
break;
2437+
case SM_UPDATE_REBASE:
2438+
strvec_push(args, "--rebase");
2439+
break;
2440+
default:
2441+
break;
2442+
}
2443+
24342444
if (update_data->references.nr) {
24352445
struct string_list_item *item;
24362446
for_each_string_list_item(item, &update_data->references)
@@ -2600,9 +2610,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
26002610
N_("path"),
26012611
N_("path into the working tree, across nested "
26022612
"submodule boundaries")),
2603-
OPT_STRING(0, "update", &opt.update_default,
2604-
N_("string"),
2605-
N_("rebase, merge, checkout or none")),
2613+
OPT_SET_INT(0, "checkout", &opt.update_default,
2614+
N_("update using checkout"), SM_UPDATE_CHECKOUT),
2615+
OPT_SET_INT('r', "rebase", &opt.update_default,
2616+
N_("update using rebase"), SM_UPDATE_REBASE),
2617+
OPT_SET_INT('m', "merge", &opt.update_default,
2618+
N_("update using merge"), SM_UPDATE_MERGE),
26062619
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
26072620
N_("reference repository")),
26082621
OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2654,9 +2667,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26542667
opt.filter_options = &filter_options;
26552668

26562669
if (opt.update_default)
2657-
if (parse_submodule_update_strategy(opt.update_default,
2658-
&opt.update_strategy) < 0)
2659-
die(_("bad value for update parameter"));
2670+
opt.update_strategy.type = opt.update_default;
26602671

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

git-submodule.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ force=
3535
cached=
3636
recursive=
3737
files=
38-
update=
3938
prefix=
4039
custom_name=
4140
depth=
@@ -267,7 +266,7 @@ cmd_update()
267266
opts="$opts $1"
268267
;;
269268
-r|--rebase)
270-
update="rebase"
269+
opts="$opts $1"
271270
;;
272271
--reference)
273272
case "$2" in '') usage ;; esac
@@ -281,13 +280,13 @@ cmd_update()
281280
opts="$opts $1"
282281
;;
283282
-m|--merge)
284-
update="merge"
283+
opts="$opts $1"
285284
;;
286285
--recursive)
287286
opts="$opts $1"
288287
;;
289288
--checkout)
290-
update="checkout"
289+
opts="$opts $1"
291290
;;
292291
--recommend-shallow)
293292
opts="$opts $1"
@@ -343,7 +342,6 @@ cmd_update()
343342
${GIT_QUIET:+--quiet} \
344343
${wt_prefix:+--prefix "$wt_prefix"} \
345344
${prefix:+--recursive-prefix "$prefix"} \
346-
${update:+--update "$update"} \
347345
$opts \
348346
-- \
349347
"$@"

0 commit comments

Comments
 (0)