Skip to content

Commit

Permalink
ENH: Update to newer third-party update script
Browse files Browse the repository at this point in the history
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 5dccc22 (BUG: Do not gpg
sign third party updates, 2018-11-19, v5.0b02~82^2~1).
  • Loading branch information
bradking committed Sep 29, 2021
1 parent f37e2cb commit 28bf772
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions Utilities/Maintenance/update-third-party.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
########################################################################

########################################################################
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" )"
Expand Down

0 comments on commit 28bf772

Please sign in to comment.