Skip to content

Instantly share code, notes, and snippets.

@lwhsu
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwhsu/11262190 to your computer and use it in GitHub Desktop.
Save lwhsu/11262190 to your computer and use it in GitHub Desktop.
#!/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
set -eu
LF=$(printf '\nX')
LF=${LF%X}
IFS="${LF}"
err() {
echo "$@" >&2
exit 1
}
clean() {
rm -rf "${dir}"
exit 1
}
ask() {
question=${1}
answer=x
while [ "${answer}" != "y" -a "${answer}" != "n" ] ; do
read -p "${question} [y/n] " answer
done
[ "${answer}" = "y" ] && return 0
return 1
}
[ $# -ne 2 ] && err "$(basename $0) requires 2 arguments: <branch> <revnumber>"
branch=$1
rev=${2##r} # remove a leading "r"
case ${rev} in
''|*[!0-9]*) err "revision should be a number" ;;
esac
: ${svnserver:="svn.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
dir=/tmp/merge.`date +%Y%m%d`
mkdir -p "${dir}"
cd "${dir}"
if [ ! -d ${branch} ]; then
${svn} co --depth=empty svn+ssh://${svnserver}/ports/branches/${branch}
fi
filelist=""
# svn:// is faster than svn+ssh://. Use it wherever it's possible.
for f in $("${svn}" diff --summarize -c ${rev} svn://${svnserver}/ports/head); do
case ${f} in
*/*) ;;
*)continue;;
esac
f=${f#*/ports/head/}
f=${f%/*}
filelist="${filelist}${LF}${f}"
done
filelist=$(printf '%s\n' "${filelist}" | sort -u)
echo "MFH: r${rev}" >> commit.txt
"${svn}" log -r${rev} svn://${svnserver}/ports/head | sed '1,2d;$d;/^MFH:/d' \
| sed '$d' >> commit.txt
"${svn}" up --parents $(printf '%s\n' $filelist \
| sed "s}^}${branch}/}")
"${svn}" up --quiet "${branch}"
"${svn}" merge -c r${rev} ^/head/ "${branch}"
"${svn}" up --quiet "${branch}"
"${svn}" status "${branch}"
"${svn}" diff "${branch}"
#ask "Do you want to commit?" || clean
#${EDITOR:-vi} commit.txt
#${svn} ci -F commit.txt ${branch}
#rm -rf ${dir}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment