Skip to content

sync-upstream: Overhaul#341

Merged
real-or-random merged 2 commits intoBlockstreamResearch:masterfrom
real-or-random:202603-sync-script
Mar 5, 2026
Merged

sync-upstream: Overhaul#341
real-or-random merged 2 commits intoBlockstreamResearch:masterfrom
real-or-random:202603-sync-script

Conversation

@real-or-random
Copy link
Copy Markdown
Member

Please see individual commit messages for details.


Here's an example session that shows why select doesn't make sense:

### Let's find some PRs to sync (master is at 5a67b63)

❯ ./contrib/sync-upstream.sh -b master range
Merging b9cb1cbf 1aafe151 . Continue with y
n

### Let's look at them in the order they have been merged

❯ git show b9cb1cbf
commit b9cb1cbfd72c9391c337ed1e30d71355dde65248
Merge: c0a2aba0 921b9711
Author: merge-script <me@real-or-random.org>
Date:   Tue Mar 3 15:31:46 2026 +0100

    Merge bitcoin-core/secp256k1#1824: util: introduce and use `ARRAY_SIZE` macro

[...]

❯ git --no-pager show 1aafe151 

commit 1aafe15139976b0142d791aaf4963de3fc1ff736 (upstream/master, upstream/HEAD)
Merge: b9cb1cbf 4d92a083
Author: merge-script <me@real-or-random.org>
Date:   Wed Mar 4 08:43:07 2026 +0100

    Merge bitcoin-core/secp256k1#1777: Make SHA256 compression runtime pluggable

[...]
    
### Let's assume I want to cherry-pick 1aafe151 but not sync b9cb1bcf 

❯ ./contrib/sync-upstream.sh -b master select 1aafe151
-----------------------------------
Upstream PRs 1777
-----------------------------------

[bitcoin-core/secp256k1#1777]: Make SHA256 compression runtime pluggable

This PR can be recreated with `./contrib/sync-upstream.sh -b master select 1aafe151`.

[...]

### Let's check if it's really only PR #1777

❯ git diff | grep ARRAY_SIZE
+ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

### Ah damn, we also got the other PR #1824...

@real-or-random
Copy link
Copy Markdown
Member Author

@jonasnick Can you take a look? I think you wrote the initial version of the script including the select option.

Comment thread contrib/sync-upstream.sh Outdated
range "$@"

TITLE="Upstream PRs"
REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH range $RANGEEND_COMMIT"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range should be removed here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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.
Roughly speaking, this changes (assuming 3 upstream PRs)

  git merge <upstream-commit1> <upstream-commit-2> <upstream-commit3>

into

  git merge <upstream-commit3>

This is more intuitive. We're merging a single upstream revision, namely
<upstream-commit3>. 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.
@mllwchrry
Copy link
Copy Markdown
Collaborator

ACK 656c7cc

Copy link
Copy Markdown
Contributor

@jonasnick jonasnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 656c7cc

Thanks for fixing this!

@real-or-random real-or-random merged commit e363adc into BlockstreamResearch:master Mar 5, 2026
106 of 122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants