From 01b5fe46344c543e403c07c29e5ac33e37fd6c55 Mon Sep 17 00:00:00 2001 From: Trevor Johnson Date: Thu, 19 Oct 2000 10:47:28 +0000 Subject: Add update-patches, a script to generate updated versions of the patches in a port. Obtained from: OpenBSD --- Tools/scripts/README | 20 +++++++- Tools/scripts/update-patches | 120 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100755 Tools/scripts/update-patches diff --git a/Tools/scripts/README b/Tools/scripts/README index 48be3afb69a0..c069063b01da 100644 --- a/Tools/scripts/README +++ b/Tools/scripts/README @@ -24,6 +24,8 @@ portsearch - A utility for searching the ports tree. It allows more detailed search criteria than ``make search key='' and accepts all perl(1) regular expressions. +update-patches - generates updated patches. + ---------------------------------------------------------------------- consistency-check gives output like: @@ -139,6 +141,22 @@ See the file README.portsearch for further information. ---------------------------------------------------------------------- +The update-patches script looks for files in $WRKSRC (if unset, this defaults +to the work/ subdirectory of the current directory) which have a matching .orig +file. It also looks in $PATCHDIR (if unset, this defaults to the files/ +subdirectory of the current directory) for patches that correspond to the first +set. If the changes in an existing patch do not reflect the changes in the +files in $WRKSRC, the script renames the existing patch by adding the suffix +.orig and generates a new patch in its place. If no patch existed, the new one +is created with a name that contains the path and filename of the file being +patched, except that "/" separators and "." characters are replaced by +underscores: for example, a new patch to $WRKSRC/foo/bar.c would be created as +$PATCHDIR/patch-foo_bar_c. If you save a .orig backup of a file, but don't +change the file, update-patches will generate an empty patch. + +---------------------------------------------------------------------- + NOTE: These scripts need work and are *NOT* safe to use unless you know what they do. Use at your own risk. Patches would be great, but - it is prefered they pass through maintainer of each particular script. + it is preferred they pass through the maintainer of each particular + script. diff --git a/Tools/scripts/update-patches b/Tools/scripts/update-patches new file mode 100755 index 000000000000..ebafe2162e9a --- /dev/null +++ b/Tools/scripts/update-patches @@ -0,0 +1,120 @@ +#!/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. + +if test -z $WRKSRC; then + if test -d `pwd`/work; then + WRKSRC=`pwd`/work + fi +fi + +if test -z $PATCHDIR; then + if test -d `pwd`/files; then + PATCHDIR=`pwd`/files + fi +fi + +if test -z $PATCH_LIST; then + if test -d $PATCHDIR; then + PATCH_LIST=$PATCHDIR/patch-* + fi +fi + +# Find out all .orig files and strip the name to what diff will use +cd $WRKSRC && find . -type f -name '*.orig' | fgrep -v $WRKSRC | \ +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 $WRKSRC && 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 $WRKSRC && 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 -- cgit v1.2.3