[PATCH 2/7] git-submodule: Extract functions module_info and module_url
From: Ping Yin <hidden>
Date: 2016-06-15 22:44:22
Subsystem:
the rest · Maintainer:
Linus Torvalds
module_info is extracted to remove the logic redundance which acquires module names and urls by path filter in several places. module_url is also extracted to prepare for an alternative logic to get url by module name. Signed-off-by: Ping Yin <redacted> --- git-submodule.sh | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 2f40620..7545d1a 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh@@ -82,6 +82,25 @@ module_name() echo "$name" } +module_url() { + git config submodule.$1.url +} + +module_info() { + git ls-files --stage -- "$@" | grep -e '^160000 ' | + while read mode sha1 stage path + do + name=$(module_name "$path") + if test -n "$name" + then + url=$(module_url "$name") + echo "$sha1 $path $name $url" + else + echo "$sha1 $path " + fi + done +} + # # Clone a submodule #
@@ -232,12 +251,11 @@ cmd_init() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do + test -n "$name" || exit # Skip already registered paths - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) test -z "$url" || continue url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url)
@@ -286,11 +304,10 @@ cmd_update() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" then # Only mention uninitialized submodules when its
@@ -537,11 +554,10 @@ cmd_status() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" || ! test -d "$path"/.git then say "-$sha1 $path"
--
1.5.4.4.653.g7cf1e