VirtualBox

source: vbox/trunk/tools/bin/backport-common.sh@ 96562

Last change on this file since 96562 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette