1 | # $Id: backport-common.sh 85668 2020-08-10 15:25:45Z vboxsync $
|
---|
2 | ## @file
|
---|
3 | # Common backport script bits.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2020 Oracle Corporation
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 |
|
---|
18 | #
|
---|
19 | # Globals.
|
---|
20 | #
|
---|
21 | MY_CAT=kmk_cat
|
---|
22 | MY_EXPR=kmk_expr
|
---|
23 | MY_PRINTF=kmk_printf
|
---|
24 | MY_RM=kmk_rm
|
---|
25 | MY_SVN=svn
|
---|
26 | MY_SED=kmk_sed
|
---|
27 |
|
---|
28 | #
|
---|
29 | # Functions.
|
---|
30 | #
|
---|
31 | BranchDirToName()
|
---|
32 | {
|
---|
33 | MY_DIR=$1
|
---|
34 | MY_NAME=`echo "${MY_DIR}" | "${MY_SED}" -e 's|^\(.*\)/\([^/][^/]*\)$|\2|'`
|
---|
35 | case "${MY_NAME}" in
|
---|
36 | VBox-[5-9].[0-3]|VBox-1[0-5].[0-3])
|
---|
37 | echo "${MY_NAME}" | "${MY_SED}" -e 's/VBox-//'
|
---|
38 | ;;
|
---|
39 | [Vv][Bb][Oo][Xx][5-9][0-3])
|
---|
40 | echo "${MY_NAME}" | "${MY_SED}" -e 's/[Vv][Bb][Oo][Xx]\([0-9]\)\([0-3]\)/\1.\2/'
|
---|
41 | ;;
|
---|
42 | [Tt][Rr][Uu][Nn][Kk])
|
---|
43 | echo trunk
|
---|
44 | ;;
|
---|
45 | *)
|
---|
46 | echo "warning: Unable to guess branch given ${MY_NAME} ($1)" 1>&2
|
---|
47 | ;;
|
---|
48 | esac
|
---|
49 | }
|
---|
50 |
|
---|
51 | AddRevision()
|
---|
52 | {
|
---|
53 | if test -z "${MY_REVISIONS}"; then
|
---|
54 | MY_REVISIONS=$1
|
---|
55 | MY_REVISION_COUNT=1
|
---|
56 | else
|
---|
57 | MY_REVISIONS="${MY_REVISIONS} $1"
|
---|
58 | MY_REVISION_COUNT=$(${MY_EXPR} ${MY_REVISION_COUNT} + 1)
|
---|
59 | fi
|
---|
60 | }
|
---|
61 |
|
---|
62 | AddRevisionRange()
|
---|
63 | {
|
---|
64 | MY_REV=$1
|
---|
65 | MY_REV_FIRST=${MY_REV%-*}
|
---|
66 | MY_REV_LAST=${MY_REV#*-}
|
---|
67 | if test -z "${MY_REV_FIRST}" -o -z "${MY_REV_LAST}" -o '(' '!' "${MY_REV_FIRST}" -lt "${MY_REV_LAST}" ')'; then
|
---|
68 | echo "error: Failed to parse revision range: MY_REV_FIRST=${MY_REV_FIRST} MY_REV_LAST=${MY_REV_LAST} MY_REV=${MY_REV}"
|
---|
69 | exit 1
|
---|
70 | fi
|
---|
71 | MY_REV=${MY_REV_FIRST}
|
---|
72 | while test ${MY_REV} -le ${MY_REV_LAST};
|
---|
73 | do
|
---|
74 | AddRevision "${MY_REV}"
|
---|
75 | MY_REV=$(${MY_EXPR} ${MY_REV} + 1)
|
---|
76 | done
|
---|
77 | }
|
---|
78 |
|
---|
79 | #
|
---|
80 | # Figure default branch given the script location.
|
---|
81 | #
|
---|
82 | MY_BRANCH_DEFAULT_DIR=`cd "${MY_SCRIPT_DIR}"; cd ../..; pwd -L`
|
---|
83 | MY_BRANCH_DEFAULT=`BranchDirToName "${MY_BRANCH_DEFAULT_DIR}"`
|
---|
84 | if test "${MY_BRANCH_DEFAULT}" = "trunk"; then
|
---|
85 | MY_TRUNK_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
86 | elif test -d "${MY_BRANCH_DEFAULT_DIR}/../../trunk"; then
|
---|
87 | MY_TRUNK_DIR=`cd "${MY_BRANCH_DEFAULT_DIR}"; cd ../../trunk; pwd -L`
|
---|
88 | else
|
---|
89 | MY_TRUNK_DIR="^/trunk"
|
---|
90 | fi
|
---|
91 |
|
---|
92 |
|
---|
93 | #
|
---|
94 | # Parse arguments.
|
---|
95 | #
|
---|
96 | MY_BRANCH_DIR=
|
---|
97 | MY_BRANCH=
|
---|
98 | MY_REVISIONS=
|
---|
99 | MY_REVISION_COUNT=0
|
---|
100 | MY_EXTRA_ARGS=
|
---|
101 | MY_DEBUG=
|
---|
102 | MY_FORCE=
|
---|
103 | MY_SHOW_DIFF=
|
---|
104 |
|
---|
105 | while test $# -ge 1;
|
---|
106 | do
|
---|
107 | ARG=$1
|
---|
108 | shift
|
---|
109 | case "${ARG}" in
|
---|
110 | r[0-9][0-9][0-9][0-9][0-9]|r[0-9][0-9][0-9][0-9][0-9][0-9]|r[0-9][0-9][0-9][0-9][0-9][0-9][0-9])
|
---|
111 | MY_REV=`echo ${ARG} | "${MY_SED}" -e 's/^r//'`
|
---|
112 | AddRevision ${MY_REV}
|
---|
113 | ;;
|
---|
114 |
|
---|
115 | [0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9][0-9])
|
---|
116 | AddRevision ${ARG}
|
---|
117 | ;;
|
---|
118 |
|
---|
119 | [0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9])
|
---|
120 | AddRevisionRange ${ARG}
|
---|
121 | ;;
|
---|
122 | r[0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]|r[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]|r[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9])
|
---|
123 | MY_REV=`echo "${ARG}" | "${MY_SED}" -e 's/^r//'`
|
---|
124 | AddRevisionRange ${MY_REV}
|
---|
125 | ;;
|
---|
126 |
|
---|
127 | --trunk-dir)
|
---|
128 | if test $# -eq 0; then
|
---|
129 | echo "error: missing --trunk-dir argument." 1>&2
|
---|
130 | exit 1;
|
---|
131 | fi
|
---|
132 | MY_TRUNK_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
|
---|
133 | shift
|
---|
134 | ;;
|
---|
135 |
|
---|
136 | --branch-dir)
|
---|
137 | if test $# -eq 0; then
|
---|
138 | echo "error: missing --branch-dir argument." 1>&2
|
---|
139 | exit 1;
|
---|
140 | fi
|
---|
141 | MY_BRANCH_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
|
---|
142 | shift
|
---|
143 | ;;
|
---|
144 |
|
---|
145 | --branch)
|
---|
146 | if test $# -eq 0; then
|
---|
147 | echo "error: missing --branch argument." 1>&2
|
---|
148 | exit 1;
|
---|
149 | fi
|
---|
150 | MY_BRANCH="$1"
|
---|
151 | shift
|
---|
152 | ;;
|
---|
153 |
|
---|
154 | --first-rev|--first|-1)
|
---|
155 | MY_FIRST_REV=1
|
---|
156 | ;;
|
---|
157 |
|
---|
158 | --force)
|
---|
159 | MY_FORCE=1
|
---|
160 | ;;
|
---|
161 |
|
---|
162 | --update-first|--update|-u)
|
---|
163 | MY_UPDATE_FIRST=1
|
---|
164 | ;;
|
---|
165 |
|
---|
166 | --show-diff)
|
---|
167 | MY_SHOW_DIFF=1
|
---|
168 | ;;
|
---|
169 |
|
---|
170 | --extra)
|
---|
171 | if test $# -eq 0; then
|
---|
172 | echo "error: missing --extra argument." 1>&2
|
---|
173 | exit 1;
|
---|
174 | fi
|
---|
175 | MY_EXTRA_ARGS="${MY_EXTRA_ARGS} $1"
|
---|
176 | shift
|
---|
177 | ;;
|
---|
178 |
|
---|
179 | --debug)
|
---|
180 | MY_DEBUG=1
|
---|
181 | ;;
|
---|
182 |
|
---|
183 | # usage
|
---|
184 | --h*|-h*|-?|--?)
|
---|
185 | echo "usage: $0 [--trunk-dir <dir>] [--branch <ver>] [--branch-dir <dir>] [--extra <svn-arg>] \\"
|
---|
186 | echo " [--first-rev] [--update-first] rev1 [rev2..[revN]]]"
|
---|
187 | echo ""
|
---|
188 | echo "Options:"
|
---|
189 | echo " --trunk-dir <dir>"
|
---|
190 | echo " The source of the changeset being backported."
|
---|
191 | echo " --branch-dir <dir>"
|
---|
192 | echo " The backport destination directory. default: script location"
|
---|
193 | echo " --branch <ver>"
|
---|
194 | echo " The name of the branch being backported to. default: auto"
|
---|
195 | echo " --debug"
|
---|
196 | echo " Enables verbose output."
|
---|
197 | echo " --first-rev, --first, -1"
|
---|
198 | echo " Merge only: Check that the branch does not have any pending changes."
|
---|
199 | echo " --force"
|
---|
200 | echo " Forces backporting, regardless of ancestry. Use with caution!"
|
---|
201 | echo " --show-diff"
|
---|
202 | echo " Shows unified diff before backporting."
|
---|
203 | echo " --update-first, --update, -u"
|
---|
204 | echo " Merge only: Update the branch before merging."
|
---|
205 | echo " --extra <svn-arg>"
|
---|
206 | echo " Additional arguments to specify to SVN."
|
---|
207 | echo ""
|
---|
208 | exit 2;
|
---|
209 | ;;
|
---|
210 |
|
---|
211 | *)
|
---|
212 | echo "syntax error: ${ARG}"
|
---|
213 | exit 2;
|
---|
214 | ;;
|
---|
215 | esac
|
---|
216 | done
|
---|
217 |
|
---|
218 | if test -n "${MY_DEBUG}"; then
|
---|
219 | echo " MY_SCRIPT_DIR=${MY_SCRIPT_DIR}"
|
---|
220 | echo " MY_BRANCH_DIR=${MY_BRANCH_DIR}"
|
---|
221 | echo " MY_BRANCH=${MY_BRANCH}"
|
---|
222 | echo "MY_BRANCH_DEFAULT_DIR=${MY_BRANCH_DEFAULT_DIR}"
|
---|
223 | echo " MY_BRANCH_DEFAULT=${MY_BRANCH_DEFAULT}"
|
---|
224 | echo " MY_TRUNK_DIR=${MY_TRUNK_DIR}"
|
---|
225 | echo " MY_REVISIONS=${MY_REVISIONS}"
|
---|
226 | fi
|
---|
227 |
|
---|
228 | #
|
---|
229 | # Resolve branch variables.
|
---|
230 | #
|
---|
231 | if test -z "${MY_BRANCH_DIR}" -a -z "${MY_BRANCH}"; then
|
---|
232 | MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
233 | MY_BRANCH=${MY_BRANCH_DEFAULT}
|
---|
234 | elif test -n "${MY_BRANCH}" -a -z "${MY_BRANCH_DIR}"; then
|
---|
235 | MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
236 | elif test -z "${MY_BRANCH}" -a -n "${MY_BRANCH_DIR}"; then
|
---|
237 | MY_BRANCH=`BranchDirToName "${MY_BRANCH_DIR}"`
|
---|
238 | if test -z "${MY_BRANCH}" -o "${MY_BRANCH}" = "${MY_BRANCH_DIR}"; then
|
---|
239 | echo "error: Failed to guess branch name for: ${MY_BRANCH_DIR}" 1>&2
|
---|
240 | echo " Use --branch to specify it." 1>&2
|
---|
241 | exit 2;
|
---|
242 | fi
|
---|
243 | fi
|
---|
244 | if test "${MY_BRANCH}" = "trunk"; then
|
---|
245 | echo "error: script does not work with 'trunk' as the branch" 1>&2
|
---|
246 | exit 2;
|
---|
247 | fi
|
---|
248 |
|
---|
249 | #
|
---|
250 | # Stop if no revisions specified.
|
---|
251 | #
|
---|
252 | if test -z "${MY_REVISIONS}" -a "${MY_SCRIPT_NAME}" '!=' "backport-commit.sh"; then
|
---|
253 | echo "error: No revisions specified" 1>&2;
|
---|
254 | exit 2;
|
---|
255 | fi
|
---|