Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Jan 2014 22:35:24 +0100
From:      Matthias Andree <mandree@FreeBSD.org>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/186256: PATCH: MFH speedups and drop-to-shell feature 
Message-ID:  <E1W8cn6-000DAv-2P@apollo.emma.line.org>
Resent-Message-ID: <201401292140.s0TLe0Hm069553@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         186256
>Category:       ports
>Synopsis:       PATCH: MFH speedups and drop-to-shell feature
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 29 21:40:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Matthias Andree
>Release:        FreeBSD 9.2-RELEASE-p3 amd64
>Organization:
>Environment:
System: FreeBSD apollo.emma.line.org 9.2-RELEASE-p3 FreeBSD 9.2-RELEASE-p3 #0: Sat Jan 11 03:25:02 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
The enclosed patch updates the Tools/scripts/mfh script a bit to use
proper quoting, use fewer svn invocations, and optionally drop to a
shell before committing, to manually fix up a botched merge.
svnserver can be overridden in the environment.
Finally, we use sh's trap builtin to make sure we always clean up.
	
>How-To-Repeat:
	
>Fix:

Apply this patch in the ports/Tools/scripts directory:

Index: mfh
===================================================================
--- ports/Tools/scripts/mfh~	(revision 341780)
+++ ports/Tools/scripts/mfh	(working copy)
@@ -27,15 +27,19 @@
 #
 # MAINTAINER=	portmgr@FreeBSD.org
 
-set -e
+set -eu
 
+LF=$(printf '\nX')
+LF=${LF%X}
+IFS="${LF}"
+
 err() {
-	echo $@ >&2
+	echo "$@" >&2
 	exit 1
 }
 
 clean() {
-	rm -rf ${dir}
+	rm -rf "${dir}"
 	exit 1
 }
 
@@ -44,7 +48,7 @@
 
 	answer=x
 	while [ "${answer}" != "y" -a "${answer}" != "n" ] ; do
-		read -p "${question} [yn] " answer
+		read -p "${question} [y/n] " answer
 	done
 
 	[ "${answer}" = "y" ] && return 0
@@ -51,7 +55,7 @@
 	return 1
 }
 
-[ $# -ne 2 ] && err "Takes 2 arguments: <branch> <revnumber>"
+[ $# -ne 2 ] && err "$(basename $0) requires 2 arguments: <branch> <revnumber>"
 branch=$1
 rev=${2##r} # remove a leading "r"
 case ${rev} in
@@ -58,7 +62,7 @@
 ''|*[!0-9]*) err "revision should be a number" ;;
 esac
 
-svnserver="svn.FreeBSD.org"
+: ${svnserver:="svn.FreeBSD.org"}
 
 if [ -n "$(type svn 2>/dev/null)" ]; then
 	svn=svn
@@ -65,16 +69,16 @@
 elif [ -n "$(type svnlite 2>/dev/null)" ]; then
 	svn=svnlite
 else
-	err "svn(1) and svnlite(1) not found. please install devel/subversion"
+	err "Neither svn(1) nor svnlite(1) found. Please install devel/subversion."
 fi
 
-
-dir=$(mktemp -d /tmp/merge.XXX)
-cd ${dir}
-${svn} co --depth=empty svn+ssh://${svnserver}/ports/branches/${branch}
+trap "rc=\$? ; rm -rf \"\${dir}\" ; exit \$rc" EXIT
+dir=$(mktemp -d /tmp/merge.XXXXXX)
+cd "${dir}"
+"${svn}" co --depth=empty svn+ssh://${svnserver}/ports/branches/"${branch}"
 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
+for f in $("${svn}" diff --summarize -c ${rev} svn://${svnserver}/ports/head); do
 	case ${f} in
 	*/*) ;;
 	*)continue;;
@@ -81,19 +85,26 @@
 	esac
 	f=${f#*/ports/head/}
 	f=${f%/*}
-	filelist="${filelist}\n${f}"
+	filelist="${filelist}${LF}${f}"
 done
-filelist=$(echo -e ${filelist} | sort -u)
+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' >> commit.txt
-for f in ${filelist}; do
-	${svn} up --parents ${branch}/${f}
-done
-${svn} up --quiet ${branch}
-${svn} merge -c r${rev} ^/head/ ${branch}
-${svn} up --quiet ${branch}
-${svn} diff ${branch}
-ask "Do you want to commit?" || clean
+"${svn}" log -r${rev} svn://${svnserver}/ports/head | sed '1,2d;$d;/^MFH:/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? (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
+)
 ${EDITOR:-vi} commit.txt
-${svn} ci -F commit.txt ${branch}
-rm -rf ${dir}
+"${svn}" ci -F commit.txt "${branch}"
+rm -rf "${dir}"
+trap - 0
	


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1W8cn6-000DAv-2P>