1 | # !kmk_ash
|
---|
2 | # $Id: backport-commit.sh 84269 2020-05-12 09:18:29Z 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 | #
|
---|
22 | MY_SED=kmk_sed
|
---|
23 | MY_SCRIPT_DIR=`echo "$0" | "${MY_SED}" -e 's|\\\|/|g' -e 's|^\(.*\)/[^/][^/]*$|\1|'` # \ -> / is for windows.
|
---|
24 | if test "${MY_SCRIPT_DIR}" = "$0"; then
|
---|
25 | MY_SCRIPT_DIR=`pwd -L`
|
---|
26 | else
|
---|
27 | MY_SCRIPT_DIR=`cd "${MY_SCRIPT_DIR}"; pwd -L` # pwd is built into kmk_ash.
|
---|
28 | fi
|
---|
29 |
|
---|
30 | #
|
---|
31 | # This does a lot.
|
---|
32 | #
|
---|
33 | MY_SCRIPT_NAME="backport-commit.sh"
|
---|
34 | . "${MY_SCRIPT_DIR}/backport-common.sh"
|
---|
35 |
|
---|
36 | #
|
---|
37 | # Generate the commit message into MY_MSG_FILE.
|
---|
38 | #
|
---|
39 | test -n "${MY_DEBUG}" && echo "MY_REVISIONS=${MY_REVISIONS}"
|
---|
40 | MY_MSG_FILE=backport-commit.txt
|
---|
41 | MY_TMP_FILE=backport-commit.tmp
|
---|
42 |
|
---|
43 | if test "${MY_REVISION_COUNT}" -eq 1; then
|
---|
44 | # Single revision, just prefix the commit message.
|
---|
45 | MY_REV=`echo ${MY_REVISIONS}` # strip leading space
|
---|
46 | echo -n "${MY_BRANCH}: Backported r${MY_REV}: " > "${MY_MSG_FILE}"
|
---|
47 | if ! "${MY_SVN}" log "-r${MY_REV}" "${MY_TRUNK_DIR}" > "${MY_TMP_FILE}"; then
|
---|
48 | echo "error: failed to get log entry for revision ${MY_REV}"
|
---|
49 | exit 1;
|
---|
50 | fi
|
---|
51 | if ! "${MY_SED}" -e '1d;2d;3d;$d' --append "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
|
---|
52 | echo "error: failed to get log entry for revision ${MY_REV} (sed failed)"
|
---|
53 | exit 1;
|
---|
54 | fi
|
---|
55 | else
|
---|
56 | # First line.
|
---|
57 | echo -n "${MY_BRANCH}: Backported" > "${MY_MSG_FILE}"
|
---|
58 | MY_COUNTER=0
|
---|
59 | for MY_REV in ${MY_REVISIONS};
|
---|
60 | do
|
---|
61 | if test ${MY_COUNTER} -eq 0; then
|
---|
62 | echo -n " r${MY_REV}" >> "${MY_MSG_FILE}"
|
---|
63 | else
|
---|
64 | echo -n " r${MY_REV}" >> "${MY_MSG_FILE}"
|
---|
65 | fi
|
---|
66 | MY_COUNTER=`"${MY_EXPR}" ${MY_COUNTER} + 1`
|
---|
67 | done
|
---|
68 | echo "." >> "${MY_MSG_FILE}"
|
---|
69 | echo "" >> "${MY_MSG_FILE}"
|
---|
70 |
|
---|
71 | # One bullet with the commit text.
|
---|
72 | for MY_REV in ${MY_REVISIONS};
|
---|
73 | do
|
---|
74 | echo -n "* r${MY_REV}: " >> "${MY_MSG_FILE}"
|
---|
75 | if ! "${MY_SVN}" log "-r${MY_REV}" "${MY_TRUNK_DIR}" > "${MY_TMP_FILE}"; then
|
---|
76 | echo "error: failed to get log entry for revision ${MY_REV}"
|
---|
77 | exit 1;
|
---|
78 | fi
|
---|
79 | if ! "${MY_SED}" -e '1d;2d;3d;$d' --append "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
|
---|
80 | echo "error: failed to get log entry for revision ${MY_REV} (sed failed)"
|
---|
81 | exit 1;
|
---|
82 | fi
|
---|
83 | done
|
---|
84 |
|
---|
85 | # This is a line ending hack for windows hosts.
|
---|
86 | if "${MY_SED}" -e 's/1/1/g' --output-text "${MY_TMP_FILE}" "${MY_MSG_FILE}" \
|
---|
87 | && "${MY_SED}" -e 's/1/1/g' --output-text "${MY_MSG_FILE}" "${MY_TMP_FILE}"; then
|
---|
88 | :
|
---|
89 | else
|
---|
90 | echo "error: SED failed to clean up commit message line-endings."
|
---|
91 | exit 1;
|
---|
92 | fi
|
---|
93 | fi
|
---|
94 | "${MY_RM}" -f -- "${MY_TMP_FILE}"
|
---|
95 |
|
---|
96 | #
|
---|
97 | # Do the committing.
|
---|
98 | #
|
---|
99 | if [ -n "${MY_SHOW_DIFF}" ]; then
|
---|
100 | echo "***"
|
---|
101 | echo "*** Diff:"
|
---|
102 | "${MY_SVN}" diff --internal-diff
|
---|
103 | echo "*** end diff ***"
|
---|
104 | echo "***"
|
---|
105 | echo ""
|
---|
106 | fi
|
---|
107 | echo "***"
|
---|
108 | echo "*** Commit message:"
|
---|
109 | "${MY_CAT}" "${MY_MSG_FILE}"
|
---|
110 | echo "*** end commit message ***"
|
---|
111 | echo "***"
|
---|
112 | IFS=`"${MY_PRINTF}" " \t\r\n"` # windows needs \r for proper 'read' operation.
|
---|
113 | for MY_IGNORE in 1 2 3; do
|
---|
114 | read -p "*** Does the above commit message look okay (y/n)?" MY_ANSWER
|
---|
115 | case "${MY_ANSWER}" in
|
---|
116 | y|Y|[yY][eE][sS])
|
---|
117 | if "${MY_SVN}" commit -F "${MY_MSG_FILE}" "${MY_BRANCH_DIR}"; then
|
---|
118 | "${MY_RM}" -f -- "${MY_MSG_FILE}"
|
---|
119 |
|
---|
120 | #
|
---|
121 | # Update the branch so we don't end up with mixed revisions.
|
---|
122 | #
|
---|
123 | echo "***"
|
---|
124 | echo "*** Updating branch dir..."
|
---|
125 | "${MY_SVN}" up "${MY_BRANCH_DIR}"
|
---|
126 | exit 0
|
---|
127 | fi
|
---|
128 | echo "error: commit failed" 1>&2
|
---|
129 | exit 1
|
---|
130 | ;;
|
---|
131 | n|N|[nN][oO])
|
---|
132 | exit 1
|
---|
133 | ;;
|
---|
134 | *)
|
---|
135 | echo
|
---|
136 | echo "Please answer 'y' or 'n'... (MY_ANSWER=${MY_ANSWER})"
|
---|
137 | esac
|
---|
138 | done
|
---|
139 | exit 1;
|
---|