Add a patch backport script

This commit is contained in:
Ivan Pozdeev 2026-09-17 04:47:05 +03:00
parent 2548d53706
commit 733afbc04b

View File

@ -0,0 +1,27 @@
# source this in Bash
# cd to git repo of CPython
_python_build_dir=$(cd "${BASH_SOURCE%/*}/.."; pwd -P)
backport() {
[[ $# -lt 2 ]] && { echo "usage: $FUNCNAME <commit_hash> <CPython version>..." >&2; return 1; }
(set -euxo pipefail
sha="${1:?}"
shift
for b; do
git checkout "Branch_v$b" || git checkout -b "Branch_v$b" "v$b"
git cherry-pick "$sha"
git format-patch -1
patch_dir="$_python_build_dir/share/python-build/$b/Python-$b"
shopt -s nullglob
pp=("$patch_dir"/*.patch)
patch_offset=${#pp[@]}
shopt -u nullglob
unset pp
mkdir -p "$patch_dir"
for f in *.patch; do
mv "$f" "$patch_dir/$(printf '%04d' $((${f::4}+patch_offset)))${f:4}"
done
done)
}