[
https://issues.apache.org/jira/browse/CASSANDRA-18399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17710435#comment-17710435
]
Jacek Lewandowski commented on CASSANDRA-18399:
-----------------------------------------------
I think, I have finished.
There is one main entry script {{prepare_merge_commands.py}}. Just run in the
cassandra repo dir (making sure the worktree is clean, the script will fail
otherwise):
{noformat}
python3 ~/path-to-cassandra-builds/dev/scripts/prepare_merge_commands.py
../merge.script
{noformat}
The only argument is the script file to generate (use ../ so that the script is
not generated in the repo directory as it would make it dirty, appropriate
checks are included).
The script will guide you through all the steps, for example:
{noformat}
jlewandowski@deauville:~/dev/apache/cassandra$ python3
~/dev/cassandra-builds/CASSANDRA-18399/dev/scripts/prepare_merge_commands.py
Remote repositories:
JeetKunDoug
apache
jacek-lewandowski
jtgrabowski
origin
Enter the name of the remote repository that points to the upstream Apache
Cassandra [default: origin]:
[email protected]:apache/cassandra.git
Enter the name of the remote repository that points to the upstream feature
branch [default: origin]: jacek-lewandowski
[email protected]:jacek-lewandowski/cassandra.git
Enter the ticket number: 99999
Fetching from origin
Fetching from jacek-lewandowski
Found the following release branches:
1.0: cassandra-1.0
1.1: cassandra-1.1
1.2: cassandra-1.2
2.0: cassandra-2.0
2.1: cassandra-2.1
2.2: cassandra-2.2
3.0: cassandra-3.0
3.11: cassandra-3.11
4.0: cassandra-4.0
4.1: cassandra-4.1
trunk: trunk
.*refs/heads/(CASSANDRA\-99999((\d+)\.(\d+))?.*)$
Found the following feature branches:
4.0: CASSANDRA-99999-4.0
4.1: CASSANDRA-99999-4.1
trunk: CASSANDRA-99999
Enter the oldest release version to merge into [default: 4.0]:
Enter the name of the feature branch to merge into cassandra-4.0 or type 'none'
if there is no feature branch for this release [default: CASSANDRA-99999-4.0]:
Enter the name of the feature branch to merge into cassandra-4.1 or type 'none'
if there is no feature branch for this release [default: CASSANDRA-99999-4.1]:
Enter the name of the feature branch to merge into trunk or type 'none' if
there is no feature branch for this release [default: CASSANDRA-99999]:
Commits:
1: Commit(sha='bde2c79b82', author='Jacek Lewandowski', title='Updated
README.asc in a stupid way')
2: Commit(sha='045c27f4e8', author='Jacek Lewandowski', title='DO NOT MERGE')
Enter the number of the commit whose message should be used as a title in
CHANGES.txt or leave empty to enter a custom title: 1
Enter the filename to save the script to [default: merge_CASSANDRA-99999.sh]:
{noformat}
As you can see, when the branches are named properly, it will autosuggest the
right names, but you are still free to choose any branches.
It generates a script like the following one:
{noformat}
#!/bin/bash
set -xe
[[ -z $(git status --porcelain) ]] # worktree must be clean
# Commands for merging CASSANDRA-99999-4.0 -> cassandra-4.0
################################################################################
git switch cassandra-4.0
git reset --hard origin/cassandra-4.0
git cherry-pick bde2c79b82 # Jacek Lewandowski - Updated README.asc in a stupid
way
git cherry-pick -n 045c27f4e8 # Jacek Lewandowski - DO NOT MERGE
python3
/home/jlewandowski/dev/cassandra-builds/CASSANDRA-18399/dev/scripts/update_changes.py
'CASSANDRA-99999' '4.0' '' 'Updated README.asc in a stupid way'
git add CHANGES.txt
git commit --amend --no-edit
[[ -n "$(git diff origin/cassandra-4.0..HEAD -- .circleci/)" ]] && (git diff
origin/cassandra-4.0..HEAD -- .circleci/ | git apply -R --index) && git commit
-a --amend --no-edit # Remove all changes in .circleci directory if you need to
git diff --name-only origin/cassandra-4.0..HEAD # print a list of all changes
files
# Commands for merging CASSANDRA-99999-4.1 -> cassandra-4.1
################################################################################
git switch cassandra-4.1
git reset --hard origin/cassandra-4.1
git merge -s ours --log --no-edit cassandra-4.0
git cherry-pick -n 339f66a75e # Jacek Lewandowski - Updated README.asc in a
stupid way
git cherry-pick -n eb400940b6 # Jacek Lewandowski - DO NOT MERGE
python3
/home/jlewandowski/dev/cassandra-builds/CASSANDRA-18399/dev/scripts/update_changes.py
'CASSANDRA-99999' '4.1' '4.0' 'Updated README.asc in a stupid way'
git add CHANGES.txt
git commit --amend --no-edit
[[ -n "$(git diff origin/cassandra-4.1..HEAD -- .circleci/)" ]] && (git diff
origin/cassandra-4.1..HEAD -- .circleci/ | git apply -R --index) && git commit
-a --amend --no-edit # Remove all changes in .circleci directory if you need to
git diff --name-only origin/cassandra-4.1..HEAD # print a list of all changes
files
# Commands for merging CASSANDRA-99999 -> trunk
################################################################################
git switch trunk
git reset --hard origin/trunk
git merge -s ours --log --no-edit cassandra-4.1
git cherry-pick -n 9465b6f93b # Jacek Lewandowski - Updated README.asc in a
stupid way
python3
/home/jlewandowski/dev/cassandra-builds/CASSANDRA-18399/dev/scripts/update_changes.py
'CASSANDRA-99999' '4.1' '4.0' 'Updated README.asc in a stupid way'
git add CHANGES.txt
git commit --amend --no-edit
[[ -n "$(git diff --name-only origin/trunk..HEAD -- .circleci/)" ]] && (git
diff origin/trunk..HEAD -- .circleci/ | git apply -R --index) && git commit -a
--amend --no-edit # Remove all changes in .circleci directory if you need to
git diff --name-only origin/trunk..HEAD # print a list of all changes files
# After executing the above commands, please run the following verification,
and manually inspect the results of the commands it generates
python3
/home/jlewandowski/dev/cassandra-builds/CASSANDRA-18399/dev/scripts/verify_git_history.py
'origin' 'cassandra-4.0,cassandra-4.1,trunk'
{noformat}
If everything goes fine, the tail of the script output should be like this:
{noformat{
Checking branch cassandra-4.0
Expected merges: []
History:
- -Commit(sha='44b94124ae', author='Jacek Lewandowski', title='Updated
README.asc in a stupid way')
Checking branch cassandra-4.1
Expected merges: [('cassandra-4.0', 'cassandra-4.1')]
History:
- Commit(sha='44b94124ae', author='Jacek Lewandowski', title='Updated
README.asc in a stupid way')
- Commit(sha='01cf31a809', author='Jacek Lewandowski', title="Merge branch
'cassandra-4.0' into cassandra-4.1")
Checking branch trunk
Expected merges: [('cassandra-4.0', 'cassandra-4.1'), ('cassandra-4.1',
'trunk')]
History:
- Commit(sha='44b94124ae', author='Jacek Lewandowski', title='Updated
README.asc in a stupid way')
- Commit(sha='01cf31a809', author='Jacek Lewandowski', title="Merge branch
'cassandra-4.0' into cassandra-4.1")
- Commit(sha='78b888f7c4', author='Jacek Lewandowski', title="Merge branch
'cassandra-4.1' into trunk")
--------------------------------------------------------------------------------
Push range for branch cassandra-4.0: 7d84ad9366..44b94124ae
git diff --name-only 7d84ad9366..44b94124ae
git show 7d84ad9366..44b94124ae
--------------------------------------------------------------------------------
Push range for branch cassandra-4.1: edb34e2f62..01cf31a809
git diff --name-only edb34e2f62..01cf31a809
git show edb34e2f62..01cf31a809
--------------------------------------------------------------------------------
Push range for branch trunk: ca6450bda4..78b888f7c4
git diff --name-only ca6450bda4..78b888f7c4
git show ca6450bda4..78b888f7c4
{noformat}
Which is the result of verification. In particular, it verifies whether commits
for a newer branch includes all the commits for the older branch + one merge
commit. Eventually, it executes dry run of {{git push --atomic -n ...}}, parse
the results and generates {{git diff}} / {{git show}} commands for manual
inspection before pushing for real. That verification is done by additional
tool {{verify_git_history.py}}, whose execution is a part of the generated
script.
After running the script, you should have all relevant local {{cassandra-x.y}}
+ {{trunk}} branches updated and ready to push.
Note, there is also another separate tool {{update_changes.py}} which is solely
used to edit CHANGES.txt in a consistent way. Its execution is also included in
the generated script.
> Add simple helper script for commiting a change to multiple branches
> --------------------------------------------------------------------
>
> Key: CASSANDRA-18399
> URL: https://issues.apache.org/jira/browse/CASSANDRA-18399
> Project: Cassandra
> Issue Type: Task
> Components: Build
> Reporter: Jacek Lewandowski
> Assignee: Jacek Lewandowski
> Priority: Low
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> This is just a simple additional script which committers can use to help them
> merge commits, especially if the change applies to multiple Cassandra
> versions.
> For example, for CASSANDRA-18153, which applies to 3.0..trunk, it generates
> the following commands, which then can be run manually:
> {noformat}
> git fetch origin
> git fetch jacek-lewandowski
> # jacek-lewandowski/CASSANDRA-18153-3.0 -> cassandra-3.0
> #
> --------------------------------------------------------------------------------------------------------
> git switch cassandra-3.0
> git reset --hard origin/cassandra-3.0
> git cherry-pick e7e9b42559 # e7e9b42559 Save host id to system.local and
> flush immediately after startup
> git cherry-pick -n 99e96a4f95 && git commit -a --amend --no-edit # 99e96a4f95
> fixes
> git cherry-pick -n c63e3f29f1 && git commit -a --amend --no-edit # c63e3f29f1
> DO NOT MERGE - CircleCI config
> grep 'CASSANDRA-18153' CHANGES.txt || sed -E -i '/^[0-9]+\.[0-9]+/{s/.*/&\n\
> * Save host id to system.local and flush immediately after startup
> (CASSANDRA-18153)/;:a;n;ba}' CHANGES.txt
> git diff CHANGES.txt
> git add CHANGES.txt
> git commit --amend --no-edit
> (git diff origin/cassandra-3.0..HEAD -- .circleci/ | git apply -R --index) &&
> git commit -a --amend --no-edit # Remove all changes in .circleci directory
> if you need to
> git diff --name-only origin/cassandra-3.0..HEAD # print a list of all changes
> files
> # jacek-lewandowski/CASSANDRA-18153-3.11 -> cassandra-3.11
> #
> --------------------------------------------------------------------------------------------------------
> git switch cassandra-3.11
> git reset --hard origin/cassandra-3.11
> git merge -s ours --log --no-edit cassandra-3.0
> git cherry-pick -n 79e7b90c8f && git commit -a --amend --no-edit # 79e7b90c8f
> Save host id to system.local and flush immediately after startup
> git cherry-pick -n bdca4c384b && git commit -a --amend --no-edit # bdca4c384b
> fixes
> git cherry-pick -n 45078e6793 && git commit -a --amend --no-edit # 45078e6793
> DO NOT MERGE - CircleCI config
> grep 'CASSANDRA-18153' CHANGES.txt || sed -E -i '/^Merged from 3.0/{s/.*/&\n\
> * Save host id to system.local and flush immediately after startup
> (CASSANDRA-18153)/;:a;n;ba}' CHANGES.txt
> git diff CHANGES.txt
> git add CHANGES.txt
> git commit --amend --no-edit
> (git diff origin/cassandra-3.11..HEAD -- .circleci/ | git apply -R --index)
> && git commit -a --amend --no-edit # Remove all changes in .circleci
> directory if you need to
> git diff --name-only origin/cassandra-3.11..HEAD # print a list of all
> changes files
> # jacek-lewandowski/CASSANDRA-18153-4.0 -> cassandra-4.0
> #
> --------------------------------------------------------------------------------------------------------
> git switch cassandra-4.0
> git reset --hard origin/cassandra-4.0
> git merge -s ours --log --no-edit cassandra-3.11
> git cherry-pick -n 2227c5c7af && git commit -a --amend --no-edit # 2227c5c7af
> Save host id to system.local and flush immediately after startup
> git cherry-pick -n a71d4e3408 && git commit -a --amend --no-edit # a71d4e3408
> DO NOT MERGE - CircleCI config
> git cherry-pick -n 6dc53f4e97 && git commit -a --amend --no-edit # 6dc53f4e97
> fixes
> grep 'CASSANDRA-18153' CHANGES.txt || sed -E -i '/^Merged from 3.0/{s/.*/&\n\
> * Save host id to system.local and flush immediately after startup
> (CASSANDRA-18153)/;:a;n;ba}' CHANGES.txt
> git diff CHANGES.txt
> git add CHANGES.txt
> git commit --amend --no-edit
> (git diff origin/cassandra-4.0..HEAD -- .circleci/ | git apply -R --index) &&
> git commit -a --amend --no-edit # Remove all changes in .circleci directory
> if you need to
> git diff --name-only origin/cassandra-4.0..HEAD # print a list of all changes
> files
> # jacek-lewandowski/CASSANDRA-18153-4.1 -> cassandra-4.1
> #
> --------------------------------------------------------------------------------------------------------
> git switch cassandra-4.1
> git reset --hard origin/cassandra-4.1
> git merge -s ours --log --no-edit cassandra-4.0
> git cherry-pick -n 3584d17b36 && git commit -a --amend --no-edit # 3584d17b36
> Save host id to system.local and flush immediately after startup
> git cherry-pick -n e7b2ca37e6 && git commit -a --amend --no-edit # e7b2ca37e6
> DO NOT MERGE - CircleCI config
> git cherry-pick -n 85f3049e90 && git commit -a --amend --no-edit # 85f3049e90
> fixes
> grep 'CASSANDRA-18153' CHANGES.txt || sed -E -i '/^Merged from 3.0/{s/.*/&\n\
> * Save host id to system.local and flush immediately after startup
> (CASSANDRA-18153)/;:a;n;ba}' CHANGES.txt
> git diff CHANGES.txt
> git add CHANGES.txt
> git commit --amend --no-edit
> (git diff origin/cassandra-4.1..HEAD -- .circleci/ | git apply -R --index) &&
> git commit -a --amend --no-edit # Remove all changes in .circleci directory
> if you need to
> git diff --name-only origin/cassandra-4.1..HEAD # print a list of all changes
> files
> # jacek-lewandowski/CASSANDRA-18153 -> trunk
> #
> --------------------------------------------------------------------------------------------------------
> git switch trunk
> git reset --hard origin/trunk
> git merge -s ours --log --no-edit cassandra-4.1
> git cherry-pick -n 3b9fa1653e && git commit -a --amend --no-edit # 3b9fa1653e
> DO NOT MERGE - CircleCI config
> git cherry-pick -n e1389f6196 && git commit -a --amend --no-edit # e1389f6196
> Save host id to system.local and flush immediately after startup
> grep 'CASSANDRA-18153' CHANGES.txt || sed -E -i '/^Merged from 3.0/{s/.*/&\n\
> * Save host id to system.local and flush immediately after startup
> (CASSANDRA-18153)/;:a;n;ba}' CHANGES.txt
> git diff CHANGES.txt
> git add CHANGES.txt
> git commit --amend --no-edit
> (git diff origin/trunk..HEAD -- .circleci/ | git apply -R --index) && git
> commit -a --amend --no-edit # Remove all changes in .circleci directory if
> you need to
> git diff --name-only origin/trunk..HEAD # print a list of all changes files
> git push --atomic origin cassandra-3.0 cassandra-3.11 cassandra-4.0
> cassandra-4.1 trunk -n
> {noformat}
> The generated script takes into account the following:
> - a change can span multiple commits - all of the will be properly squashed
> (when running a script, you can comment out the commits you don't want to
> include)
> - when commits leave .circleci directory modified, one of the last commands
> for each branch reverts those changes
> - the script does its best to update CHANGED.txt properly, to confirm, it
> always displays the diff for CHANGES.txt
> Note that, the script does not push anything, it just generates the script to
> be manually run by the committer.
> I'll appreciate if someone can run it on Mac so we know if there are some
> fixes needed for MacOS.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]