submodule: port submodule subcommand 'sync' from shell to C
Port the submodule subcommand 'sync' from shell to C using the same mechanism as that used for porting submodule subcommand 'status'. Hence, here the function cmd_sync() is ported from shell to C. This is done by introducing four functions: module_sync(), sync_submodule(), sync_submodule_cb() and print_default_remote(). The function print_default_remote() is introduced for getting the default remote as stdout. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Stefan Beller <sbeller@google.com> Signed-off-by: Prathamesh Chavan <pc44800@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
36438dc19d
commit
13424764db
@ -1036,63 +1036,8 @@ cmd_sync()
|
||||
;;
|
||||
esac
|
||||
done
|
||||
cd_to_toplevel
|
||||
{
|
||||
git submodule--helper list --prefix "$wt_prefix" "$@" ||
|
||||
echo "#unmatched" $?
|
||||
} |
|
||||
while read -r mode sha1 stage sm_path
|
||||
do
|
||||
die_if_unmatched "$mode" "$sha1"
|
||||
|
||||
# skip inactive submodules
|
||||
if ! git submodule--helper is-active "$sm_path"
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
name=$(git submodule--helper name "$sm_path")
|
||||
url=$(git config -f .gitmodules --get submodule."$name".url)
|
||||
|
||||
# Possibly a url relative to parent
|
||||
case "$url" in
|
||||
./*|../*)
|
||||
# rewrite foo/bar as ../.. to find path from
|
||||
# submodule work tree to superproject work tree
|
||||
up_path="$(printf '%s\n' "$sm_path" | sed "s/[^/][^/]*/../g")" &&
|
||||
# guarantee a trailing /
|
||||
up_path=${up_path%/}/ &&
|
||||
# path from submodule work tree to submodule origin repo
|
||||
sub_origin_url=$(git submodule--helper resolve-relative-url "$url" "$up_path") &&
|
||||
# path from superproject work tree to submodule origin repo
|
||||
super_config_url=$(git submodule--helper resolve-relative-url "$url") || exit
|
||||
;;
|
||||
*)
|
||||
sub_origin_url="$url"
|
||||
super_config_url="$url"
|
||||
;;
|
||||
esac
|
||||
|
||||
displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
|
||||
say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
|
||||
git config submodule."$name".url "$super_config_url"
|
||||
|
||||
if test -e "$sm_path"/.git
|
||||
then
|
||||
(
|
||||
sanitize_submodule_env
|
||||
cd "$sm_path"
|
||||
remote=$(get_default_remote)
|
||||
git config remote."$remote".url "$sub_origin_url"
|
||||
|
||||
if test -n "$recursive"
|
||||
then
|
||||
prefix="$prefix$sm_path/"
|
||||
eval cmd_sync
|
||||
fi
|
||||
)
|
||||
fi
|
||||
done
|
||||
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@"
|
||||
}
|
||||
|
||||
cmd_absorbgitdirs()
|
||||
|
Reference in New Issue
Block a user