@matheusbsbs / matheus-bagliano / commits / a7b3269c4b
Fork 0

git-submodule: replace duplicated code with a module_list function

Several call sites in git-submodule.sh used the same idiom for getting submodule information: git ls-files --stage -- "$@" | grep '^160000 ' This patch removes this duplication by introducing a module_list function. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Aug 22, 2008 at 00:30 UTC a7b3269c4b9acde052d75b6dc54c8f869b77eb44
1 file changed +13 -4
git-submodule.sh
+13 -4
@@ -53,6 +53,15 @@ resolve_relative_url ()
53 echo "$remoteurl/$url"
54 }
55
56 +#
57 +# Get submodule info for registered submodules
58 +# $@ = path to limit submodule list
59 +#
60 +module_list()
61 +{
62 + git ls-files --stage -- "$@" | grep '^160000 '
63 +}
64 +
65 #
66 # Map submodule path to submodule name
67 #
@@ -206,7 +215,7 @@ cmd_add()
215 #
216 cmd_foreach()
217 {
209 - git ls-files --stage | grep '^160000 ' |
218 + module_list |
219 while read mode sha1 stage path
220 do
221 if test -e "$path"/.git
@@ -246,7 +255,7 @@ cmd_init()
255 shift
256 done
257
249 - git ls-files --stage -- "$@" | grep '^160000 ' |
258 + module_list "$@" |
259 while read mode sha1 stage path
260 do
261 # Skip already registered paths
@@ -304,7 +313,7 @@ cmd_update()
313 esac
314 done
315
307 - git ls-files --stage -- "$@" | grep '^160000 ' |
316 + module_list "$@" |
317 while read mode sha1 stage path
318 do
319 name=$(module_name "$path") || exit
@@ -569,7 +578,7 @@ cmd_status()
578 shift
579 done
580
572 - git ls-files --stage -- "$@" | grep '^160000 ' |
581 + module_list "$@" |
582 while read mode sha1 stage path
583 do
584 name=$(module_name "$path") || exit