VirtualBox

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

Last change on this file since 83734 was 83680, checked in by vboxsync, 5 years ago

tools/bin/backport-*: Adding a --update-first option to update the branch before merging.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1# $Id: backport-common.sh 83680 2020-04-11 18:44:19Z 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
23MY_PRINTF=kmk_printf
24 MY_RM=kmk_rm
25 MY_SVN=svn
26 MY_SED=kmk_sed
27
28#
29# Functions.
30#
31BranchDirToName()
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
52#
53# Figure default branch given the script location.
54#
55MY_BRANCH_DEFAULT_DIR=`cd "${MY_SCRIPT_DIR}"; cd ../..; pwd -L`
56MY_BRANCH_DEFAULT=`BranchDirToName "${MY_BRANCH_DEFAULT_DIR}"`
57if test "${MY_BRANCH_DEFAULT}" = "trunk"; then
58 MY_TRUNK_DIR=${MY_BRANCH_DEFAULT_DIR}
59elif test -d "${MY_BRANCH_DEFAULT_DIR}/../../trunk"; then
60 MY_TRUNK_DIR=`cd "${MY_BRANCH_DEFAULT_DIR}"; cd ../../trunk; pwd -L`
61else
62 MY_TRUNK_DIR="^/trunk"
63fi
64
65
66#
67# Parse arguments.
68#
69MY_BRANCH_DIR=
70MY_BRANCH=
71MY_REVISIONS=
72MY_REVISION_COUNT=0
73MY_EXTRA_ARGS=
74MY_DEBUG=
75
76while test $# -ge 1;
77do
78 ARG=$1
79 shift
80 case "${ARG}" in
81 r[0-9][0-9]*)
82 MY_REV=`echo ${ARG} | "${MY_SED}" -e 's/^r//'`
83 if test -z "${MY_REVISIONS}"; then
84 MY_REVISIONS=${MY_REV}
85 else
86 MY_REVISIONS="${MY_REVISIONS} ${MY_REV}"
87 fi
88 MY_REVISION_COUNT=`${MY_EXPR} ${MY_REVISION_COUNT} + 1`
89 ;;
90
91 [0-9][0-9]*)
92 if test -z "${MY_REVISIONS}"; then
93 MY_REVISIONS=${ARG}
94 else
95 MY_REVISIONS="${MY_REVISIONS} ${ARG}"
96 fi
97 MY_REVISION_COUNT=`${MY_EXPR} ${MY_REVISION_COUNT} + 1`
98 ;;
99
100 --trunk-dir)
101 if test $# -eq 0; then
102 echo "error: missing --trunk-dir argument." 1>&2
103 exit 1;
104 fi
105 MY_TRUNK_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
106 shift
107 ;;
108
109 --branch-dir)
110 if test $# -eq 0; then
111 echo "error: missing --branch-dir argument." 1>&2
112 exit 1;
113 fi
114 MY_BRANCH_DIR=`echo "$1" | "${MY_SED}" -e 's|\\\|/|g'`
115 shift
116 ;;
117
118 --branch)
119 if test $# -eq 0; then
120 echo "error: missing --branch argument." 1>&2
121 exit 1;
122 fi
123 MY_BRANCH="$1"
124 shift
125 ;;
126
127 --first-rev|--first|-1)
128 MY_FIRST_REV=1
129 ;;
130
131 --update-first|--update|-u)
132 MY_UPDATE_FIRST=1
133 ;;
134
135 --extra)
136 if test $# -eq 0; then
137 echo "error: missing --extra argument." 1>&2
138 exit 1;
139 fi
140 MY_EXTRA_ARGS="${MY_EXTRA_ARGS} $1"
141 shift
142 ;;
143
144 --debug)
145 MY_DEBUG=1
146 ;;
147
148 # usage
149 --h*|-h*|-?|--?)
150 echo "usage: $0 [--trunk-dir <dir>] [--branch <ver>] [--branch-dir <dir>] [--extra <svn-arg>] \\"
151 echo " [--first-rev] [--update-first] rev1 [rev2..[revN]]]"
152 echo ""
153 echo "Options:"
154 echo " --trunk-dir <dir>"
155 echo " The source of the changeset being backported."
156 echo " --branch-dir <dir>"
157 echo " The backport destination directory. default: script location"
158 echo " --branch <ver>"
159 echo " The name of the branch being backported to. default: auto"
160 echo " --first-rev, --first, -1"
161 echo " Merge only: Check that the branch does not have any pending changes."
162 echo " --update-first, --update, -u"
163 echo " Merge only: Update the branch before merging."
164 echo " --extra <svn-arg>"
165 echo " Additional arguments to specify to SVN."
166 echo ""
167 exit 2;
168 ;;
169
170 *)
171 echo "syntax error: ${ARG}"
172 exit 2;
173 ;;
174 esac
175done
176
177if test -n "${MY_DEBUG}"; then
178 echo " MY_SCRIPT_DIR=${MY_SCRIPT_DIR}"
179 echo " MY_BRANCH_DIR=${MY_BRANCH_DIR}"
180 echo " MY_BRANCH=${MY_BRANCH}"
181 echo "MY_BRANCH_DEFAULT_DIR=${MY_BRANCH_DEFAULT_DIR}"
182 echo " MY_BRANCH_DEFAULT=${MY_BRANCH_DEFAULT}"
183 echo " MY_TRUNK_DIR=${MY_TRUNK_DIR}"
184 echo " MY_REVISIONS=${MY_REVISIONS}"
185fi
186
187#
188# Resolve branch variables.
189#
190if test -z "${MY_BRANCH_DIR}" -a -z "${MY_BRANCH}"; then
191 MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
192 MY_BRANCH=${MY_BRANCH_DEFAULT}
193elif test -n "${MY_BRANCH}" -a -z "${MY_BRANCH_DIR}"; then
194 MY_BRANCH_DIR=${MY_BRANCH_DEFAULT_DIR}
195elif test -z "${MY_BRANCH}" -a -n "${MY_BRANCH_DIR}"; then
196 MY_BRANCH=`BranchDirToName "${MY_BRANCH_DIR}"`
197 if test -z "${MY_BRANCH}" -o "${MY_BRANCH}" = "${MY_BRANCH_DIR}"; then
198 echo "error: Failed to guess branch name for: ${MY_BRANCH_DIR}" 1>&2
199 echo " Use --branch to specify it." 1>&2
200 exit 2;
201 fi
202fi
203if test "${MY_BRANCH}" = "trunk"; then
204 echo "error: script does not work with 'trunk' as the branch" 1>&2
205 exit 2;
206fi
207
208#
209# Stop if no revisions specified.
210#
211if test -z "${MY_REVISIONS}"; then
212 echo "error: No revisions specified" 1>&2;
213 exit 2;
214fi
215
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