From 8497104088da602013fadebc252b707be749352e Mon Sep 17 00:00:00 2001 From: Rogdham Date: Sat, 6 Dec 2025 16:54:23 +0100 Subject: [PATCH] chore: add CPython sync script --- sync/.gitignore | 2 + sync/cpython.sh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 sync/.gitignore create mode 100755 sync/cpython.sh diff --git a/sync/.gitignore b/sync/.gitignore new file mode 100644 index 0000000..c018014 --- /dev/null +++ b/sync/.gitignore @@ -0,0 +1,2 @@ +/.env +/cpython diff --git a/sync/cpython.sh b/sync/cpython.sh new file mode 100755 index 0000000..729ed6e --- /dev/null +++ b/sync/cpython.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +set -Exeuo pipefail + +# +# Usage +# +# if code is based on 3.14.0 and want to change to 3.14.1: +# $0 v3.14.0 v3.14.1 +# if you just want to compute the diffs with an upstream version: +# $0 v3.14.0 v3.14.0 +# note that both args are any valid git revision, but tags work fine +# + +cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." + +# load CPYTHON_CLONE_PATH +set -a +source sync/.env +set +a + +# make sure local git repo is clean +test -z "$(git status --porcelain | tee /dev/stderr)" + +# fetch CPython tags +src_rev="$1" +dst_rev="$2" +git -C "$CPYTHON_CLONE_PATH" fetch +git -C "$CPYTHON_CLONE_PATH" show --no-patch "$src_rev" +git -C "$CPYTHON_CLONE_PATH" show --no-patch "$dst_rev" + +# cleanup +patch_dir="sync/cpython" +rm -rf "$patch_dir" +find . -name '*.orig' -delete +find . -name '*.rej' -delete + +# perform the diff & patch +set +x +while read -r src_path dst_path; do + echo ">>>> $src_path" + mkdir -p "$patch_dir/$(dirname "$dst_path")" + patch_file="$patch_dir/$dst_path.patch" + git -C "$CPYTHON_CLONE_PATH" show "$src_rev:$src_path" >"$dst_path" + git diff -R --output="$patch_file" "$dst_path" + git -C "$CPYTHON_CLONE_PATH" show "$dst_rev:$src_path" >"$dst_path" + if [ -s "$patch_file" ]; then + patch -i "$patch_file" -p 1 || true + else + rm "$patch_file" + fi +done <>> Rejected patches" +find . -name '*.rej' + +echo ">>> Also check shutil diffs manually" +git -C "$CPYTHON_CLONE_PATH" diff "$src_rev...$dst_rev" "Lib/shutil.py" + +echo ">>> Script finished, but diffs needs to be reviewed manually"