1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-19 18:46:09 +02:00

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()
This commit is contained in:
Junio C Hamano 2022-07-14 15:04:00 -07:00
commit 361cbe6d6d
7 changed files with 96 additions and 103 deletions

View File

@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
};
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper foreach [--quiet] [--recursive] [--] <command>"),
N_("git submodule foreach [--quiet] [--recursive] [--] <command>"),
NULL
};
@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix)
};
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper init [<options>] [<path>]"),
N_("git submodule init [<options>] [<path>]"),
NULL
};
@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix)
};
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper summary [<options>] [<commit>] [--] [<path>]"),
N_("git submodule summary [<options>] [<commit>] [--] [<path>]"),
NULL
};
@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix)
};
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper sync [--quiet] [--recursive] [<path>]"),
N_("git submodule sync [--quiet] [--recursive] [<path>]"),
NULL
};
@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
static void determine_submodule_update_strategy(struct repository *r,
int just_cloned,
const char *path,
const char *update,
enum submodule_update_type update,
struct submodule_update_strategy *out)
{
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r,
key = xstrfmt("submodule.%s.update", sub->name);
if (update) {
if (parse_submodule_update_strategy(update, out) < 0)
die(_("Invalid update mode '%s' for submodule path '%s'"),
update, path);
out->type = update;
} else if (!repo_config_get_string_tmp(r, key, &val)) {
if (parse_submodule_update_strategy(val, out) < 0)
die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@ -1882,7 +1880,7 @@ struct update_data {
const char *prefix;
const char *recursive_prefix;
const char *displaypath;
const char *update_default;
enum submodule_update_type update_default;
struct object_id suboid;
struct string_list references;
struct submodule_update_strategy update_strategy;
@ -2405,8 +2403,27 @@ static void ensure_core_worktree(const char *path)
}
}
static const char *submodule_update_type_to_label(enum submodule_update_type type)
{
switch (type) {
case SM_UPDATE_CHECKOUT:
return "checkout";
case SM_UPDATE_MERGE:
return "merge";
case SM_UPDATE_REBASE:
return "rebase";
case SM_UPDATE_UNSPECIFIED:
case SM_UPDATE_NONE:
case SM_UPDATE_COMMAND:
break;
}
BUG("unreachable with type %d", type);
}
static void update_data_to_args(struct update_data *update_data, struct strvec *args)
{
enum submodule_update_type update_type = update_data->update_default;
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
if (update_data->recursive_prefix)
@ -2430,8 +2447,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
strvec_push(args, "--require-init");
if (update_data->depth)
strvec_pushf(args, "--depth=%d", update_data->depth);
if (update_data->update_default)
strvec_pushl(args, "--update", update_data->update_default, NULL);
if (update_type != SM_UPDATE_UNSPECIFIED)
strvec_pushf(args, "--%s",
submodule_update_type_to_label(update_type));
if (update_data->references.nr) {
struct string_list_item *item;
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)
N_("path"),
N_("path into the working tree, across nested "
"submodule boundaries")),
OPT_STRING(0, "update", &opt.update_default,
N_("string"),
N_("rebase, merge, checkout or none")),
OPT_SET_INT(0, "checkout", &opt.update_default,
N_("use the 'checkout' update strategy (default)"),
SM_UPDATE_CHECKOUT),
OPT_SET_INT('m', "merge", &opt.update_default,
N_("use the 'merge' update strategy"),
SM_UPDATE_MERGE),
OPT_SET_INT('r', "rebase", &opt.update_default,
N_("use the 'rebase' update strategy"),
SM_UPDATE_REBASE),
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
N_("reference repository")),
OPT_BOOL(0, "dissociate", &opt.dissociate,
@ -2619,7 +2644,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "progress", &opt.progress,
N_("force cloning progress")),
OPT_BOOL(0, "require-init", &opt.require_init,
N_("disallow cloning into non-empty directory")),
N_("disallow cloning into non-empty directory, implies --init")),
OPT_BOOL(0, "single-branch", &opt.single_branch,
N_("clone only one branch, HEAD or --branch")),
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@ -2643,6 +2668,9 @@ static int module_update(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, module_update_options,
git_submodule_helper_usage, 0);
if (opt.require_init)
opt.init = 1;
if (filter_options.choice && !opt.init) {
usage_with_options(git_submodule_helper_usage,
module_update_options);
@ -2651,9 +2679,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
opt.filter_options = &filter_options;
if (opt.update_default)
if (parse_submodule_update_strategy(opt.update_default,
&opt.update_strategy) < 0)
die(_("bad value for update parameter"));
opt.update_strategy.type = opt.update_default;
if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
list_objects_filter_release(&filter_options);
@ -2785,7 +2811,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
};
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper absorb-git-dirs [<options>] [<path>...]"),
N_("git submodule absorbgitdirs [<options>] [<path>...]"),
NULL
};
@ -2890,7 +2916,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
OPT_END()
};
const char *const usage[] = {
N_("git submodule--helper set-url [--quiet] <path> <newurl>"),
N_("git submodule set-url [--quiet] <path> <newurl>"),
NULL
};
@ -2929,8 +2955,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
OPT_END()
};
const char *const usage[] = {
N_("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>"),
N_("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
N_("git submodule set-branch [-q|--quiet] (-d|--default) <path>"),
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
NULL
};
@ -3274,7 +3300,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
};
const char *const usage[] = {
N_("git submodule--helper add [<options>] [--] <repository> [<path>]"),
N_("git submodule add [<options>] [--] <repository> [<path>]"),
NULL
};
@ -3387,7 +3413,7 @@ static struct cmd_struct commands[] = {
{"deinit", module_deinit, 0},
{"summary", module_summary, SUPPORT_SUPER_PREFIX},
{"push-check", push_check, 0},
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
{"is-active", is_active, 0},
{"check-name", check_name, 0},
{"config", module_config, 0},

View File

@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit
indent=0
# Usage: say [MSG...]
say () {
if test -z "$arg_quiet"
then
printf '%s\n' "$*"
fi
}
# Usage: debug [MSG...]
debug () {
if test -n "$arg_debug"
@ -60,7 +68,7 @@ debug () {
# Usage: progress [MSG...]
progress () {
if test -z "$GIT_QUIET"
if test -z "$arg_quiet"
then
if test -z "$arg_debug"
then
@ -146,6 +154,7 @@ main () {
eval "$set_args"
# Begin "real" flag parsing.
arg_quiet=
arg_debug=
arg_prefix=
arg_split_branch=
@ -161,7 +170,7 @@ main () {
case "$opt" in
-q)
GIT_QUIET=1
arg_quiet=1
;;
-d)
arg_debug=1
@ -252,7 +261,7 @@ main () {
dir="$(dirname "$arg_prefix/.")"
debug "command: {$arg_command}"
debug "quiet: {$GIT_QUIET}"
debug "quiet: {$arg_quiet}"
debug "dir: {$dir}"
debug "opts: {$*}"
debug

View File

@ -102,7 +102,7 @@ resolve_full_httpd () {
start_httpd () {
if test -f "$fqgitdir/pid"; then
say "Instance already running. Restarting..."
echo "Instance already running. Restarting..."
stop_httpd
fi

View File

@ -57,15 +57,6 @@ die_with_status () {
exit "$status"
}
GIT_QUIET=
say () {
if test -z "$GIT_QUIET"
then
printf '%s\n' "$*"
fi
}
if test -n "$OPTIONS_SPEC"; then
usage() {
"$0" -h
@ -285,13 +276,6 @@ get_author_ident_from_commit () {
parse_ident_from_commit author AUTHOR
}
# Clear repo-local GIT_* environment variables. Useful when switching to
# another repository (e.g. when entering a submodule). See also the env
# list in git_connect()
clear_local_git_env() {
unset $(git rev-parse --local-env-vars)
}
# Generate a virtual base file for a two-file merge. Uses git apply to
# remove lines from $1 that are not in $2, leaving only common lines.
create_virtual_base() {

View File

@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0
export GIT_PROTOCOL_FROM_USER
command=
quiet=
branch=
force=
reference=
@ -40,8 +41,9 @@ require_init=
files=
remote=
nofetch=
update=
prefix=
rebase=
merge=
checkout=
custom_name=
depth=
progress=
@ -56,17 +58,6 @@ isnumber()
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
}
# Sanitize the local git environment for use within a submodule. We
# can't simply use clear_local_git_env since we want to preserve some
# of the settings from GIT_CONFIG_PARAMETERS.
sanitize_submodule_env()
{
save_config=$GIT_CONFIG_PARAMETERS
clear_local_git_env
GIT_CONFIG_PARAMETERS=$save_config
export GIT_CONFIG_PARAMETERS
}
#
# Add a new submodule to the working tree, .gitmodules and the index
#
@ -90,7 +81,7 @@ cmd_add()
force=$1
;;
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--progress)
progress=1
@ -138,7 +129,7 @@ cmd_add()
usage
fi
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
}
#
@ -154,7 +145,7 @@ cmd_foreach()
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--recursive)
recursive=1
@ -169,7 +160,7 @@ cmd_foreach()
shift
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@"
}
#
@ -184,7 +175,7 @@ cmd_init()
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--)
shift
@ -200,7 +191,7 @@ cmd_init()
shift
done
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@"
}
#
@ -217,7 +208,7 @@ cmd_deinit()
force=$1
;;
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--all)
deinit_all=t
@ -236,7 +227,7 @@ cmd_deinit()
shift
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
}
#
@ -251,10 +242,7 @@ cmd_update()
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
;;
-v)
unset GIT_QUIET
quiet=1
;;
--progress)
progress=1
@ -263,7 +251,6 @@ cmd_update()
init=1
;;
--require-init)
init=1
require_init=1
;;
--remote)
@ -276,7 +263,7 @@ cmd_update()
force=$1
;;
-r|--rebase)
update="rebase"
rebase=1
;;
--reference)
case "$2" in '') usage ;; esac
@ -290,13 +277,13 @@ cmd_update()
dissociate=1
;;
-m|--merge)
update="merge"
merge=1
;;
--recursive)
recursive=1
;;
--checkout)
update="checkout"
checkout=1
;;
--recommend-shallow)
recommend_shallow="--recommend-shallow"
@ -349,7 +336,7 @@ cmd_update()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
${GIT_QUIET:+--quiet} \
${quiet:+--quiet} \
${force:+--force} \
${progress:+"--progress"} \
${remote:+--remote} \
@ -357,8 +344,9 @@ cmd_update()
${init:+--init} \
${nofetch:+--no-fetch} \
${wt_prefix:+--prefix "$wt_prefix"} \
${prefix:+--recursive-prefix "$prefix"} \
${update:+--update "$update"} \
${rebase:+--rebase} \
${merge:+--merge} \
${checkout:+--checkout} \
${reference:+"$reference"} \
${dissociate:+"--dissociate"} \
${depth:+"$depth"} \
@ -409,7 +397,7 @@ cmd_set_branch() {
shift
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
}
#
@ -422,7 +410,7 @@ cmd_set_url() {
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--)
shift
@ -438,7 +426,7 @@ cmd_set_url() {
shift
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@"
}
#
@ -459,7 +447,7 @@ cmd_summary() {
do
case "$1" in
--cached)
cached="$1"
cached=1
;;
--files)
files="$1"
@ -509,7 +497,7 @@ cmd_status()
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
quiet=1
;;
--cached)
cached=1
@ -531,7 +519,7 @@ cmd_status()
shift
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
}
#
# Sync remote urls for submodules
@ -544,7 +532,7 @@ cmd_sync()
do
case "$1" in
-q|--quiet)
GIT_QUIET=1
quiet=1
shift
;;
--recursive)
@ -564,12 +552,12 @@ cmd_sync()
esac
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@"
}
cmd_absorbgitdirs()
{
git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@"
git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@"
}
# This loop parses the command line arguments to find the
@ -585,18 +573,10 @@ do
command=$1
;;
-q|--quiet)
GIT_QUIET=1
;;
-b|--branch)
case "$2" in
'')
usage
;;
esac
branch="$2"; shift
quiet=1
;;
--cached)
cached="$1"
cached=1
;;
--)
break
@ -622,12 +602,6 @@ then
fi
fi
# "-b branch" is accepted only by "add" and "set-branch"
if test -n "$branch" && (test "$command" != add || test "$command" != set-branch)
then
usage
fi
# "--cached" is accepted only by "status" and "summary"
if test -n "$cached" && test "$command" != status && test "$command" != summary
then

View File

@ -2374,7 +2374,7 @@ void absorb_git_dir_into_superproject(const char *path,
cp.no_stdin = 1;
strvec_pushl(&cp.args, "--super-prefix", sb.buf,
"submodule--helper",
"absorb-git-dirs", NULL);
"absorbgitdirs", NULL);
prepare_submodule_repo_env(&cp.env);
if (run_command(&cp))
die(_("could not recurse into submodule '%s'"), path);

View File

@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase'
git submodule update --rebase --quiet >out 2>err &&
test_must_be_empty out &&
test_must_be_empty err &&
git submodule update --rebase -v >out 2>err &&
git submodule update --rebase >out 2>err &&
test_file_not_empty out &&
test_must_be_empty err
)