VirtualBox

source: vbox/trunk/tools/bin/backport-commit.sh@ 100235

Last change on this file since 100235 was 98105, checked in by vboxsync, 2 years ago

tools/bin: Use correct hash-bang so zsh/macOS doesn't give us a 'sh' w/o the support for '-n' option in the echo command.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1#!/usr/bin/env kmk_ash
2# $Id: backport-commit.sh 98105 2023-01-17 15:17:40Z vboxsync $
3## @file
4# Script for committing a backport from trunk.
5#
6
7#
8# Copyright (C) 2020-2023 Oracle and/or its affiliates.
9#
10# This file is part of VirtualBox base platform packages, as
11# available from https://www.virtualbox.org.
12#
13# This program is free software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License
15# as published by the Free Software Foundation, in version 3 of the
16# License.
17#
18# This program is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, see <https://www.gnu.org/licenses>.
25#
26# SPDX-License-Identifier: GPL-3.0-only
27#
28
29#
30# Determin script dir so we can source the common bits.
31#
32MY_SED=kmk_sed
33MY_SCRIPT_DIR=`echo "$0" | "${MY_SED}" -e 's|\\\|/|g' -e 's|^\(.*\)/[^/][^/]*$|\1|'` # \ -> / is for windows.
34if test "${MY_SCRIPT_DIR}" = "$0"; then
35 MY_SCRIPT_DIR=`pwd -L`
36else
37 MY_SCRIPT_DIR=`cd "${MY_SCRIPT_DIR}"; pwd -L` # pwd is built into kmk_ash.
38fi
39
40#
41# This does a lot.
42#
43MY_SCRIPT_NAME="backport-commit.sh"
44. "${MY_SCRIPT_DIR}/backport-common.sh"
45
46#
47# If no revisions was given, try figure it out from the svn:merge-info
48# property.
49#
50if test -z "${MY_REVISIONS}"; then
51 MY_REV_TMP=backport-revisions.tmp
52 if ! svn di --properties-only --depth empty "${MY_BRANCH_DIR}" > "${MY_REV_TMP}"; then
53 echo "error: failed to get revisions from svn:mergeinfo (svn)"
54 exit 1;
55 fi
56 for MY_REV in $("${MY_SED}" -e '/ *Merged \//!d' -e "s/^ [^:]*:[r]*//" -e 's/,[r]*/ /g' "${MY_REV_TMP}");
57 do
58 case "${MY_REV}" in
59 [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])
60 AddRevision "${MY_REV}"
61 ;;
62 [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])
63 AddRevisionRange "${MY_REV}"
64 ;;
65
66 *) echo "error: failed to get revisions from svn:mergeinfo - does not grok: ${MY_ARG}"
67 exit 1;;
68 esac
69 done
70 "${MY_RM}" -f -- "${MY_REV_TMP}"
71 if test -z "${MY_REVISIONS}"; then
72 echo "error: No backported revisions found";
73 exit 1;
74 fi
75 echo "info: Detected revisions: ${MY_REVISIONS}"
76fi
77
78#
79# Generate the commit message into MY_MSG_FILE.
80#
81test -n "${MY_DEBUG}" && echo "MY_REVISIONS=${MY_REVISIONS}"
82MY_MSG_FILE=backport-commit.txt
83MY_TMP_FILE=backport-commit.tmp
84
85if test "${MY_REVISION_COUNT}" -eq 1; then
86 # Single revision, just prefix the commit message.
87 MY_REV=`echo ${MY_REVISIONS}` # strip leading space
88 echo -n "${MY_BRANCH}: Backported r${MY_REV}: " > "${MY_MSG_FILE}"
89 if ! "${MY_SVN}" log "-r${MY_REV}" "${MY_TRUNK_DIR}" > "${MY_TMP_FILE}"; then
90 echo "error: failed to get log entry for revision ${MY_REV}"
91 exit 1;
92 fi
93 if ! "${MY_SED}" -e '1d;2d;3d;$d' --append "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
94 echo "error: failed to get log entry for revision ${MY_REV} (sed failed)"
95 exit 1;
96 fi
97else
98 # First line.
99 echo -n "${MY_BRANCH}: Backported" > "${MY_MSG_FILE}"
100 MY_COUNTER=0
101 for MY_REV in ${MY_REVISIONS};
102 do
103 if test ${MY_COUNTER} -eq 0; then
104 echo -n " r${MY_REV}" >> "${MY_MSG_FILE}"
105 else
106 echo -n " r${MY_REV}" >> "${MY_MSG_FILE}"
107 fi
108 MY_COUNTER=`"${MY_EXPR}" ${MY_COUNTER} + 1`
109 done
110 echo "." >> "${MY_MSG_FILE}"
111 echo "" >> "${MY_MSG_FILE}"
112
113 # One bullet with the commit text.
114 for MY_REV in ${MY_REVISIONS};
115 do
116 echo -n "* r${MY_REV}: " >> "${MY_MSG_FILE}"
117 if ! "${MY_SVN}" log "-r${MY_REV}" "${MY_TRUNK_DIR}" > "${MY_TMP_FILE}"; then
118 echo "error: failed to get log entry for revision ${MY_REV}"
119 exit 1;
120 fi
121 if ! "${MY_SED}" -e '1d;2d;3d;$d' --append "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
122 echo "error: failed to get log entry for revision ${MY_REV} (sed failed)"
123 exit 1;
124 fi
125 done
126
127 # This is a line ending hack for windows hosts.
128 if "${MY_SED}" -e 's/1/1/g' --output-text "${MY_TMP_FILE}" "${MY_MSG_FILE}" \
129 && "${MY_SED}" -e 's/1/1/g' --output-text "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
130 :
131 else
132 echo "error: SED failed to clean up commit message line-endings."
133 exit 1;
134 fi
135fi
136"${MY_RM}" -f -- "${MY_TMP_FILE}"
137
138#
139# Do the committing.
140#
141if [ -n "${MY_SHOW_DIFF}" ]; then
142 echo "***"
143 echo "*** Diff:"
144 "${MY_SVN}" diff --internal-diff
145 echo "*** end diff ***"
146 echo "***"
147 echo ""
148fi
149echo "***"
150echo "*** Commit message:"
151"${MY_CAT}" "${MY_MSG_FILE}"
152echo "*** end commit message ***"
153echo "***"
154IFS=`"${MY_PRINTF}" " \t\r\n"` # windows needs \r for proper 'read' operation.
155for MY_IGNORE in 1 2 3; do
156 read -p "*** Does the above commit message look okay (y/n)?" MY_ANSWER
157 case "${MY_ANSWER}" in
158 y|Y|[yY][eE][sS])
159 if "${MY_SVN}" commit -F "${MY_MSG_FILE}" "${MY_BRANCH_DIR}"; then
160 "${MY_RM}" -f -- "${MY_MSG_FILE}"
161
162 #
163 # Update the branch so we don't end up with mixed revisions.
164 #
165 echo "***"
166 echo "*** Updating branch dir..."
167 "${MY_SVN}" up "${MY_BRANCH_DIR}"
168 exit 0
169 fi
170 echo "error: commit failed" 1>&2
171 exit 1
172 ;;
173 n|N|[nN][oO])
174 exit 1
175 ;;
176 *)
177 echo
178 echo "Please answer 'y' or 'n'... (MY_ANSWER=${MY_ANSWER})"
179 esac
180done
181exit 1;
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