Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Jun 2000 07:49:30 -0400 (EDT)
From:      Trevor Johnson <trevor@jpj.net>
To:        Satoshi Asami <asami@freebsd.org>, ports@freebsd.org
Subject:   proposal:  update-patches
Message-ID:  <Pine.BSI.4.21.0006300730580.16570-100000@blues.jpj.net>

next in thread | raw e-mail | index | archive | help
This is something written by Marc Espie for OpenBSD.  Christian Weisgerber
pointed it out to me.

Suppose you're making a new port, and you've edited some files in WRKSRC,
saving the originals with a .orig extension.  By doing "make
update-patches" you can (with this change) generate the patches.  
Furthermore, the generated patches are--apart from slight munging--named
according to the names of the files and directories to which they
correspond.  You can tell what files were changed just by looking at the
names of the patches.

Now suppose you're working on an existing port, which has patches with the
unfortunate patch-aa, patch-ab names.  You edit some files which were
already patched, then do "make update-patches".  The new changes are saved
in patches/ under the same names, while the old patches are moved to
patches/patch-aa and so forth.

The original version of this would bring up an editor after generating the
patches:

    @toedit=`WRKDIST=${WRKDIST} PATCHDIR=${PATCHDIR} PATCH_LIST=${PATCH_LIST} \
            DIFF_ARGS=${DIFF_ARGS} DISTORIG=${DISTORIG} \
            /bin/sh ${PORTSDIR}/infrastructure/build/update-patches`; \
    case $$toedit in "");; \
    *) read i?'edit patches: '; \
    cd ${PATCHDIR} && $${VISUAL:-$${EDIT:-/usr/bin/vi}} $$toedit;; esac

I didn't see how to get that working on FreeBSD, so I omitted it.

Here's the script and the target in bsd.port.mk:

diff -ruN Mk.orig/bsd.port.mk Mk/bsd.port.mk
--- Mk.orig/bsd.port.mk	Mon Jun 19 20:29:55 2000
+++ Mk/bsd.port.mk	Fri Jun 30 10:15:40 2000
@@ -2163,6 +2163,13 @@
 .endif
 .endif
 
+# Update patches.
+
+update-patches:
+	@toedit=`WRKDIST=${WRKSRC} PATCHDIR=${PATCHDIR} PATCH_LIST=${PATCHDIR}/patch-* \
+		DIFF_ARGS=${DIFF_ARGS} DISTORIG=${WRKSRC} \
+		/bin/sh ${PORTSDIR}/Tools/scripts/update-patches`;
+
 # Checksumming utilities
 
 .if !target(makesum)
diff -ruN Tools.orig/scripts/update-patches Tools/scripts/update-patches
--- Tools.orig/scripts/update-patches	Thu Jan  1 00:00:00 1970
+++ Tools/scripts/update-patches	Fri Jun 30 10:11:50 2000
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+# $OpenBSD: update-patches,v 1.3 2000/06/09 17:08:37 espie Exp $
+# Copyright (c) 2000
+# Marc Espie.  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 code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Neither the name of OpenBSD nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY ITS AUTHOR AND THE OpenBSD project ``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 REGENTS 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.
+
+# Find out all .orig files and strip the name to what diff will use
+cd $WRKDIST && find . -type f -name '*.orig' | fgrep -v $DISTORIG | \
+sed -e "s,^./\(.*\)\.orig\$,\1," | {
+while read file 
+do
+    echo 1>&2 "Processing $file"
+    # look in patchdir for an existing patchfile matching this
+    mkdir -p $PATCHDIR
+    cd $PATCHDIR
+    for i in ${PATCH_LIST}
+    do
+	# Ignore non-files, or old backup
+	[ -f $i ] || continue
+	case $i in \
+	*.orig|*.rej|*~) ;;
+	*) # Patch found. Is this the one ?
+	    if grep "^--- $file.orig" $i >/dev/null
+	    then
+		accounted="$accounted $i"
+		# found it, splice before diff part with diff
+		esc=`echo $file | sed -e 's,/,\\\\/,g'`
+		{ sed -e "/^--- $esc.orig/,\$ d" <$i
+		    (cd $WRKDIST && diff ${DIFF_ARGS} -u $file.orig $file) } >$i.new
+		# did it change ? mark it as changed
+		if diff ${DIFF_ARGS} -u --ignore-matching-lines="^--- $file.orig	.*" \
+		    --ignore-matching-lines="^+++ $file	.*" $i $i.new 1>&2
+		then
+		    rm $i.new
+		else
+		    echo 1>&2 "Patch $i for $file updated"
+		    mv $i $i.orig
+		    mv $i.new $i
+		    edit="$edit $i"
+		fi
+		continue 2
+	    fi;;
+	esac
+    done
+    # Build a sensible name for the patch file
+    patchname=patch-`echo $file|sed -e s,[/.],_,g`
+    echo 1>&2 "No patch-* found for $file, creating $patchname"
+    { (cd $WRKDIST && diff ${DIFF_ARGS} -u $file.orig $file) } >$patchname
+    edit="$edit $patchname"
+    accounted="$accounted $patchname"
+done
+
+# Verify all patches accounted for
+for i in *
+do
+    [ -f $i ] || continue
+    case $i in \
+    *.orig|*.rej|*~) ;;
+    *)
+	for j in $accounted 
+	do
+	    if [ $j = $i ]
+	    then
+		continue 2
+	    fi
+	done
+	echo 1>&2 "*** Patch $i not accounted for.";;
+    esac
+done
+
+# Check for $Id: update-patches,v 1.3 2000/06/09 17:08:37 espie Exp $ and similar bugs in all those patch files.
+for i in $accounted
+do
+    if sed -e '/1,^---/ d' $i|grep '$(Id|FreeBSD'
+    then
+	    echo 1>&2 "Problem with $i: CVS tag found in patch"
+    fi
+done
+
+echo $edit
+}
+exit 0
--
Trevor Johnson
http://jpj.net/~trevor/gpgkey.txt



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSI.4.21.0006300730580.16570-100000>