VirtualBox

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

Last change on this file since 85618 was 85586, checked in by vboxsync, 4 years ago

Forward ported 139660 from 6.1: backport-commit.sh: Try guess the revisions being backported from svn:mergeinfo if none given.

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