1 | # $Id: backport-common.sh 85589 2020-07-31 19:26:03Z 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 | #
|
---|
63 | # Figure default branch given the script location.
|
---|
64 | #
|
---|
65 | MY_BRANCH_DEFAULT_DIR=`cd "${MY_SCRIPT_DIR}"; cd ../..; pwd -L`
|
---|
66 | MY_BRANCH_DEFAULT=`BranchDirToName "${MY_BRANCH_DEFAULT_DIR}"`
|
---|
67 | if test "${MY_BRANCH_DEFAULT}" = "trunk"; then
|
---|
68 | MY_TRUNK_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
69 | elif test -d "${MY_BRANCH_DEFAULT_DIR}/../../trunk"; then
|
---|
70 | MY_TRUNK_DIR=`cd "${MY_BRANCH_DEFAULT_DIR}"; cd ../../trunk; pwd -L`
|
---|
71 | else
|
---|
72 | MY_TRUNK_DIR="^/trunk"
|
---|
73 | fi
|
---|
74 |
|
---|
75 |
|
---|
76 | #
|
---|
77 | # Parse arguments.
|
---|
78 | #
|
---|
79 | MY_BRANCH_DIR=
|
---|
80 | MY_BRANCH=
|
---|
81 | MY_REVISIONS=
|
---|
82 | MY_REVISION_COUNT=0
|
---|
83 | MY_EXTRA_ARGS=
|
---|
84 | MY_DEBUG=
|
---|
85 | MY_FORCE=
|
---|
86 | MY_SHOW_DIFF=
|
---|
87 |
|
---|
88 | while test $# -ge 1;
|
---|
89 | do
|
---|
90 | ARG=$1
|
---|
91 | shift
|
---|
92 | case "${ARG}" in
|
---|
93 | 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])
|
---|
94 | MY_REV=`echo ${ARG} | "${MY_SED}" -e 's/^r//'`
|
---|
95 | AddRevision ${MY_REV}
|
---|
96 | ;;
|
---|
97 |
|
---|
98 | [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])
|
---|
99 | AddRevision ${ARG}
|
---|
100 | ;;
|
---|
101 |
|
---|
102 | --trunk-dir)
|
---|
103 | if test $# -eq 0; then
|
---|
104 | echo "error: missing --trunk-dir argument." 1>&2
|
---|
105 | exit 1;
|
---|
106 | fi
|
---|
107 | MY_TRUNK_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
|
---|
108 | shift
|
---|
109 | ;;
|
---|
110 |
|
---|
111 | --branch-dir)
|
---|
112 | if test $# -eq 0; then
|
---|
113 | echo "error: missing --branch-dir argument." 1>&2
|
---|
114 | exit 1;
|
---|
115 | fi
|
---|
116 | MY_BRANCH_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
|
---|
117 | shift
|
---|
118 | ;;
|
---|
119 |
|
---|
120 | --branch)
|
---|
121 | if test $# -eq 0; then
|
---|
122 | echo "error: missing --branch argument." 1>&2
|
---|
123 | exit 1;
|
---|
124 | fi
|
---|
125 | MY_BRANCH="$1"
|
---|
126 | shift
|
---|
127 | ;;
|
---|
128 |
|
---|
129 | --first-rev|--first|-1)
|
---|
130 | MY_FIRST_REV=1
|
---|
131 | ;;
|
---|
132 |
|
---|
133 | --force)
|
---|
134 | MY_FORCE=1
|
---|
135 | ;;
|
---|
136 |
|
---|
137 | --update-first|--update|-u)
|
---|
138 | MY_UPDATE_FIRST=1
|
---|
139 | ;;
|
---|
140 |
|
---|
141 | --show-diff)
|
---|
142 | MY_SHOW_DIFF=1
|
---|
143 | ;;
|
---|
144 |
|
---|
145 | --extra)
|
---|
146 | if test $# -eq 0; then
|
---|
147 | echo "error: missing --extra argument." 1>&2
|
---|
148 | exit 1;
|
---|
149 | fi
|
---|
150 | MY_EXTRA_ARGS="${MY_EXTRA_ARGS} $1"
|
---|
151 | shift
|
---|
152 | ;;
|
---|
153 |
|
---|
154 | --debug)
|
---|
155 | MY_DEBUG=1
|
---|
156 | ;;
|
---|
157 |
|
---|
158 | # usage
|
---|
159 | --h*|-h*|-?|--?)
|
---|
160 | echo "usage: $0 [--trunk-dir <dir>] [--branch <ver>] [--branch-dir <dir>] [--extra <svn-arg>] \\"
|
---|
161 | echo " [--first-rev] [--update-first] rev1 [rev2..[revN]]]"
|
---|
162 | echo ""
|
---|
163 | echo "Options:"
|
---|
164 | echo " --trunk-dir <dir>"
|
---|
165 | echo " The source of the changeset being backported."
|
---|
166 | echo " --branch-dir <dir>"
|
---|
167 | echo " The backport destination directory. default: script location"
|
---|
168 | echo " --branch <ver>"
|
---|
169 | echo " The name of the branch being backported to. default: auto"
|
---|
170 | echo " --debug"
|
---|
171 | echo " Enables verbose output."
|
---|
172 | echo " --first-rev, --first, -1"
|
---|
173 | echo " Merge only: Check that the branch does not have any pending changes."
|
---|
174 | echo " --force"
|
---|
175 | echo " Forces backporting, regardless of ancestry. Use with caution!"
|
---|
176 | echo " --show-diff"
|
---|
177 | echo " Shows unified diff before backporting."
|
---|
178 | echo " --update-first, --update, -u"
|
---|
179 | echo " Merge only: Update the branch before merging."
|
---|
180 | echo " --extra <svn-arg>"
|
---|
181 | echo " Additional arguments to specify to SVN."
|
---|
182 | echo ""
|
---|
183 | exit 2;
|
---|
184 | ;;
|
---|
185 |
|
---|
186 | *)
|
---|
187 | echo "syntax error: ${ARG}"
|
---|
188 | exit 2;
|
---|
189 | ;;
|
---|
190 | esac
|
---|
191 | done
|
---|
192 |
|
---|
193 | if test -n "${MY_DEBUG}"; then
|
---|
194 | echo " MY_SCRIPT_DIR=${MY_SCRIPT_DIR}"
|
---|
195 | echo " MY_BRANCH_DIR=${MY_BRANCH_DIR}"
|
---|
196 | echo " MY_BRANCH=${MY_BRANCH}"
|
---|
197 | echo "MY_BRANCH_DEFAULT_DIR=${MY_BRANCH_DEFAULT_DIR}"
|
---|
198 | echo " MY_BRANCH_DEFAULT=${MY_BRANCH_DEFAULT}"
|
---|
199 | echo " MY_TRUNK_DIR=${MY_TRUNK_DIR}"
|
---|
200 | echo " MY_REVISIONS=${MY_REVISIONS}"
|
---|
201 | fi
|
---|
202 |
|
---|
203 | #
|
---|
204 | # Resolve branch variables.
|
---|
205 | #
|
---|
206 | if test -z "${MY_BRANCH_DIR}" -a -z "${MY_BRANCH}"; then
|
---|
207 | MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
208 | MY_BRANCH=${MY_BRANCH_DEFAULT}
|
---|
209 | elif test -n "${MY_BRANCH}" -a -z "${MY_BRANCH_DIR}"; then
|
---|
210 | MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
|
---|
211 | elif test -z "${MY_BRANCH}" -a -n "${MY_BRANCH_DIR}"; then
|
---|
212 | MY_BRANCH=`BranchDirToName "${MY_BRANCH_DIR}"`
|
---|
213 | if test -z "${MY_BRANCH}" -o "${MY_BRANCH}" = "${MY_BRANCH_DIR}"; then
|
---|
214 | echo "error: Failed to guess branch name for: ${MY_BRANCH_DIR}" 1>&2
|
---|
215 | echo " Use --branch to specify it." 1>&2
|
---|
216 | exit 2;
|
---|
217 | fi
|
---|
218 | fi
|
---|
219 | if test "${MY_BRANCH}" = "trunk"; then
|
---|
220 | echo "error: script does not work with 'trunk' as the branch" 1>&2
|
---|
221 | exit 2;
|
---|
222 | fi
|
---|
223 |
|
---|
224 | #
|
---|
225 | # Stop if no revisions specified.
|
---|
226 | #
|
---|
227 | if test -z "${MY_REVISIONS}" -a "${MY_SCRIPT_NAME}" '!=' "backport-commit.sh"; then
|
---|
228 | echo "error: No revisions specified" 1>&2;
|
---|
229 | exit 2;
|
---|
230 | fi
|
---|