From 349a94b169357bd79102119d796ea557040b49e8 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Thu, 5 Mar 2026 11:02:59 +0100 Subject: [PATCH 1/2] sync-upstream: Remove "select" mode and simplify I believe it was introduced to cherry-pick upstream PRs, but that simply doesn't work. Assume upstream is two PRs A and B ahead, and A has been merged before B. Then trying to cherry-picking B by merging the state of upstream's master after the merge-B commit won't do what we expect. In particular, the merge result will *include A's changes* because A had already been merged in upstream's master when B was merged. (One could think that merging the PR branch of B instead works, but this will yield the same result if B was rebased on master before it was merged.) The proper way to cherry-pick B is to create a PR that cherry-picks all commits that had been included in B. This could be done automatically, but the need to cherry-pick a PR is rare enough that we don't need tool support for it. In fact, because we want to keep cherry-picking at a minimum, there's a good chance that we'd anyway want to pick only a subset of the commits in a upstream PR, and that would need manual work anyway. --- contrib/sync-upstream.sh | 45 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/contrib/sync-upstream.sh b/contrib/sync-upstream.sh index c1ad8e0a..a0495f60 100755 --- a/contrib/sync-upstream.sh +++ b/contrib/sync-upstream.sh @@ -6,14 +6,11 @@ help() { echo "Sync merge commits from bitcoin-core/secp256k1 into secp256k1-zkp." echo echo "Usage:" - echo " $0 [-b ] range [end]" + echo " $0 [-b ] [end]" echo " Merges every merge commit present in upstream/master and missing in " echo " (default: master). If the optional [end] commit is provided, only merges" echo " up to and including [end]." echo - echo " $0 [-b ] select ... " - echo " Merges every selected merge commit into (default: master)." - echo echo "This tool creates a temporary branch and attempts to merge the upstream commits." echo "If there are merge conflicts, resolve them and run tests, then use the generated" echo "script contrib/gh-pr-create.sh to create the PR (requires the gh tool)." @@ -26,7 +23,7 @@ help() { echo "Listing upstream merge commits:" echo " To list merge commits in upstream/master that are missing from (oldest first):" echo " git log --oneline --merges \$(git merge-base upstream/master )..upstream/master | tac" - echo " Use these for [end] in 'range' or as arguments to 'select'." + echo " These are candidates for [end]." exit 1 } @@ -67,14 +64,18 @@ range() { esac } -# Process -b argument -while getopts "b:" opt; do +# Process -b and -h arguments +while getopts "b:h" opt; do case $opt in b) LOCAL_BRANCH=$OPTARG ;; - \?) - echo "Invalid option: -$OPTARG" >&2 + h) + help + ;; + *) + echo + help ;; esac done @@ -82,31 +83,11 @@ done # Shift off the processed options shift $((OPTIND -1)) -if [ "$#" -lt 1 ]; then - help -fi - -case $1 in - range) - shift - setup - range "$@" - REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH range $RANGEEND_COMMIT" - ;; - select) - shift - setup - COMMITS=$* - REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH select $@" - ;; - help) - help - ;; - *) - help -esac +setup +range "$@" TITLE="Upstream PRs" +REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH $RANGEEND_COMMIT" BODY="" for COMMIT in $COMMITS do From 656c7cc70449a2116de4e3475bce21809ee4a3f1 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Thu, 5 Mar 2026 12:01:09 +0100 Subject: [PATCH 2/2] sync-upstream: Clarify that we merge a *single* upstream ref Roughly speaking, this changes (assuming 3 upstream PRs) git merge into git merge This is more intuitive. We're merging a single upstream revision, namely . The other two commits are simply parents of that one, i.e., they're included anyway, and git merge ignores them. (In fact, passing multiple refs looks like we're doing an octopus merge. It's just that git recognizes the fact that everything is included in the last ref anyway, and behaves as if only the last one had been passed.) This commit also makes some further clean ups and improvements. --- contrib/sync-upstream.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/sync-upstream.sh b/contrib/sync-upstream.sh index a0495f60..1cb285bb 100755 --- a/contrib/sync-upstream.sh +++ b/contrib/sync-upstream.sh @@ -22,7 +22,7 @@ help() { echo echo "Listing upstream merge commits:" echo " To list merge commits in upstream/master that are missing from (oldest first):" - echo " git log --oneline --merges \$(git merge-base upstream/master )..upstream/master | tac" + echo " git log --oneline --topo-order --reverse --merges \$(git merge-base upstream/master )..upstream/master" echo " These are candidates for [end]." exit 1 } @@ -53,15 +53,7 @@ range() { if [ "$#" = 1 ]; then RANGEEND_COMMIT=$1 fi - - COMMITS=$(git --no-pager log --oneline --merges "$RANGESTART_COMMIT".."$RANGEEND_COMMIT") - COMMITS=$(echo "$COMMITS" | tac | awk '{ print $1 }' ORS=' ') - echo "Merging $COMMITS. Continue with y" - read -r yn - case $yn in - [Yy]* ) ;; - * ) exit 1;; - esac + COMMITS=$(git --no-pager log --pretty=format:%H --topo-order --reverse --merges "$RANGESTART_COMMIT".."$RANGEEND_COMMIT") } # Process -b and -h arguments @@ -94,6 +86,7 @@ do PRNUM=$(git log -1 "$COMMIT" --pretty=format:%s | sed s/'Merge \(bitcoin-core\/secp256k1\)\?#\([0-9]*\).*'/'\2'/) TITLE="$TITLE $PRNUM," BODY=$(printf "%s\n%s" "$BODY" "$(git log -1 "$COMMIT" --pretty=format:%s | sed s/'Merge \(bitcoin-core\/secp256k1\)\?#\([0-9]*\)'/'[bitcoin-core\/secp256k1#\2]'/)") + LAST_COMMIT="$COMMIT" done # Remove trailing "," TITLE=${TITLE%?} @@ -109,6 +102,13 @@ Tips: EOF ) +echo "Merging $TITLE. Continue with y" +read -r yn +case $yn in + [Yy]* ) ;; + * ) exit 1;; +esac + echo "-----------------------------------" echo "$TITLE" echo "-----------------------------------" @@ -140,4 +140,4 @@ EOT chmod +x "$FNAME" echo Run "$FNAME" after solving the merge conflicts -git merge --no-edit -m "Merge commits '$COMMITS' into temp-merge-$PRNUM" $COMMITS +git merge --no-edit -m "Merge upstream '${LAST_COMMIT:0:7}' into temp-merge-$PRNUM" "$LAST_COMMIT"