git submodule update: have a dedicated helper for cloning

This introduces a new helper function in git submodule--helper
which takes care of cloning all submodules, which we want to
parallelize eventually.

Some tests (such as empty URL, update_mode=none) are required in the
helper to make the decision for cloning. These checks have been
moved into the C function as well (no need to repeat them in the
shell script).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stefan Beller
2016-02-29 18:07:17 -08:00
committed by Junio C Hamano
parent aa71049485
commit 48308681b0
2 changed files with 259 additions and 34 deletions

View File

@ -664,17 +664,20 @@ cmd_update()
cmd_init "--" "$@" || return
fi
cloned_modules=
git submodule--helper list --prefix "$wt_prefix" "$@" | {
{
git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
${wt_prefix:+--prefix "$wt_prefix"} \
${prefix:+--recursive-prefix "$prefix"} \
${update:+--update "$update"} \
${reference:+--reference "$reference"} \
${depth:+--depth "$depth"} \
"$@" || echo "#unmatched"
} | {
err=
while read mode sha1 stage sm_path
while read mode sha1 stage just_cloned sm_path
do
die_if_unmatched "$mode"
if test "$stage" = U
then
echo >&2 "Skipping unmerged submodule $prefix$sm_path"
continue
fi
name=$(git submodule--helper name "$sm_path") || exit
url=$(git config submodule."$name".url)
branch=$(get_submodule_config "$name" branch master)
@ -691,27 +694,10 @@ cmd_update()
displaypath=$(relative_path "$prefix$sm_path")
if test "$update_module" = "none"
if test $just_cloned -eq 1
then
echo >&2 "Skipping submodule '$displaypath'"
continue
fi
if test -z "$url"
then
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
Maybe you want to use 'update --init'?")"
continue
fi
if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
then
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
cloned_modules="$cloned_modules;$name"
subsha1=
update_module=checkout
else
subsha1=$(clear_local_git_env; cd "$sm_path" &&
git rev-parse --verify HEAD) ||
@ -751,13 +737,6 @@ Maybe you want to use 'update --init'?")"
die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
fi
# Is this something we just cloned?
case ";$cloned_modules;" in
*";$name;"*)
# then there is no local change to integrate
update_module=checkout ;;
esac
must_die_on_failure=
case "$update_module" in
checkout)