2013-12-19 14:43:58 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# mfh - Merge from head to a given branch
|
|
|
|
# Copyright 2013 Baptiste Daroussin
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# MAINTAINER= portmgr@FreeBSD.org
|
|
|
|
|
2014-06-25 19:04:31 +00:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
LF=$(printf '\nX')
|
|
|
|
LF=${LF%X}
|
|
|
|
IFS="${LF}"
|
2013-12-19 14:43:58 +00:00
|
|
|
|
|
|
|
err() {
|
2014-06-25 19:04:31 +00:00
|
|
|
echo "$@" >&2
|
2013-12-19 14:43:58 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
2014-06-25 19:04:31 +00:00
|
|
|
rm -rf "${dir}"
|
2013-12-19 14:43:58 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ask() {
|
|
|
|
question=${1}
|
|
|
|
|
|
|
|
answer=x
|
|
|
|
while [ "${answer}" != "y" -a "${answer}" != "n" ] ; do
|
2014-06-25 19:04:31 +00:00
|
|
|
read -p "${question} [y/n] " answer
|
2013-12-19 14:43:58 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
[ "${answer}" = "y" ] && return 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-01-03 18:33:19 +00:00
|
|
|
: ${svnserver:="svn+ssh://repo.FreeBSD.org"}
|
|
|
|
|
|
|
|
if [ -n "$(type svn 2>/dev/null)" ]; then
|
|
|
|
svn=svn
|
|
|
|
elif [ -n "$(type svnlite 2>/dev/null)" ]; then
|
|
|
|
svn=svnlite
|
|
|
|
else
|
|
|
|
err "Neither svn(1) nor svnlite(1) found. Please install devel/subversion."
|
|
|
|
fi
|
|
|
|
|
|
|
|
latest_branch=$("${svn}" ls ${svnserver}/ports/branches/|sed -ne '/^2.*Q./s|/$||p'|tail -1)
|
|
|
|
|
|
|
|
[ $# -lt 1 ] && err "$(basename $0) requires at least 1 arguments: [<branch>] <revnumber> [<revnumber>...]"
|
2013-12-19 14:43:58 +00:00
|
|
|
branch=$1
|
2017-01-03 18:33:19 +00:00
|
|
|
|
|
|
|
# I sure hope by 2030 we'll be doing something else. Yes, famous last words.
|
|
|
|
if expr ${branch} : '20[12][0-9]Q[1-4]' > /dev/null; then
|
|
|
|
shift
|
|
|
|
if [ ${latest_branch} != ${branch} ]; then
|
|
|
|
ask "/!\\ The latest branch is ${latest_branch}, do you really want to commit to ${branch}?" || exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
branch=${latest_branch}
|
|
|
|
fi
|
|
|
|
|
2015-09-07 12:23:51 +00:00
|
|
|
revs=""
|
|
|
|
for rev in $@
|
|
|
|
do
|
|
|
|
rev=${rev##r} # remove a leading "r"
|
|
|
|
case ${rev} in
|
2015-12-18 15:29:38 +00:00
|
|
|
''|*[!-0-9]*) err "revision \"${rev}\" should be a number" ;;
|
2015-09-07 12:23:51 +00:00
|
|
|
esac
|
|
|
|
done
|
2013-12-19 14:43:58 +00:00
|
|
|
|
2014-01-08 22:43:21 +00:00
|
|
|
|
2014-06-25 19:04:31 +00:00
|
|
|
trap "rc=\$? ; rm -rf \"\${dir}\" ; exit \$rc" EXIT
|
|
|
|
dir=$(mktemp -d /tmp/merge.XXXXXX)
|
|
|
|
cd "${dir}"
|
2015-09-20 20:56:59 +00:00
|
|
|
"${svn}" co --depth=empty ${svnserver}/ports/branches/"${branch}"
|
2013-12-19 14:43:58 +00:00
|
|
|
filelist=""
|
2015-09-07 12:23:51 +00:00
|
|
|
|
|
|
|
echo -n "MFH:" > commit.txt
|
|
|
|
for rev in $@
|
|
|
|
do
|
|
|
|
rev=${rev##r}
|
|
|
|
echo -n " r${rev}" >> commit.txt
|
|
|
|
done
|
|
|
|
echo >> commit.txt
|
|
|
|
for rev in $@
|
|
|
|
do
|
|
|
|
rev=${rev##r}
|
2015-09-20 20:56:59 +00:00
|
|
|
for f in $("${svn}" diff --summarize -c r${rev} ${svnserver}/ports/head); do
|
2015-09-07 12:23:51 +00:00
|
|
|
case ${f} in
|
|
|
|
*/*) ;;
|
|
|
|
*)continue;;
|
|
|
|
esac
|
|
|
|
f=${f#*/ports/head/}
|
|
|
|
f=${f%/*}
|
|
|
|
filelist="${filelist}${LF}${f}"
|
|
|
|
done
|
2015-12-18 15:29:38 +00:00
|
|
|
"${svn}" log -r${rev##-} ${svnserver}/ports/head | sed '1,2d;$d;/^MFH:/d' \
|
2015-09-07 12:23:51 +00:00
|
|
|
| sed '$d' >> commit.txt
|
2013-12-19 14:43:58 +00:00
|
|
|
done
|
2014-06-25 19:04:31 +00:00
|
|
|
filelist=$(printf '%s\n' "${filelist}" | sort -u)
|
|
|
|
"${svn}" up --parents $(printf '%s\n' $filelist \
|
|
|
|
| sed "s}^}${branch}/}")
|
|
|
|
"${svn}" up --quiet "${branch}"
|
2015-09-07 12:23:51 +00:00
|
|
|
for rev in $@
|
|
|
|
do
|
|
|
|
rev=${rev##r}
|
|
|
|
"${svn}" merge -c r${rev} ^/head/ "${branch}"
|
|
|
|
done
|
2014-06-25 19:04:31 +00:00
|
|
|
"${svn}" up --quiet "${branch}"
|
|
|
|
"${svn}" status "${branch}"
|
|
|
|
"${svn}" diff "${branch}"
|
2016-08-15 10:01:58 +00:00
|
|
|
echo "All the merge work was done in ${dir}/${branch}."
|
2014-06-25 19:04:31 +00:00
|
|
|
ask "Do you want to commit? (no = start a shell)" || (
|
|
|
|
echo "Dropping you to a shell so you can investigate. Exit the shell to resume this script."
|
|
|
|
cd "${branch}"
|
|
|
|
pwd
|
|
|
|
su -m $(id -un) || :
|
|
|
|
ask "Do you want to commit now? (no = clean up and abort)" || clean
|
|
|
|
)
|
2016-03-15 16:52:10 +00:00
|
|
|
echo >> commit.txt
|
|
|
|
echo "Approved by: " >> commit.txt
|
2013-12-19 14:43:58 +00:00
|
|
|
${EDITOR:-vi} commit.txt
|
2014-06-25 19:04:31 +00:00
|
|
|
"${svn}" ci -F commit.txt "${branch}"
|
|
|
|
rm -rf "${dir}"
|
|
|
|
trap - 0
|