Fri Mar 4 15:57:07 2011 UTC ()
Add "-D"/"-d dir" options to mkpatches and patchdiff.

-D provides the previous behaviour of creating patches in $WRKDIR/.newpatches
-d dir specifies the directory where the patches will be created.

Requested by Aleksey Cheusov for read-only pkgsrc checkouts.

Fix minor bugs while here.

Bump version.


(wiz)
diff -r1.72 -r1.73 pkgsrc/pkgtools/pkgdiff/Makefile
diff -r1.6 -r1.7 pkgsrc/pkgtools/pkgdiff/files/mkpatches.1
diff -r1.6 -r1.7 pkgsrc/pkgtools/pkgdiff/files/patchdiff.1
diff -r1.15 -r1.16 pkgsrc/pkgtools/pkgdiff/files/mkpatches.pl
diff -r1.14 -r1.15 pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl

cvs diff -r1.72 -r1.73 pkgsrc/pkgtools/pkgdiff/Makefile (expand / switch to context diff)
--- pkgsrc/pkgtools/pkgdiff/Makefile 2011/02/02 23:35:51 1.72
+++ pkgsrc/pkgtools/pkgdiff/Makefile 2011/03/04 15:57:07 1.73
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.72 2011/02/02 23:35:51 wiz Exp $
+# $NetBSD: Makefile,v 1.73 2011/03/04 15:57:07 wiz Exp $
 #
 
-DISTNAME=	pkgdiff-1.0
+DISTNAME=	pkgdiff-1.1
 CATEGORIES=	pkgtools devel
 MASTER_SITES=	# empty
 DISTFILES=	# empty

cvs diff -r1.6 -r1.7 pkgsrc/pkgtools/pkgdiff/files/mkpatches.1 (expand / switch to context diff)
--- pkgsrc/pkgtools/pkgdiff/files/mkpatches.1 2011/02/02 23:34:48 1.6
+++ pkgsrc/pkgtools/pkgdiff/files/mkpatches.1 2011/03/04 15:57:07 1.7
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mkpatches.1,v 1.6 2011/02/02 23:34:48 wiz Exp $
+.\"	$NetBSD: mkpatches.1,v 1.7 2011/03/04 15:57:07 wiz Exp $
 .\"
 .\" Copyright (c) 2000-2011 by Thomas Klausner <wiz@NetBSD.org>
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 31, 2011
+.Dd February 20, 2011
 .Dt MKPATCHES 1
 .Os
 .Sh NAME
@@ -32,8 +32,9 @@
 .Nd create patch files appropriate for pkgsrc
 .Sh SYNOPSIS
 .Nm
-.Oo Fl c | Fl r Oc
 .Op Fl hv
+.Oo Fl c | Fl r Oc
+.Op Fl D | Fl d Ar dir
 .Sh DESCRIPTION
 .Nm
 is a perl script that simplifies creating patches from a changed work
@@ -67,6 +68,20 @@
 Clean up backup patches of previous runs.
 Use this after you're finished working on the patch set and committed
 it.
+.It Fl D
+Use
+.Pa $WRKDIR/.newpatches
+for patches.
+See
+.Fl d
+for more details.
+.It Fl d Ar dir
+Use
+.Ar dir
+for patches.
+Copies any existing patches there on the first run and then
+creates or updates patches only there.
+Use this e.g. if you have a read-only pkgsrc.
 .It Fl h
 Show a short usage.
 .It Fl r

cvs diff -r1.6 -r1.7 pkgsrc/pkgtools/pkgdiff/files/patchdiff.1 (expand / switch to context diff)
--- pkgsrc/pkgtools/pkgdiff/files/patchdiff.1 2011/02/02 23:34:48 1.6
+++ pkgsrc/pkgtools/pkgdiff/files/patchdiff.1 2011/03/04 15:57:07 1.7
@@ -1,4 +1,4 @@
-.\"	$NetBSD: patchdiff.1,v 1.6 2011/02/02 23:34:48 wiz Exp $
+.\"	$NetBSD: patchdiff.1,v 1.7 2011/03/04 15:57:07 wiz Exp $
 .\"
 .\" Copyright (c) 2000-2011 by Thomas Klausner <wiz@NetBSD.org>
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 31, 2011
+.Dd February 20, 2011
 .Dt PATCHDIFF 1
 .Os
 .Sh NAME
@@ -32,6 +32,7 @@
 .Nd compare sets of patches
 .Sh SYNOPSIS
 .Nm
+.Op Fl D | Fl d Ar dir
 .Sh DESCRIPTION
 .Nm
 is a perl script that simplifies comparing a set of previously
@@ -48,7 +49,23 @@
 using
 .Xr diff 1 .
 If no relevant differences are found, the original patch is restored.
+.Pp
+If the
+.Fl d
+option is used,
+.Nm
+looks for patches in
+.Ar dir
+instead of the default
+.Pa patches
+directory.
+If the
+.Fl D
+option is used,
+.Nm
+looks in
+.Pa $WRKDIR/.newpatches .
 .Sh SEE ALSO
 .Xr diff 1 ,
-.Xr patchdiff 1 ,
+.Xr mkpatches 1 ,
 .Xr pkgdiff 1

cvs diff -r1.15 -r1.16 pkgsrc/pkgtools/pkgdiff/files/mkpatches.pl (expand / switch to context diff)
--- pkgsrc/pkgtools/pkgdiff/files/mkpatches.pl 2011/02/02 23:35:11 1.15
+++ pkgsrc/pkgtools/pkgdiff/files/mkpatches.pl 2011/03/04 15:57:07 1.16
@@ -1,6 +1,6 @@
 #!@PERL5@
 #
