Annotation of pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl, revision 1.1.1.1
1.1 wiz 1: #!@PREFIX@/bin/perl
2: #
3: # $NetBSD$
4: #
5: # patchdiff: compares a set of patches patch-aa, patch-ab, ... in
6: # $WRKDIR/.newpatches in the with another set in patches.
7: #
8: # Copyright (c) 2000 by Dieter Baron <dillo@giga.or.at> and
9: # Thomas Klausner <wiz@netbsd.org>
10: # All Rights Reserved. Absolutely no warranty.
11:
12: use Getopt::Std;
13: use Cwd;
14:
15: my $oldpatchdir, $newpatchdir;
16: my $wrkdir;
17: my %orig, %new;
18:
19: # change to WRKDIR
20:
21: sub goto_wrkdir {
22: chdir $wrkdir or die ("can't cd to WRKDIR ($wrkdir)");
23: }
24:
25: sub getfilename {
26: my $fname=shift;
27: local $_;
28: local *handle;
29: open(handle, $fname);
30: while (<handle>) {
31: next unless m/^\+\+\+ ([^ ]*)/;
32: close(handle);
33: return $1;
34: }
35: close(handle);
36: return undef;
37: }
38:
39: sub putinhash {
40: my $hash=shift;
41: my $files=shift;
42: my $temp;
43: local *handle;
44: open(handle, "ls $files|");
45: while(<handle>) {
46: chomp;
47: $temp=getfilename($_);
48: $$hash{$temp}=$_;
49: # print "put in hash: $temp // $_";
50: }
51: close(handle);
52: }
53:
54: getopts('d:h');
55:
56: if ($opt_h) {
57: ($prog) = ($0 =~ /([^\/]+)$/);
58: print STDERR <<EOF;
59: usage: $prog [-d output-directory]
60: -d dirname directory to compare the patches in patches/ to;
61: defaults to \$WRKDIR/.newpatches
62: EOF
63: exit 0;
64: };
65:
66: %orig=();
67: %new=();
68: $oldpatchdir=cwd();
69: chomp($oldpatchdir);
70: $oldpatchdir=$oldpatchdir."/patches";
71:
72: $wrkdir=`make show-var VARNAME=WRKDIR` or
73: die ("can't find WRKDIR -- wrong dir?");
74: chomp($wrkdir);
75:
76: if ($opt_d) {
77: $newpatchdir = cwd()."/$opt_d";
78: }
79: else {
80: $newpatchdir="$wrkdir"."/.newpatches";
81: }
82:
83: if ( ! -d $oldpatchdir) {
84: print "No old patches found (directory $oldpatchdir not found)\n";
85: exit(0);
86: }
87: if ( ! -d $newpatchdir ) {
88: print "No new patches found (directory $newpatchdir not found)\n";
89: exit(0);
90: }
91: putinhash(\%orig,"$oldpatchdir/patch-*");
92: putinhash(\%new,"$newpatchdir/patch-*");
93: foreach $patch (keys%orig) {
94: print "Only in old: $orig{$patch} ($patch)\n" unless defined($new{$patch});
95: }
96: foreach $patch (keys%new) {
97: if (defined($orig{$patch})) {
98: # system("diff",$orig{$patch},$new{$patch});
99: $diff=`diff $orig{$patch} $new{$patch}`;
100: $diff=~s/^\dc\d\n..\$NetBSD.*\$\n---\n..\$NetBSD.*\$\n//m;
101: $diff=~s/^\dc\d\n..\+\+\+.*\n---\n..\+\+\+.*\n//m;
102: if ($diff) {
103: print "Comparing $orig{$patch} to $new{$patch}\n$diff";
104: }
105: } else {
106: print "Only in new: $new{$patch} ($patch)\n"
107: }
108: }
CVSweb <webmaster@jp.NetBSD.org>