Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Side by Side Diff: tools/common-includes.sh

Issue 9463041: Refactored push-to-trunk.sh and merge-to-branch.sh. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fixes for push-to-trunk.sh Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/merge-to-branch.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2012 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
4 # met:
5 #
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 # This file contains common function definitions for various other shell
29 # scripts in this directory. It is not meant to be executed by itself.
30
31 # Important: before including this file, the following variables must be set:
32 # - BRANCHNAME
33 # - PERSISTFILE_BASENAME
34
35 TEMP_BRANCH=$BRANCHNAME-temporary-branch-created-by-script
36 VERSION_FILE="src/version.cc"
37 CHANGELOG_ENTRY_FILE="$PERSISTFILE_BASENAME-changelog-entry"
38 PATCH_FILE="$PERSISTFILE_BASENAME-patch"
39 COMMITMSG_FILE="$PERSISTFILE_BASENAME-commitmsg"
40 TOUCHED_FILES_FILE="$PERSISTFILE_BASENAME-touched-files"
41 TRUNK_REVISION_FILE="$PERSISTFILE_BASENAME-trunkrevision"
42 START_STEP=0
43 CURRENT_STEP=0
44
45 die() {
46 [[ -n "$1" ]] && echo "Error: $1"
47 echo "Exiting."
48 exit 1
49 }
50
51 confirm() {
52 echo -n "$1 [Y/n] "
53 read ANSWER
54 if [[ -z "$ANSWER" || "$ANSWER" == "Y" || "$ANSWER" == "y" ]] ; then
55 return 0
56 else
57 return 1
58 fi
59 }
60
61 delete_branch() {
62 local MATCH=$(git branch | grep $1 | awk '{print $NF}' )
63 if [ "$MATCH" == "$1" ] ; then
64 confirm "Branch $1 exists, do you want to delete it?"
65 if [ $? -eq 0 ] ; then
66 git branch -D $1 || die "Deleting branch '$1' failed."
67 echo "Branch $1 deleted."
68 else
69 die "Can't continue. Please delete branch $1 and try again."
70 fi
71 fi
72 }
73
74 # Persist and restore variables to support canceling/resuming execution
75 # of this script.
76 persist() {
77 local VARNAME=$1
78 local FILE="$PERSISTFILE_BASENAME-$VARNAME"
79 echo "${!VARNAME}" > $FILE
80 }
81
82 restore() {
83 local VARNAME=$1
84 local FILE="$PERSISTFILE_BASENAME-$VARNAME"
85 local VALUE="$(cat $FILE)"
86 eval "$VARNAME=\"$VALUE\""
87 }
88
89 restore_if_unset() {
90 local VARNAME=$1
91 [[ -z "${!VARNAME}" ]] && restore "$VARNAME"
92 [[ -z "${!VARNAME}" ]] && die "Variable '$VARNAME' could not be restored."
93 }
94
95 initial_environment_checks() {
96 # Cancel if this is not a git checkout.
97 [[ -d .git ]] \
98 || die "This is not a git checkout, this script won't work for you."
99
100 # Cancel if EDITOR is unset or not executable.
101 [[ -n "$EDITOR" && -x "$(which $EDITOR)" ]] \
102 || die "Please set your EDITOR environment variable, you'll need it."
103 }
104
105 common_prepare() {
106 # Check for a clean workdir.
107 [[ -z "$(git status -s -uno)" ]] \
108 || die "Workspace is not clean. Please commit or undo your changes."
109
110 # Persist current branch.
111 CURRENT_BRANCH=$(git status -s -b -uno | grep "^##" | awk '{print $2}')
112 persist "CURRENT_BRANCH"
113
114 # Fetch unfetched revisions.
115 git svn fetch || die "'git svn fetch' failed."
116
117 # Get ahold of a safe temporary branch and check it out.
118 if [ "$CURRENT_BRANCH" != "$TEMP_BRANCH" ] ; then
119 delete_branch $TEMP_BRANCH
120 git checkout -b $TEMP_BRANCH
121 fi
122
123 # Delete the branch that will be created later if it exists already.
124 delete_branch $BRANCHNAME
125 }
126
127 common_cleanup() {
128 restore_if_unset "CURRENT_BRANCH"
129 git checkout -f $CURRENT_BRANCH
130 [[ "$TEMP_BRANCH" != "$CURRENT_BRANCH" ]] && git branch -D $TEMP_BRANCH
131 [[ "$BRANCHNAME" != "$CURRENT_BRANCH" ]] && git branch -D $BRANCHNAME
132 # Clean up all temporary files.
133 rm -f "$PERSISTFILE_BASENAME"*
134 }
135
136 # These two functions take a prefix for the variable names as first argument.
137 read_and_persist_version() {
138 for v in MAJOR_VERSION MINOR_VERSION BUILD_NUMBER PATCH_LEVEL; do
139 VARNAME="$1${v%%_*}"
140 VALUE=$(grep "#define $v" "$VERSION_FILE" | awk '{print $NF}')
141 eval "$VARNAME=\"$VALUE\""
142 persist "$VARNAME"
143 done
144 }
145 restore_version_if_unset() {
146 for v in MAJOR MINOR BUILD PATCH; do
147 restore_if_unset "$1$v"
148 done
149 }
150
151 upload_step() {
152 let CURRENT_STEP+=1
153 if [ $START_STEP -le $CURRENT_STEP ] ; then
154 echo ">>> Step $CURRENT_STEP: Upload for code review."
155 echo -n "Please enter the email address of a V8 reviewer for your patch: "
156 read REVIEWER
157 git cl upload -r "$REVIEWER" --send-mail \
158 || die "'git cl upload' failed, please try again."
159 fi
160 }
161
162 wait_for_lgtm() {
163 echo "Please wait for an LGTM, then type \"LGTM<Return>\" to commit your \
164 change. (If you need to iterate on the patch or double check that it's \
165 sane, do so in another shell, but remember to not change the headline of \
166 the uploaded CL."
167 unset ANSWER
168 while [ "$ANSWER" != "LGTM" ] ; do
169 [[ -n "$ANSWER" ]] && echo "That was not 'LGTM'."
170 echo -n "> "
171 read ANSWER
172 done
173 }
174
175 # Takes a file containing the patch to apply as first argument.
176 apply_patch() {
177 patch -p1 < "$1" | tee >(awk '{print $NF}' >> "$TOUCHED_FILES_FILE")
178 [[ $? -eq 0 ]] || die "Applying the patch failed."
179 }
180
181 stage_files() {
182 # Stage added and modified files.
183 TOUCHED_FILES=$(cat "$TOUCHED_FILES_FILE")
184 for FILE in $TOUCHED_FILES ; do
185 git add "$FILE"
186 done
187 # Stage deleted files.
188 DELETED_FILES=$(git status -s -uno --porcelain | grep "^ D" \
189 | awk '{print $NF}')
190 for FILE in $DELETED_FILES ; do
191 git rm "$FILE"
192 done
193 rm -f "$TOUCHED_FILES_FILE"
194 }
OLDNEW
« no previous file with comments | « no previous file | tools/merge-to-branch.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698