-# $NetBSD: mkpatches.pl,v 1.15 2011/02/02 23:35:11 wiz Exp $
+# $NetBSD: mkpatches.pl,v 1.16 2011/03/04 15:57:07 wiz Exp $
 #
 # mkpatches: creates a set of patches patch-aa, patch-ab, ...
 #   in work/.newpatches by looking for *.orig files in and below
@@ -46,6 +46,7 @@
 my $patchdir;
 my $old_patchdir;
 my $wrkdir;
+my $wrksrc;
 my %old_filename;
 my %old_header;
 
@@ -54,23 +55,30 @@
 sub create_patchdir {
     if (! -d $patchdir) {
 	mkdir($patchdir, 0755);
+	if (-d $origpatchdir && "$origpatchdir" != "$patchdir") {
+	    system("cp", "$origpatchdir/p*", "$patchdir");
+	}
     }
 }
 
 # read command line arguments
 
 undef($opt_c);
+undef($opt_D);
+undef($opt_d);
 undef($opt_h);
 undef($opt_r);
 undef($opt_v);
 
-getopts('chrv');
+getopts('cDd:hrv');
 
 if ($opt_h) {
 		($prog) = ($0 =~ /([^\/]+)$/);
 		print STDERR <<EOF;
-usage: $prog [-chv]
+usage: $prog [-hv] [-c | -r] [-D | -d dir]
     -c   	commit -- clean up old patches backups
+    -d dir   	create patches in this directory
+    -D   	create patches in \$WRKDIR/.newpatches
     -h   	show this help
     -r   	revert -- remove new patches, put old patches back
     -v   	verbose - list .orig files as processed
@@ -78,15 +86,37 @@
 		exit 0;
 };
 
-# get WRKDIR
+if ($opt_d && $opt_D) {
+    print STDERR "-D and -d conflict, choose one\n";
+    exit 1;
+}
 
+# get some pkgsrc variables
+
+$wrksrc=`@MAKE@ show-var VARNAME=WRKSRC` or 
+    die ("can't find WRKSRC -- wrong dir?");
+chomp($wrksrc);
 $wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or
     die ("can't find WRKDIR -- wrong dir?");
 chomp($wrkdir);
-$patchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
+$origpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
     die ("can't find PATCHDIR -- wrong dir?");
-chomp($patchdir);
+chomp($origpatchdir);
 
+if ($opt_D) {
+    $patchdir = "$wrkdir/.newpatches";
+} elsif ($opt_d) {
+    if (-d "/$opt_d") {
+	$patchdir = $opt_d;
+    } else {
+	my $pwd = cwd();
+	chomp($pwd);
+	$patchdir = "$pwd/$opt_d";
+    }
+} else {
+    $patchdir = $origpatchdir;
+}
+
 if ($opt_c) {
     open(HANDLE, "find ${patchdir} -type f -name \\\*.orig |");
     foreach (<HANDLE>) {
@@ -113,12 +143,7 @@
 
 create_patchdir();
 
-# get WRKSRC
 
-$wrksrc=`@MAKE@ show-var VARNAME=WRKSRC` or 
-    die ("can't find WRKSRC -- wrong dir?");
-chomp($wrksrc);
-
 move_away_old_patches();
 
 analyze_old_patches();
@@ -127,7 +152,7 @@
 
 # find files
 
-open(HANDLE, "find ${wrkdir} -type f -name \\\*.orig |");
+open(HANDLE, "find ${wrksrc} -type f -name \\\*.orig |");
 
 # create patches
 

cvs diff -r1.14 -r1.15 pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl (expand / switch to context diff)
--- pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl 2011/02/02 23:35:11 1.14
+++ pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl 2011/03/04 15:57:07 1.15
@@ -1,6 +1,6 @@
 #!@PERL5@
 #
-# $NetBSD: patchdiff.pl,v 1.14 2011/02/02 23:35:11 wiz Exp $
+# $NetBSD: patchdiff.pl,v 1.15 2011/03/04 15:57:07 wiz Exp $
 #
 # patchdiff: compares a set of patches in the patch dir with their predecessors
 #
@@ -69,12 +69,14 @@
      close(handle);
 }
 
-getopts('h');
+getopts('Dd:h');
 
 if ($opt_h) {
 		($prog) = ($0 =~ /([^\/]+)$/);
 		print STDERR <<EOF;
-usage: $prog
+usage: $prog [-D | -d dir]
+    -D		look at patches in \$WRKDIR/.newpatches
+    -d dir	look at patches in this directory
 EOF
 		exit 0;
 };
@@ -83,9 +85,24 @@
 %new=();
 $thisdir=cwd();
 chomp($thisdir);
-$patchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
+$wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or
+    die ("can't find WRKDIR -- wrong dir?");
+chomp($wrkdir);
+$origpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
     die ("can't find PATCHDIR -- wrong dir?");
-chomp($patchdir);
+chomp($origpatchdir);
+
+if ($opt_D) {
+    $patchdir = "$wrkdir/.newpatches";
+} elsif ($opt_d) {
+    if (-d "/$opt_d") {
+	$patchdir = $opt_d;
+    } else {
+	$patchdir = "$thisdir/$opt_d";
+    }
+} else {
+    $patchdir = $origpatchdir;
+}
 
 if ( ! -d $patchdir) {
     print "No patches found (directory $patchdir not found)\n";