Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 24 additions & 43 deletions contrib/sync-upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ help() {
echo "Sync merge commits from bitcoin-core/secp256k1 into secp256k1-zkp."
echo
echo "Usage:"
echo " $0 [-b <branch>] range [end]"
echo " $0 [-b <branch>] [end]"
echo " Merges every merge commit present in upstream/master and missing in <branch>"
echo " (default: master). If the optional [end] commit is provided, only merges"
echo " up to and including [end]."
echo
echo " $0 [-b <branch>] select <commit> ... <commit>"
echo " Merges every selected merge commit into <branch> (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)."
Expand All @@ -25,8 +22,8 @@ help() {
echo
echo "Listing upstream merge commits:"
echo " To list merge commits in upstream/master that are missing from <branch> (oldest first):"
echo " git log --oneline --merges \$(git merge-base upstream/master <branch>)..upstream/master | tac"
echo " Use these for [end] in 'range' or as arguments to 'select'."
echo " git log --oneline --topo-order --reverse --merges \$(git merge-base upstream/master <branch>)..upstream/master"
echo " These are candidates for [end]."
exit 1
}

Expand Down Expand Up @@ -56,63 +53,40 @@ 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 <branch> argument
while getopts "b:" opt; do
# Process -b <branch> 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

# 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
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%?}
Expand All @@ -128,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 "-----------------------------------"
Expand Down Expand Up @@ -159,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"
Loading