Skip to content

Commit 361cbe6

Browse files
committed
Merge branch 'ab/submodule-cleanup'
Further preparation to turn git-submodule.sh into a builtin. * ab/submodule-cleanup: git-sh-setup.sh: remove "say" function, change last users git-submodule.sh: use "$quiet", not "$GIT_QUIET" submodule--helper: eliminate internal "--update" option submodule--helper: understand --checkout, --merge and --rebase synonyms submodule--helper: report "submodule" as our name in some "-h" output submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" submodule update: remove "-v" option submodule--helper: have --require-init imply --init git-submodule.sh: remove unused top-level "--branch" argument git-submodule.sh: make the "$cached" variable a boolean git-submodule.sh: remove unused $prefix variable git-submodule.sh: remove unused sanitize_submodule_env()
2 parents 0455aad + 5b893f7 commit 361cbe6

File tree

7 files changed

+96
-103
lines changed

7 files changed

+96
-103
lines changed

builtin/submodule--helper.c

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
444444
};
445445

446446
const char *const git_submodule_helper_usage[] = {
447-
N_("git submodule--helper foreach [--quiet] [--recursive] [--] <command>"),
447+
N_("git submodule foreach [--quiet] [--recursive] [--] <command>"),
448448
NULL
449449
};
450450

@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix)
582582
};
583583

584584
const char *const git_submodule_helper_usage[] = {
585-
N_("git submodule--helper init [<options>] [<path>]"),
585+
N_("git submodule init [<options>] [<path>]"),
586586
NULL
587587
};
588588

@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix)
11851185
};
11861186

11871187
const char *const git_submodule_helper_usage[] = {
1188-
N_("git submodule--helper summary [<options>] [<commit>] [--] [<path>]"),
1188+
N_("git submodule summary [<options>] [<commit>] [--] [<path>]"),
11891189
NULL
11901190
};
11911191

@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix)
13491349
};
13501350

13511351
const char *const git_submodule_helper_usage[] = {
1352-
N_("git submodule--helper sync [--quiet] [--recursive] [<path>]"),
1352+
N_("git submodule sync [--quiet] [--recursive] [<path>]"),
13531353
NULL
13541354
};
13551355

@@ -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;
@@ -2405,8 +2403,27 @@ static void ensure_core_worktree(const char *path)
24052403
}
24062404
}
24072405

2406+
static const char *submodule_update_type_to_label(enum submodule_update_type type)
2407+
{
2408+
switch (type) {
2409+
case SM_UPDATE_CHECKOUT:
2410+
return "checkout";
2411+
case SM_UPDATE_MERGE:
2412+
return "merge";
2413+
case SM_UPDATE_REBASE:
2414+
return "rebase";
2415+
case SM_UPDATE_UNSPECIFIED:
2416+
case SM_UPDATE_NONE:
2417+
case SM_UPDATE_COMMAND:
2418+
break;
2419+
}
2420+
BUG("unreachable with type %d", type);
2421+
}
2422+
24082423
static void update_data_to_args(struct update_data *update_data, struct strvec *args)
24092424
{
2425+
enum submodule_update_type update_type = update_data->update_default;
2426+
24102427
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
24112428
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
24122429
if (update_data->recursive_prefix)
@@ -2430,8 +2447,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24302447
strvec_push(args, "--require-init");
24312448
if (update_data->depth)
24322449
strvec_pushf(args, "--depth=%d", update_data->depth);
2433-
if (update_data->update_default)
2434-
strvec_pushl(args, "--update", update_data->update_default, NULL);
2450+
if (update_type != SM_UPDATE_UNSPECIFIED)
2451+
strvec_pushf(args, "--%s",
2452+
submodule_update_type_to_label(update_type));
2453+
24352454
if (update_data->references.nr) {
24362455
struct string_list_item *item;
24372456
for_each_string_list_item(item, &update_data->references)
@@ -2601,9 +2620,15 @@ static int module_update(int argc, const char **argv, const char *prefix)
26012620
N_("path"),
26022621
N_("path into the working tree, across nested "
26032622
"submodule boundaries")),
2604-
OPT_STRING(0, "update", &opt.update_default,
2605-
N_("string"),
2606-
N_("rebase, merge, checkout or none")),
2623+
OPT_SET_INT(0, "checkout", &opt.update_default,
2624+
N_("use the 'checkout' update strategy (default)"),
2625+
SM_UPDATE_CHECKOUT),
2626+
OPT_SET_INT('m', "merge", &opt.update_default,
2627+
N_("use the 'merge' update strategy"),
2628+
SM_UPDATE_MERGE),
2629+
OPT_SET_INT('r', "rebase", &opt.update_default,
2630+
N_("use the 'rebase' update strategy"),
2631+
SM_UPDATE_REBASE),
26072632
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
26082633
N_("reference repository")),
26092634
OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2619,7 +2644,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26192644
OPT_BOOL(0, "progress", &opt.progress,
26202645
N_("force cloning progress")),
26212646
OPT_BOOL(0, "require-init", &opt.require_init,
2622-
N_("disallow cloning into non-empty directory")),
2647+
N_("disallow cloning into non-empty directory, implies --init")),
26232648
OPT_BOOL(0, "single-branch", &opt.single_branch,
26242649
N_("clone only one branch, HEAD or --branch")),
26252650
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2643,6 +2668,9 @@ static int module_update(int argc, const char **argv, const char *prefix)
26432668
argc = parse_options(argc, argv, prefix, module_update_options,
26442669
git_submodule_helper_usage, 0);
26452670

