[98105] | 1 | #!/usr/bin/env kmk_ash
|
---|
[83611] | 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 | #
|
---|
[98103] | 8 | # Copyright (C) 2020-2023 Oracle and/or its affiliates.
|
---|
[83611] | 9 | #
|
---|
[96407] | 10 | # This file is part of VirtualBox base platform packages, as
|
---|
| 11 | # available from https://www.virtualbox.org.
|
---|
[83611] | 12 | #
|
---|
[96407] | 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 | #
|
---|
[83611] | 28 |
|
---|
| 29 | #
|
---|
| 30 | # Determin script dir so we can source the common bits.
|
---|
| 31 | #
|
---|
| 32 | MY_SED=kmk_sed
|
---|
| 33 | MY_SCRIPT_DIR=`echo "$0" | "${MY_SED}" -e 's|\\\|/|g' -e 's|^\(.*\)/[^/][^/]*$|\1|'` # \ -> / is for windows.
|
---|
| 34 | if test "${MY_SCRIPT_DIR}" = "$0"; then
|
---|
| 35 | MY_SCRIPT_DIR=`pwd -L`
|
---|
| 36 | else
|
---|
| 37 | MY_SCRIPT_DIR=`cd "${MY_SCRIPT_DIR}"; pwd -L` # pwd is built into kmk_ash.
|
---|
| 38 | fi
|
---|
| 39 |
|
---|
| 40 | #
|
---|
| 41 | # This does a lot.
|
---|
| 42 | #
|
---|
| 43 | MY_SCRIPT_NAME="backport-commit.sh"
|
---|
| 44 | . "${MY_SCRIPT_DIR}/backport-common.sh"
|
---|
| 45 |
|
---|
| 46 | #
|
---|
[85586] | 47 | # If no revisions was given, try figure it out from the svn:merge-info
|
---|
| 48 | # property.
|
---|
| 49 | #
|
---|
| 50 | if 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])
|
---|
[85668] | 63 | AddRevisionRange "${MY_REV}"
|
---|
[85586] | 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}"
|
---|
| 76 | fi
|
---|
| 77 |
|
---|
| 78 | #
|
---|
[83611] | 79 | # Generate the commit message into MY_MSG_FILE.
|
---|
| 80 | #
|
---|
| 81 | test -n "${MY_DEBUG}" && echo "MY_REVISIONS=${MY_REVISIONS}"
|
---|
| 82 | MY_MSG_FILE=backport-commit.txt
|
---|
| 83 | MY_TMP_FILE=backport-commit.tmp
|
---|
| 84 |
|
---|
| 85 | if 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
|
---|
| 97 | else
|
---|
| 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}"
|
---|
[83667] | 111 | echo "" >> "${MY_MSG_FILE}"
|
---|
[83611] | 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}"
|
---|
[83667] | 117 | if ! "${MY_SVN}" log "-r${MY_REV}" "${MY_TRUNK_DIR}" > "${MY_TMP_FILE}"; then
|
---|
[83611] | 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
|
---|
[83667] | 126 |
|
---|
| 127 | # This is a line ending hack for windows hosts.
|
---|
[83903] | 128 | if "${MY_SED}" -e 's/1/1/g' --output-text "${MY_TMP_FILE}" "${MY_MSG_FILE}" \
|
---|
[83667] | 129 | && "${MY_SED}" -e 's/1/1/g' --output-text "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
|
---|
[83904] | 130 | :
|
---|
[83667] | 131 | else
|
---|
| 132 | echo "error: SED failed to clean up commit message line-endings."
|
---|
| 133 | exit 1;
|
---|
| 134 | fi
|
---|
[83611] | 135 | fi
|
---|
| 136 | "${MY_RM}" -f -- "${MY_TMP_FILE}"
|
---|
| 137 |
|
---|
| 138 | #
|
---|
| 139 | # Do the committing.
|
---|
| 140 | #
|
---|
[84269] | 141 | if [ -n "${MY_SHOW_DIFF}" ]; then
|
---|
| 142 | echo "***"
|
---|
| 143 | echo "*** Diff:"
|
---|
| 144 | "${MY_SVN}" diff --internal-diff
|
---|
| 145 | echo "*** end diff ***"
|
---|
| 146 | echo "***"
|
---|
| 147 | echo ""
|
---|
| 148 | fi
|
---|
[83611] | 149 | echo "***"
|
---|
| 150 | echo "*** Commit message:"
|
---|
| 151 | "${MY_CAT}" "${MY_MSG_FILE}"
|
---|
[83667] | 152 | echo "*** end commit message ***"
|
---|
[83611] | 153 | echo "***"
|
---|
| 154 | IFS=`"${MY_PRINTF}" " \t\r\n"` # windows needs \r for proper 'read' operation.
|
---|
| 155 | for 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
|
---|
[83678] | 170 | echo "error: commit failed" 1>&2
|
---|
[83611] | 171 | exit 1
|
---|
| 172 | ;;
|
---|
| 173 | n|N|[nN][oO])
|
---|
| 174 | exit 1
|
---|
| 175 | ;;
|
---|
| 176 | *)
|
---|
[83667] | 177 | echo
|
---|
[83611] | 178 | echo "Please answer 'y' or 'n'... (MY_ANSWER=${MY_ANSWER})"
|
---|
| 179 | esac
|
---|
| 180 | done
|
---|
| 181 | exit 1;
|
---|