Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
leleliu008 committed Jul 16, 2024
1 parent ea32488 commit a75d7dc
Showing 1 changed file with 71 additions and 19 deletions.
90 changes: 71 additions & 19 deletions xcpkg
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,74 @@ sedInPlace() {
fi
}

git_submodule_update_recursive() {
if [ -z "$1" ] ; then
GIT_REPO_ROOT_DIR="$PWD"
else
GIT_REPO_ROOT_DIR="$1"
fi

GIT_SUBMODULE_HAVE="$(cd "$GIT_REPO_ROOT_DIR" && find . -type f -name '.gitmodules' -print -quit)"

if [ -n "$GIT_SUBMODULE_HAVE" ] ; then
if [ -z "$XCPKG_URL_TRANSFORM" ] ; then
run git submodule update --init --recursive
else
unset GIT_SUBMODULE_BASEDIR_STACK

GIT_SUBMODULE_CONFIG_FILE_LIST="$(find "$GIT_REPO_ROOT_DIR" -type f -name '.gitmodules')"

for f in $GIT_SUBMODULE_CONFIG_FILE_LIST
do
if [ -z "$GIT_SUBMODULE_BASEDIR_STACK" ] ; then
GIT_SUBMODULE_BASEDIR_STACK="${f%/*}"
else
GIT_SUBMODULE_BASEDIR_STACK="$GIT_SUBMODULE_BASEDIR_STACK;${f%/*}"
fi
done

while [ -n "$GIT_SUBMODULE_BASEDIR_STACK" ]
do
case $GIT_SUBMODULE_BASEDIR_STACK in
*\;*) GIT_SUBMODULE_BASEDIR="${GIT_SUBMODULE_BASEDIR_STACK##*;}" ; GIT_SUBMODULE_BASEDIR_STACK="${GIT_SUBMODULE_BASEDIR_STACK%;*}" ;;
*) GIT_SUBMODULE_BASEDIR="${GIT_SUBMODULE_BASEDIR_STACK}" ; GIT_SUBMODULE_BASEDIR_STACK=
esac

run cd "$GIT_SUBMODULE_BASEDIR"

GIT_SUBMODULE_NAME_LIST="$(sed -n '/\[submodule ".*"\]/p' .gitmodules | sed 's|\[submodule "\(.*\)"\]|\1|')"

for GIT_SUBMODULE_NAME in $GIT_SUBMODULE_NAME_LIST
do
GIT_SUBMODULE_PATH="$(git config --file=.gitmodules --get "submodule.$GIT_SUBMODULE_NAME.path")"
GIT_SUBMODULE_URL="$(git config --file=.gitmodules --get "submodule.$GIT_SUBMODULE_NAME.url")"
GIT_SUBMODULE_URI="$("$XCPKG_URL_TRANSFORM" "$GIT_SUBMODULE_URL")"

run git submodule set-url "$GIT_SUBMODULE_PATH" "$GIT_SUBMODULE_URI"
done

run git submodule update --init

GIT_SUBMODULE_PATH_LIST="$(git submodule | sed 's|^ *||' | cut -d ' ' -f2)"

for GIT_SUBMODULE_PATH in $GIT_SUBMODULE_PATH_LIST
do
GIT_SUBMODULE_CONFIG_FILE_LIST="$(find "$GIT_SUBMODULE_PATH" -type f -name '.gitmodules')"

for f in $GIT_SUBMODULE_CONFIG_FILE_LIST
do
if [ -z "$GIT_SUBMODULE_BASEDIR_STACK" ] ; then
GIT_SUBMODULE_BASEDIR_STACK="$GIT_SUBMODULE_BASEDIR/${f%/*}"
else
GIT_SUBMODULE_BASEDIR_STACK="$GIT_SUBMODULE_BASEDIR_STACK;$GIT_SUBMODULE_BASEDIR/${f%/*}"
fi
done
done
done
fi
fi
}

# check if the given two version match the condition
#
# condition:
Expand Down Expand Up @@ -2663,7 +2731,8 @@ __fetch_resources_of_the_given_package() {
run git remote add origin "$GIT_FETCH_URL"
run git -c protocol.version=2 fetch --progress $GIT_FETCH_EXTRA_OPTIONS origin "$GIT_REF_SPEC"
run git checkout --progress --force -B "$GIT_BRANCH_NAME" "refs/remotes/origin/$GIT_BRANCH_NAME"
run git submodule update --init

git_submodule_update_recursive

rm -rf "$SESSION_DIR"
fi
Expand Down Expand Up @@ -3778,24 +3847,7 @@ $DOT_CONTENT
run git -c protocol.version=2 fetch --progress $GIT_FETCH_EXTRA_OPTIONS origin "$GIT_REF_SPEC"
run git checkout --progress --force -B "$GIT_BRANCH_NAME" "refs/remotes/origin/$GIT_BRANCH_NAME"

GIT_SUBMODULE_PATH_LIST="$(find . -name .gitmodules)"

if [ -n "$GIT_SUBMODULE_PATH_LIST" ] ; then
if [ -n "$XCPKG_URL_TRANSFORM" ] ; then
for GIT_SUBMODULE_PATH in $GIT_SUBMODULE_PATH_LIST
do
GIT_SUBMODULE_URLS="$(grep 'url = ' "$GIT_SUBMODULE_PATH" | sed 's|[[:space:]]||g' | cut -c5-)"

for GIT_SUBMODULE_URL in $GIT_SUBMODULE_URLS
do
GIT_SUBMODULE_URI="$("$XCPKG_URL_TRANSFORM" "$GIT_SUBMODULE_URL")"
sedInPlace "s|$GIT_SUBMODULE_URL|$GIT_SUBMODULE_URI|" "$GIT_SUBMODULE_PATH"
done
done
fi

run git submodule update --init
fi
git_submodule_update_recursive
fi
;;
dir://*)
Expand Down

0 comments on commit a75d7dc

Please sign in to comment.