2671+
if (opt.require_init)
2672+
opt.init = 1;
2673+
26462674
if (filter_options.choice && !opt.init) {
26472675
usage_with_options(git_submodule_helper_usage,
26482676
module_update_options);
@@ -2651,9 +2679,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26512679
opt.filter_options = &filter_options;
26522680

26532681
if (opt.update_default)
2654-
if (parse_submodule_update_strategy(opt.update_default,
2655-
&opt.update_strategy) < 0)
2656-
die(_("bad value for update parameter"));
2682+
opt.update_strategy.type = opt.update_default;
26572683

26582684
if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
26592685
list_objects_filter_release(&filter_options);
@@ -2785,7 +2811,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
27852811
};
27862812

27872813
const char *const git_submodule_helper_usage[] = {
2788-
N_("git submodule--helper absorb-git-dirs [<options>] [<path>...]"),
2814+
N_("git submodule absorbgitdirs [<options>] [<path>...]"),
27892815
NULL
27902816
};
27912817

@@ -2890,7 +2916,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
28902916
OPT_END()
28912917
};
28922918
const char *const usage[] = {
2893-
N_("git submodule--helper set-url [--quiet] <path> <newurl>"),
2919+
N_("git submodule set-url [--quiet] <path> <newurl>"),
28942920
NULL
28952921
};
28962922

@@ -2929,8 +2955,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
29292955
OPT_END()
29302956
};
29312957
const char *const usage[] = {
2932-
N_("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>"),
2933-
N_("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
2958+
N_("git submodule set-branch [-q|--quiet] (-d|--default) <path>"),
2959+
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
29342960
NULL
29352961
};
29362962

@@ -3274,7 +3300,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
32743300
};
32753301

32763302
const char *const usage[] = {
3277-
N_("git submodule--helper add [<options>] [--] <repository> [<path>]"),
3303+
N_("git submodule add [<options>] [--] <repository> [<path>]"),
32783304
NULL
32793305
};
32803306

@@ -3387,7 +3413,7 @@ static struct cmd_struct commands[] = {
33873413
{"deinit", module_deinit, 0},
33883414
{"summary", module_summary, SUPPORT_SUPER_PREFIX},
33893415
{"push-check", push_check, 0},
3390-
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
3416+
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
33913417
{"is-active", is_active, 0},
33923418
{"check-name", check_name, 0},
33933419
{"config", module_config, 0},

contrib/subtree/git-subtree.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit
5050

5151
indent=0
5252

53+
# Usage: say [MSG...]
54+
say () {
55+
if test -z "$arg_quiet"
56+
then
57+
printf '%s\n' "$*"
58+
fi
59+
}
60+
5361
# Usage: debug [MSG...]
5462
debug () {
5563
if test -n "$arg_debug"
@@ -60,7 +68,7 @@ debug () {
6068

6169
# Usage: progress [MSG...]
6270
progress () {
63-
if test -z "$GIT_QUIET"
71+
if test -z "$arg_quiet"
6472
then
6573
if test -z "$arg_debug"
6674
then
@@ -146,6 +154,7 @@ main () {
146154
eval "$set_args"
147155

148156
# Begin "real" flag parsing.
157+
arg_quiet=
149158
arg_debug=
150159
arg_prefix=
151160
arg_split_branch=
@@ -161,7 +170,7 @@ main () {
161170

162171
case "$opt" in
163172
-q)
164-
GIT_QUIET=1
173+
arg_quiet=1
165174
;;
166175
-d)
167176
arg_debug=1
@@ -252,7 +261,7 @@ main () {
252261
dir="$(dirname "$arg_prefix/.")"
253262

254263
debug "command: {$arg_command}"
255-
debug "quiet: {$GIT_QUIET}"
264+
debug "quiet: {$arg_quiet}"
256265
debug "dir: {$dir}"
257266
debug "opts: {$*}"
258267
debug

git-instaweb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ resolve_full_httpd () {
102102

103103
start_httpd () {
104104
if test -f "$fqgitdir/pid"; then
105-
say "Instance already running. Restarting..."
105+
echo "Instance already running. Restarting..."
106106
stop_httpd
107107
fi
108108

git-sh-setup.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ die_with_status () {
5757
exit "$status"
5858
}
5959
60-
GIT_QUIET=
61-
62-
say () {
63-
if test -z "$GIT_QUIET"
64-
then
65-
printf '%s\n' "$*"
66-
fi
67-
}
68-
6960
if test -n "$OPTIONS_SPEC"; then
7061
usage() {
7162
"$0" -h
@@ -285,13 +276,6 @@ get_author_ident_from_commit () {
285276
parse_ident_from_commit author AUTHOR
286277
}
287278
288-
# Clear repo-local GIT_* environment variables. Useful when switching to
289-
# another repository (e.g. when entering a submodule). See also the env
290-
# list in git_connect()
291-
clear_local_git_env() {
292-
unset $(git rev-parse --local-env-vars)
293-
}
294-
295279
# Generate a virtual base file for a two-file merge. Uses git apply to
296280
# remove lines from $1 that are not in $2, leaving only common lines.
297281
create_virtual_base() {

0 commit comments

Comments
 (0)