Index: tools/merge-to-branch.sh |
diff --git a/tools/merge-to-branch.sh b/tools/merge-to-branch.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..5d3f07dc0d56bb449eda8afbe775196f7d72413d |
--- /dev/null |
+++ b/tools/merge-to-branch.sh |
@@ -0,0 +1,338 @@ |
+#!/bin/bash |
+# Copyright 2011 the V8 project authors. All rights reserved. |
Jakob Kummerow
2012/01/27 16:28:12
nit: 2012
danno
2012/01/31 10:37:57
Done.
|
+# Redistribution and use in source and binary forms, with or without |
+# modification, are permitted provided that the following conditions are |
+# met: |
+# |
+# * Redistributions of source code must retain the above copyright |
+# notice, this list of conditions and the following disclaimer. |
+# * Redistributions in binary form must reproduce the above |
+# copyright notice, this list of conditions and the following |
+# disclaimer in the documentation and/or other materials provided |
+# with the distribution. |
+# * Neither the name of Google Inc. nor the names of its |
+# contributors may be used to endorse or promote products derived |
+# from this software without specific prior written permission. |
+# |
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
+########## Global variable definitions |
+ |
+BRANCHNAME=prepare-merge |
+VERSION_FILE="src/version.cc" |
+PERSISTFILE_BASENAME=/tmp/v8-merge-to-branch-tempfile |
+CHANGELOG_ENTRY_FILE="$PERSISTFILE_BASENAME-changelog-entry" |
+PATCH_FILE="$PERSISTFILE_BASENAME-patch" |
+COMMITMSG_FILE="$PERSISTFILE_BASENAME-commitmsg" |
+COMMITMSG_FILE_COPY="$PERSISTFILE_BASENAME-commitmsg-copy" |
+TOUCHED_FILES_FILE="$PERSISTFILE_BASENAME-touched-files" |
+TRUNK_REVISION_FILE="$PERSISTFILE_BASENAME-trunkrevision" |
+STEP=0 |
+ |
+usage() { |
+cat << EOF |
+usage: $0 [OPTIONS]... BRANCH [REVISION]... |
+ |
+Performs the necessary steps to merge revisions from bleeding_edge |
+to other branches, including trunk. |
+ |
+OPTIONS: |
+ -h Show this message |
+ -s Specify the step where to start work. Default: 0. |
+EOF |
+} |
+ |
+########## Function definitions |
+ |
+die() { |
+ [[ -n "$1" ]] && echo "Error: $1" |
+ echo "Exiting." |
+ exit 1 |
+} |
+ |
+confirm() { |
+ echo -n "$1 [Y/n] " |
+ read ANSWER |
+ if [[ -z "$ANSWER" || "$ANSWER" == "Y" || "$ANSWER" == "y" ]] ; then |
+ return 0 |
+ else |
+ return 1 |
+ fi |
+} |
+ |
+delete_branch() { |
+ local MATCH=$(git branch | grep $1 | awk '{print $NF}' ) |
+ if [ "$MATCH" == "$1" ] ; then |
+ confirm "Branch $1 exists, do you want to delete it?" |
+ if [ $? -eq 0 ] ; then |
+ git branch -D $1 || die "Deleting branch '$1' failed." |
+ echo "Branch $1 deleted." |
+ else |
+ die "Can't continue. Please delete branch $1 and try again." |
+ fi |
+ fi |
+} |
+ |
+# Persist and restore variables to support canceling/resuming execution |
+# of this script. |
+persist() { |
+ local VARNAME=$1 |
+ local FILE="$PERSISTFILE_BASENAME-$VARNAME" |
+ echo "${!VARNAME}" > $FILE |
+} |
+ |
+restore() { |
+ local VARNAME=$1 |
+ local FILE="$PERSISTFILE_BASENAME-$VARNAME" |
+ local VALUE="$(cat $FILE)" |
+ eval "$VARNAME=\"$VALUE\"" |
+} |
+ |
+restore_if_unset() { |
+ local VARNAME=$1 |
+ [[ -z "${!VARNAME}" ]] && restore "$VARNAME" |
+ [[ -z "${!VARNAME}" ]] && die "Variable '$VARNAME' could not be restored." |
+} |
+ |
+ |
+########## Option parsing |
+ |
+while getopts ":hs:" OPTION ; do |
+ case $OPTION in |
+ h) usage |
+ exit 0 |
+ ;; |
+ s) STEP=$OPTARG |
+ ;; |
+ ?) echo "Illegal option: -$OPTARG" |
+ usage |
+ exit 1 |
+ ;; |
+ esac |
+done |
+ |
+MERGE_TO_BRANCH=$1 |
+[[ -n "$MERGE_TO_BRANCH" ]] \ |
+ || die "Please specify a branch to merge to" |
+shift |
+ |
+MERGE_REVISION=$1 |
+[[ -n "$MERGE_REVISION" ]] \ |
+ || die "Please specify a svn revision to merge" |
+ |
+########## Regular workflow |
+ |
+# Cancel if this is not a git checkout. |
+[[ -d .git ]] \ |
+ || die "This is not a git checkout, this script won't work for you." |
+ |
+# Cancel if EDITOR is unset or not executable. |
+[[ -n "$EDITOR" && -x "$(which $EDITOR)" ]] \ |
+ || die "Please set your EDITOR environment variable, you'll need it." |
+ |
+if [ $STEP -le 0 ] ; then |
+ echo ">>> Step 0: Preparation" |
+ # Check for a clean workdir. |
+ [[ -z "$(git status -s -uno)" ]] \ |
+ || die "Workspace is not clean. Please commit or undo your changes." |
+ |
+ # Persist current branch. |
+ CURRENT_BRANCH=$(git status -s -b -uno | grep "^##" | awk '{print $2}') |
+ persist "CURRENT_BRANCH" |
+ delete_branch $BRANCHNAME |
+fi |
+ |
+if [ $STEP -le 1 ] ; then |
+ echo ">>> Step 1: Fetch unfetched revisions." |
+ git svn fetch || die "'git svn fetch' failed." |
+fi |
+ |
+if [ $STEP -le 2 ] ; then |
+ echo ">>> Step 2: Create a fresh branch for the patch." |
+ git checkout -b $BRANCHNAME svn/$MERGE_TO_BRANCH \ |
+ || die "Creating branch $BRANCHNAME failed." |
+fi |
+ |
+if [ $STEP -le 3 ] ; then |
+ echo ">>> Step 3: Find the git revsions associated with the patches." |
Jakob Kummerow
2012/01/27 16:28:12
nit: "revisions"
danno
2012/01/31 10:37:57
Done.
|
+ current=0 |
+ for REVISION in "$@" |
Jakob Kummerow
2012/01/27 16:28:12
nit: You can get closer to our C++ style by puttin
danno
2012/01/31 10:37:57
Done.
|
+ do |
+ NEXT_HASH=$(git svn find-rev "r$REVISION" bleeding_edge) |
Jakob Kummerow
2012/01/27 16:28:12
"bleeding_edge" is one of your local git branches.
danno
2012/01/31 10:37:57
Done.
|
+ [[ -n "$NEXT_HASH" ]] \ |
+ || die "Cannot determine git hash for r$REVISION" |
+ PATCH_COMMIT_HASHES[$current]="$NEXT_HASH" |
+ if [ "$NEW_COMMIT_MSG" ] ; then |
Jakob Kummerow
2012/01/27 16:28:12
for consistency:
[[ -n "$NEW_COMMIT_MSG" ]] && NE
danno
2012/01/31 10:37:57
Done.
|
+ NEW_COMMIT_MSG="$NEW_COMMIT_MSG," |
+ fi |
+ NEW_COMMIT_MSG="$NEW_COMMIT_MSG r$REVISION" |
+ let current+=1 |
+ done |
+ NEW_COMMIT_MSG="Merged$NEW_COMMIT_MSG into \ |
+$MERGE_TO_BRANCH branch." |
+ persist PATCH_COMMIT_HASHES |
Jakob Kummerow
2012/01/27 16:28:12
Have you tested whether persist() can handle array
danno
2012/01/31 10:37:57
Done.
|
+ persist NEW_COMMIT_MSG |
+fi |
+ |
+if [ $STEP -le 4 ] ; then |
+ restore_if_unset "PATCH_COMMIT_HASHES" |
+ restore_if_unset "NEW_COMMIT_MSG" |
+ echo ">>> Step 4: Aggregate patch description and bugs numbers." |
+ |
+ echo "$NEW_COMMIT_MSG" > $COMMITMSG_FILE |
Jakob Kummerow
2012/01/27 16:28:12
If you move this to the end of step 3, you don't n
danno
2012/01/31 10:37:57
Done.
|
+ echo >> $COMMITMSG_FILE |
+ for HASH in ${PATCH_COMMIT_HASHES[@]} |
+ do |
+ PATCH_MERGE_DESCRIPTION=$(git show --notes $HASH \ |
Jakob Kummerow
2012/01/27 16:28:12
I think what you mean here is just:
PATCH_MERGE_D
danno
2012/01/31 10:37:57
Done.
|
+ | awk '{ |
+ if (line_number == 4) { |
+ printf($0); |
+ }; |
+ line_number++ |
+ }' \ |
+ | sed 's/ //') |
+ echo "DESC: $PATCH_MERGE_DESCRIPTION" |
+ echo "$PATCH_MERGE_DESCRIPTION" >> $COMMITMSG_FILE |
+ echo >> $COMMITMSG_FILE |
+ done |
+ for HASH in ${PATCH_COMMIT_HASHES[@]} |
+ do |
+ BUG=$(git show --notes $HASH | grep "BUG=" | awk -F '=' '{print $NF}') |
Jakob Kummerow
2012/01/27 16:28:12
I guess it doesn't really matter, but "git log -1"
danno
2012/01/31 10:37:57
Done.
|
+ if [ $BUG ] ; then |
+ if [ "$BUG_AGGREGATE" ] ; then |
+ BUG_AGGREGATE="$BUG_AGGREGATE," |
+ fi |
+ BUG_AGGREGATE="$BUG_AGGREGATE$BUG" |
+ fi |
+ done |
+ if [ "$BUG_AGGREGATE" ] ; then |
+ echo "BUG=$BUG_AGGREGATE" >> $COMMITMSG_FILE |
+ else |
+ echo "BUG=none" >> $COMMITMSG_FILE |
+ fi |
+fi |
+ |
+if [ $STEP -le 5 ] ; then |
+ echo ">>> Step 5: Apply the revision patch and create commit message." |
+ for HASH in ${PATCH_COMMIT_HASHES[@]} |
Jakob Kummerow
2012/01/27 16:28:12
missing restore_if_unset for PATCH_COMMIT_HASHES
danno
2012/01/31 10:37:57
Done.
|
+ do |
+ git log -1 -p $HASH | patch -p1 \ |
+ || die "Cannot apply the patch for r$MERGE_REVISION on $MERGE_TO_BRANCH" |
Jakob Kummerow
2012/01/27 16:28:12
Talking about a single MERGE_REVISION here is inco
danno
2012/01/31 10:37:57
Done.
|
+ done |
+fi |
+ |
+if [ $STEP -le 6 ] ; then |
+ echo ">>> Step 6: Prepare version.cc" |
+# These version numbers are used again later for the trunk commit. |
Jakob Kummerow
2012/01/27 16:28:12
outdated comment?
danno
2012/01/31 10:37:57
Done.
|
+ MAJOR=$(grep "#define MAJOR_VERSION" "$VERSION_FILE" | awk '{print $NF}') |
Jakob Kummerow
2012/01/27 16:28:12
do we need MAJOR, MINOR and BUILD at all?
danno
2012/01/31 10:37:57
Yes. For building the tag.
On 2012/01/27 16:28:12,
|
+ persist "MAJOR" |
+ MINOR=$(grep "#define MINOR_VERSION" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "MINOR" |
+ BUILD=$(grep "#define BUILD_NUMBER" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "BUILD" |
+ PATCH=$(grep "#define PATCH_LEVEL" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "PATCH" |
+fi |
+ |
+if [ $STEP -le 7 ] ; then |
+ echo ">>> Step 7: Increment version number." |
+ restore_if_unset "PATCH" |
+ NEWPATCH=$(($PATCH + 1)) |
+ confirm "Automatically increment BUILD_NUMBER? (Saying 'n' will fire up \ |
Jakob Kummerow
2012/01/27 16:28:12
s/BUILD_NUMBER/PATCH_LEVEL/
danno
2012/01/31 10:37:57
Done.
|
+your EDITOR on $VERSION_FILE so you can make arbitrary changes. When \ |
+you're done, save the file and exit your EDITOR.)" |
+ if [ $? -eq 0 ] ; then |
+ sed -e "/#define PATCH_LEVEL/s/[0-9]*$/$NEWPATCH/" \ |
+ -i "$VERSION_FILE" |
+ else |
+ $EDITOR "$VERSION_FILE" |
+ fi |
+ NEWMAJOR=$(grep "#define MAJOR_VERSION" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "NEWMAJOR" |
+ NEWMINOR=$(grep "#define MINOR_VERSION" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "NEWMINOR" |
+ NEWBUILD=$(grep "#define BUILD_NUMBER" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "NEWBUILD" |
+ NEWPATCH=$(grep "#define PATCH_LEVEL" "$VERSION_FILE" | awk '{print $NF}') |
+ persist "NEWPATCH" |
+fi |
+ |
+if [ $STEP -le 8 ] ; then |
+ echo ">>> Step 8: Commit to local branch." |
+ restore_if_unset "NEW_COMMIT_MSG" |
+ git commit -a -m "$NEW_COMMIT_MSG" \ |
+ || die "'git commit -a' failed." |
+fi |
+ |
+if [ $STEP -le 9 ] ; then |
+ echo ">>> Step 9: Confirm merge commit." |
+ echo "This is the message that will be used for the commit:" |
+ echo "--------------------" |
+ cat "$COMMITMSG_FILE" |
+ echo -e "--------------------" |
Jakob Kummerow
2012/01/27 16:28:12
nit: "-e" is unnecessary (since you don't have any
danno
2012/01/31 10:37:57
Done.
|
+ confirm "Does this look good to you? (Saying 'n' will fire up your \ |
+EDITOR so you can change the commit message. When you're done, save the \ |
+file and exit your EDITOR.)" |
+ if [ $? -ne 0 ] ; then |
+ $EDITOR "$COMMITMSG_FILE" |
+ fi |
+fi |
+ |
+if [ $STEP -le 10 ] ; then |
+ echo ">>> Step 10: Upload for code review." |
+ echo -n "Please enter the email address of a V8 reviewer for your patch: " |
+ read REVIEWER |
+ cat $COMMITMSG_FILE > $COMMITMSG_FILE_COPY |
+ echo "R=$REVIEWER" >> $COMMITMSG_FILE_COPY |
Jakob Kummerow
2012/01/27 16:28:12
You don't need this. "git cl upload --review" auto
danno
2012/01/31 10:37:57
On 2012/01/27 16:28:12, Jakob wrote:
> You don't n
|
+ export EDITOR="cat $COMMITMSG_FILE_COPY >" |
Jakob Kummerow
2012/01/27 16:28:12
I'm not sure I like messing with my EDITOR variabl
danno
2012/01/31 10:37:57
Done.
|
+ git cl upload --review "$REVIEWER" --send-mail \ |
+ || die "'git cl upload' failed, please try again." |
+fi |
+ |
+if [ $STEP -le 11 ] ; then |
+ echo ">>> Step 11: Sanity check." |
+ confirm "Please check if your local checkout is sane: Inspect $VERSION_FILE, \ |
+compile, run tests. Do you want to commit this new trunk revision to the \ |
Jakob Kummerow
2012/01/27 16:28:12
nit: s/new trunk//
Also, we don't really need ste
danno
2012/01/31 10:37:57
Done.
|
+repository?" |
+ [[ $? -eq 0 ]] || die "Execution canceled." |
+fi |
+ |
+if [ $STEP -le 12 ] ; then |
+ echo ">>> Step 12: Commit to the repository." |
+ echo "Please wait for an LGTM, then type \"LGTM<Return>\" to commit your \ |
+change. (If you need to iterate on the patch, do so in another shell. Do not \ |
Jakob Kummerow
2012/01/27 16:28:12
You can remove the "Do not modify..." part, as it
danno
2012/01/31 10:37:57
Done.
|
+modify the existing local commit's commit message.)" |
+ unset ANSWER |
+ while [ "$ANSWER" != "LGTM" ] ; do |
+ [[ -n "$ANSWER" ]] && echo "That was not 'LGTM'." |
+ echo -n "> " |
+ read ANSWER |
+ done |
+ echo "git-cl dcommit" |
Jakob Kummerow
2012/01/27 16:28:12
Forgot to remove the "echo".
danno
2012/01/31 10:37:57
Done.
|
+fi |
+ |
+if [ $STEP -le 13 ] ; then |
+ restore_if_unset "NEWMAJOR" |
+ restore_if_unset "NEWMINOR" |
+ restore_if_unset "NEWBUILD" |
+ restore_if_unset "NEWPATCH" |
+ echo ">>> Step 13: Create the tag." |
+ echo "svn copy -r ? https://v8.googlecode.com/svn/branches/$MERGE_TO_BRANCH https://v8.googlecode.com/svn/tags/$NEWMAJOR.$NEWMINOR.$NEWBUILD.$NEWPATCH -m \"Tagging version $NEWMAJOR.$NEWMINOR.$NEWBUILD.$NEWPATCH\"" |
Jakob Kummerow
2012/01/27 16:28:12
another "echo" that needs to go.
danno
2012/01/31 10:37:57
Done.
|
+fi |
+ |
+if [ $STEP -le 14 ] ; then |
+ echo ">>> Step 14: Cleanup." |
+ restore_if_unset "CURRENT_BRANCH" |
+ git checkout -f $CURRENT_BRANCH |
+ [[ "$BRANCHNAME" != "$CURRENT_BRANCH" ]] && echo "git branch -D $BRANCHNAME" |
Jakob Kummerow
2012/01/27 16:28:12
another "echo" that needs to go.
danno
2012/01/31 10:37:57
Done.
|
+fi |