aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Farrell <jamesfarrell@google.com>2023-08-17 20:37:51 +0000
committerJames Farrell <jamesfarrell@google.com>2023-08-17 21:07:11 +0000
commit98e326f9d7eb219c63de26553d2ee616380bca25 (patch)
tree1f818e73c98aa439954e3998fd266076775d2783
parent7725ed4b1c3951951cd9b0022d2a3b8599ff8f49 (diff)
downloadcpython3-98e326f9d7eb219c63de26553d2ee616380bca25.tar.gz
Script to update to a new major version.
Bug: 278602456 Change-Id: I17d4249bddddbf4340c710e158dd852e641111fc
-rwxr-xr-xandroid/update-major-version.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/android/update-major-version.sh b/android/update-major-version.sh
new file mode 100755
index 0000000000..4a11469f6c
--- /dev/null
+++ b/android/update-major-version.sh
@@ -0,0 +1,57 @@
+#!/bin/bash -ex
+#
+# Copyright 2023 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Update between branches, to a new major version.
+
+cd `dirname ${BASH_SOURCE[0]}`/..
+
+if [ -z ${1+x} ]; then
+ echo "Usage: update-major-version.sh <upstream tag>"
+ exit 1
+fi
+NEW_VERSION=$1
+NEW_VERSION_SHORT=${NEW_VERSION#upstream-}
+CURRENT_VERSION=upstream-$(grep 'version:' METADATA | grep -E -o 'v[0-9][^"]+')
+CURRENT_HEAD=$(git rev-parse HEAD)
+echo "Updating from $CURRENT_VERSION to $NEW_VERSION"
+
+ADDED_FILES=$(git diff --name-only --diff-filter=A $CURRENT_VERSION HEAD | sort)
+CHANGED_FILES=$(git diff --name-only --diff-filter=a $CURRENT_VERSION HEAD | sort)
+
+PATCHFILE=$(mktemp --suffix=.patch)
+trap "rm -f $PATCHFILE" EXIT
+
+git diff --patch $CURRENT_VERSION HEAD -- $CHANGED_FILES > $PATCHFILE
+
+git merge --no-commit -s ours $NEW_VERSION
+git restore --staged --worktree --source=$NEW_VERSION -- .
+git restore --staged --worktree --source=$CURRENT_HEAD -- $ADDED_FILES
+patch -p1 < $PATCHFILE
+git add $CHANGED_FILES
+sed -i -e "s/\(version: \"\)v[0-9][^\"]*/\1$NEW_VERSION_SHORT/" METADATA
+git add METADATA
+
+NEW_ADDED_FILES=$(git diff --name-only --diff-filter=A --staged $NEW_VERSION | sort)
+if [ "$ADDED_FILES" != "$NEW_ADDED_FILES" ] ; then
+ echo "Added files don't match"
+ exit 1
+fi
+
+NEW_CHANGED_FILES=$(git diff --name-only --diff-filter=a --staged $NEW_VERSION | sort)
+if [ "$CHANGED_FILES" != "$NEW_CHANGED_FILES" ] ; then
+ echo "Changed files don't match"
+ exit 1
+fi