From 28bf772844f71d0fbde7ebf9aa6f9e7206867a78 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 29 Sep 2021 14:50:45 -0400 Subject: [PATCH] ENH: Update to newer third-party update script Update to `update-common.sh` from commit `7134d5ebef` in https://gitlab.kitware.com/utils/git-import-third-party Manually preserve ITK's change from commit 5dccc2207e (BUG: Do not gpg sign third party updates, 2018-11-19, v5.0b02~82^2~1). --- Utilities/Maintenance/update-third-party.bash | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Utilities/Maintenance/update-third-party.bash b/Utilities/Maintenance/update-third-party.bash index 46bb599bde4..02182bc016a 100644 --- a/Utilities/Maintenance/update-third-party.bash +++ b/Utilities/Maintenance/update-third-party.bash @@ -42,6 +42,22 @@ # For convenience, the function may use the "git_archive" function which # does a standard "git archive" extraction using the (optional) "paths" # variable to only extract a subset of the source tree. +# +# Dependencies +# +# To update third party packages from git repositories with submodule, +# you will need to install the "git-archive-all" Python package with +# +# pip install git-archive-all +# +# or install it from https://github.com/Kentzo/git-archive-all. +# +# This package installs a script named "git-archive-all" where pip +# installs executables. If you run pip under your user privileges (i.e., +# not using "sudo"), this location may be $HOME/.local/bin. Make sure +# that directory is in your path so that git can find the +# "git-archive-all" script. +# ######################################################################## ######################################################################## @@ -52,11 +68,24 @@ git_archive () { tar -C "$extractdir" -x } +confirm_archive_all_exists () { + which git-archive-all || die "git requires an archive-all command. Please run 'pip install git-archive-all'" +} + +git_archive_all () { + confirm_archive_all_exists + local tmptarball="temp.tar" + git archive-all --prefix="" "$tmptarball" + mkdir -p "$extractdir/$name-reduced" + tar -C "$extractdir/$name-reduced" -xf "$tmptarball" $paths + rm -f "$tmptarball" +} + disable_custom_gitattributes() { pushd "${extractdir}/${name}-reduced" # Git does not allow custom attributes in a subdirectory where we # are about to merge the `.gitattributes` file, so disable them. - sed -i '/^\[attr\]/ {s/^/#/}' .gitattributes + sed -i '/^\[attr\]/ {s/^/#/;}' .gitattributes popd } @@ -71,6 +100,9 @@ warn () { readonly regex_date='20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]' readonly basehash_regex="$name $regex_date ([0-9a-f]*)" +readonly toplevel_dir="$( git rev-parse --show-toplevel )" + +cd "$toplevel_dir" ######################################################################## # Sanity checking @@ -89,13 +121,13 @@ readonly basehash_regex="$name $regex_date ([0-9a-f]*)" # Check for an empty destination directory on disk. By checking on disk and # not in the repo it allows a library to be freshly re-inialized in a single # commit rather than first deleting the old copy in one commit and adding the -# new copy in a seperate commit. +# new copy in a separate commit. if [ ! -d "$(git rev-parse --show-toplevel)/$subtree" ]; then readonly basehash="" else readonly basehash="$( git rev-list --author="$ownership" --grep="$basehash_regex" -n 1 HEAD )" fi -readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$basehash_regex"'/ {s/.*(//;s/)//;p}' | egrep '^[0-9a-f]+$' )" +readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$basehash_regex"'/ {s/.*(//;s/)//;p;}' | egrep '^[0-9a-f]+$' )" [ -n "$basehash" ] || \ warn "'basehash' is empty; performing initial import" @@ -111,7 +143,7 @@ readonly extractdir="$workdir/extract" trap "rm -rf '$workdir'" EXIT # Get upstream -git clone "$repo" "$upstreamdir" +git clone --recursive "$repo" "$upstreamdir" if [ -n "$basehash" ]; then # Remove old worktrees @@ -120,7 +152,7 @@ if [ -n "$basehash" ]; then git worktree add "$extractdir" "$basehash" # Clear out the working tree pushd "$extractdir" - git ls-files | xargs rm -v + git ls-files -z --recurse-submodules | xargs -0 rm -v find . -type d -empty -delete popd else @@ -132,6 +164,8 @@ fi # Extract the subset of upstream we care about pushd "$upstreamdir" git checkout "$tag" +git submodule sync --recursive +git submodule update --recursive --init readonly upstream_hash="$( git rev-parse HEAD )" readonly upstream_hash_short="$( git rev-parse --short=8 "$upstream_hash" )" readonly upstream_datetime="$( git rev-list "$upstream_hash" --format='%ci' -n 1 | grep -e "^$regex_date" )"