submodule sync: skip work for inactive submodules

Sync does some work determining what URLs should be used for a submodule but then throws this work away if the submodule isn't active. Instead perform the activity check earlier and skip inactive submodule in order to avoid doing unnecessary work. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 16, 2017 at 15:29 UTC e7849a9677e9db6af81f568ae40ad2eddf5d3f0d
1 file changed +21 -17
git-submodule.sh
+21 -17
@@ -1090,6 +1090,13 @@ cmd_sync()
1090 do
1091 die_if_unmatched "$mode" "$sha1"
1092 name=$(git submodule--helper name "$sm_path")
1093 +
1094 + # skip inactive submodules
1095 + if ! git config "submodule.$name.url" >/dev/null 2>/dev/null
1096 + then
1097 + continue
1098 + fi
1099 +
1100 url=$(git config -f .gitmodules --get submodule."$name".url)
1101
1102 # Possibly a url relative to parent
@@ -1111,27 +1118,24 @@ cmd_sync()
1118 ;;
1119 esac
1120
1114 - if git config "submodule.$name.url" >/dev/null 2>/dev/null
1121 + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
1122 + say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
1123 + git config submodule."$name".url "$super_config_url"
1124 +
1125 + if test -e "$sm_path"/.git
1126 then
1116 - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
1117 - say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
1118 - git config submodule."$name".url "$super_config_url"
1127 + (
1128 + sanitize_submodule_env
1129 + cd "$sm_path"
1130 + remote=$(get_default_remote)
1131 + git config remote."$remote".url "$sub_origin_url"
1132
1120 - if test -e "$sm_path"/.git
1133 + if test -n "$recursive"
1134 then
1122 - (
1123 - sanitize_submodule_env
1124 - cd "$sm_path"
1125 - remote=$(get_default_remote)
1126 - git config remote."$remote".url "$sub_origin_url"
1127 -
1128 - if test -n "$recursive"
1129 - then
1130 - prefix="$prefix$sm_path/"
1131 - eval cmd_sync
1132 - fi
1133 - )
1135 + prefix="$prefix$sm_path/"
1136 + eval cmd_sync
1137 fi
1138 + )
1139 fi
1140 done
1141 }