Subject: pkgtools/pkglint: patch for detecting multiple files in patch files
To: None <tech-pkg@netbsd.org>
From: Roland Illig <roland.illig@gmx.de>
List: tech-pkg
Date: 02/26/2004 09:46:52
This is a multi-part message in MIME format.
--------------020602010707010109020402
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

And here's the automated workaround to my last complaint.

Please commit it if you find it useful. I dont have permission to do it 
myself. You (tech-pkg@netbsd.org) are the maintainer. :)

Roland

--------------020602010707010109020402
Content-Type: text/x-patch;
 name="pkglint-3.68-multiple-patches.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="pkglint-3.68-multiple-patches.patch"

Index: pkglint.pl
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkglint/files/pkglint.pl,v
retrieving revision 1.98
diff -u -r1.98 pkglint.pl
--- pkglint.pl	23 Feb 2004 12:33:29 -0000	1.98
+++ pkglint.pl	26 Feb 2004 08:42:40 -0000
@@ -536,6 +536,7 @@
 	local($file) = @_;
 	local($rcsidseen) = 0;
 	local($whole);
+	my (@lines);
 
 	if ($file =~ /.*~$/) {
 		&perror("WARN: is $file a backup file? If so, please remove it \n"
@@ -547,6 +548,7 @@
 	while (<IN>) {
 		$rcsidseen++ if /\$$rcsidstr[:\$]/;
 		$whole .= $_;
+		push(@lines, $_);
 	}
 	if ($committer && $whole =~ /.\$(Author|Date|Header|Id|Locker|Log|Name|RCSfile|Revision|Source|State|NetBSD)(:.*\$|\$)/) { # XXX
 	        # RCS ID in very first line is ok, to identify version
@@ -560,6 +562,45 @@
 			"in patch $file.")
 	}
 	close(IN);
+
+	$files_in_patch = 0;
+	$patch_state = "";
+	foreach my $patch_line (@lines) {
+	    chomp($patch_line);
+	    if (index($patch_line, "--- ") == 0 && $patch_line !~ qr"^--- \d+,\d+ ----$") {
+	        $line_type = "-";
+	    } elsif (index($patch_line, "*** ") == 0 && $patch_line !~ qr"^\*\*\* \d+,\d+ \*\*\*\*$") {
+	        $line_type = "*";
+	    } elsif (index($patch_line, "+++ ") == 0) {
+	        $line_type = "+";
+	    } else {
+	        $line_type = "";
+	    }
+	    if ($patch_state eq "*") {
+	        if ($line_type eq "-") {
+		    $files_in_patch++;
+		    $patch_state = "";
+		} else {
+	            &perror("WARN: $i:$.: unknown patch format (might be an internal error)");
+		}
+	    } elsif ($patch_state eq "-") {
+	        if ($line_type eq "+") {
+		    $files_in_patch++;
+		    $patch_state = "";
+		} else {
+		    &perror("WARN: $i:$.: unknown patch format (might be an internal error)");
+		}
+	    } elsif ($patch_state eq "") {
+	        $patch_state = $line_type;
+	    }
+	    #print("$i:$.: state=($patch_state), line=($line_type)\n");
+	}
+	if ($files_in_patch > 1) {
+	    &perror("WARN: patch `$i' contains patches for more than one file, namely $files_in_patch");
+	} elsif ($files_in_patch == 0) {
+	    &perror("WARN: patch `$i' contains no patch");
+	}
+	return 1;
 }
 
 sub readmakefile {

--------------020602010707010109020402--