submodule: port init from shell to C
[gitweb.git] / git-submodule.sh
index 2423d7c3ef34b936eb01b63f79bbe0ffedf000c8..82e95a923bd94f1da578f56e909da59594259170 100755 (executable)
@@ -394,50 +394,7 @@ cmd_init()
                shift
        done
 
-       git submodule--helper list --prefix "$wt_prefix" "$@" |
-       while read mode sha1 stage sm_path
-       do
-               die_if_unmatched "$mode"
-               name=$(git submodule--helper name "$sm_path") || exit
-
-               displaypath=$(relative_path "$prefix$sm_path")
-
-               # Copy url setting when it is not set yet
-               if test -z "$(git config "submodule.$name.url")"
-               then
-                       url=$(git config -f .gitmodules submodule."$name".url)
-                       test -z "$url" &&
-                       die "$(eval_gettext "No url found for submodule path '\$displaypath' in .gitmodules")"
-
-                       # Possibly a url relative to parent
-                       case "$url" in
-                       ./*|../*)
-                               url=$(git submodule--helper resolve-relative-url "$url") || exit
-                               ;;
-                       esac
-                       git config submodule."$name".url "$url" ||
-                       die "$(eval_gettext "Failed to register url for submodule path '\$displaypath'")"
-
-                       say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$displaypath'")"
-               fi
-
-               # Copy "update" setting when it is not set yet
-               if upd="$(git config -f .gitmodules submodule."$name".update)" &&
-                  test -n "$upd" &&
-                  test -z "$(git config submodule."$name".update)"
-               then
-                       case "$upd" in
-                       checkout | rebase | merge | none)
-                               ;; # known modes of updating
-                       *)
-                               echo >&2 "warning: unknown update mode '$upd' suggested for submodule '$name'"
-                               upd=none
-                               ;;
-                       esac
-                       git config submodule."$name".update "$upd" ||
-                       die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
-               fi
-       done
+       git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} "$@"
 }
 
 #
@@ -740,7 +697,8 @@ cmd_update()
                if test -n "$recursive"
                then
                        (
-                               prefix="$prefix$sm_path/"
+                               prefix=$(relative_path "$prefix$sm_path/")
+                               wt_prefix=
                                clear_local_git_env
                                cd "$sm_path" &&
                                eval cmd_update