summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorPrathamesh Chavan <pc44800@gmail.com>2018-02-02 10:27:45 +0530
committerJunio C Hamano <gitster@pobox.com>2018-02-02 12:47:53 -0800
commita21f21c1ebd8edb31b1e7b6383c1a536bebb8d0b (patch)
treefd9fb22dd0a90b1aa6680a091ba81e455f0cbafb /git-submodule.sh
parent79d1b062a52a2d3e12883b240111138c54abb3e4 (diff)
downloadgit-pc/submodule-helper-foreach.tar.gz
submodule: port submodule subcommand 'foreach' from shell to Cpc/submodule-helper-foreach
This aims to make git-submodule foreach a builtin. This is the very first step taken in this direction. Hence, 'foreach' is ported to submodule--helper, and submodule--helper is called from git-submodule.sh. The code is split up to have one function to obtain all the list of submodules. This function acts as the front-end of git-submodule foreach subcommand. It calls the function for_each_listed_submodule(), which basically loops through the list and calls function fn, which in this case is runcommand_in_submodule_cb(). This third function is a callback function that calls runcommand_in_submodule() with the appropriate parameters and then takes care of running the command in that submodule, and recursively performing the same when --recursive is flagged. The first function module_foreach first parses the options present in argv, and then with the help of module_list_compute(), generates the list of submodules present in the current working tree. The second function for_each_listed_submodule() traverses through the list, and calls function fn (which in case of submodule subcommand foreach is runcommand_in_submodule_cb()) is called for each entry. The third function runcommand_in_submodule_cb() calls the function runcommand_in_submodule() after passing appropraite parameters. The fourth function runcommand_in_submodule(), generates a submodule struct sub for $name, value and then later prepends name=sub->name; and other value assignment to the env argv_array structure of a child_process. Also the <command> of submodule-foreach is push to args argv_array structure and finally, using run_command the commands are executed using a shell. The fourth function also takes care of the recursive flag, by creating a separate child_process structure and prepending "--super-prefix displaypath", to the args argv_array structure. Other required arguments and the input <command> of submodule-foreach is also appended to this argv_array. Helped-by: Brandon Williams <bmwill@google.com> 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>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh39
1 files changed, 1 insertions, 38 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 7305ee25fe..7627e27c8c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -323,44 +323,7 @@ cmd_foreach()
shift
done
- toplevel=$(pwd)
-
- # dup stdin so that it can be restored when running the external
- # command in the subshell (and a recursive call to this function)
- exec 3<&0
-
- {
- git submodule--helper list --prefix "$wt_prefix" ||
- echo "#unmatched" $?
- } |
- while read -r mode sha1 stage sm_path
- do
- die_if_unmatched "$mode" "$sha1"
- if test -e "$sm_path"/.git
- then
- displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
- say "$(eval_gettext "Entering '\$displaypath'")"
- name=$(git submodule--helper name "$sm_path")
- (
- prefix="$prefix$sm_path/"
- sanitize_submodule_env
- cd "$sm_path" &&
- # we make $path available to scripts ...
- path=$sm_path &&
- if test $# -eq 1
- then
- eval "$1"
- else
- "$@"
- fi &&
- if test -n "$recursive"
- then
- cmd_foreach "--recursive" "$@"
- fi
- ) <&3 3<&- ||
- die "$(eval_gettext "Stopping at '\$displaypath'; script returned non-zero status.")"
- fi
- done
+ git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@"
}
#