Annotation of pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl, revision 1.3
1.1 wiz 1: #!@PREFIX@/bin/perl
2: #
1.3 ! skrll 3: # $NetBSD: patchdiff.pl,v 1.2 2000/08/17 03:09:26 wiz Exp $
1.1 wiz 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;
1.3 ! skrll 14: use File::Spec;
1.1 wiz 15:
16: my $oldpatchdir, $newpatchdir;
1.3 ! skrll 17: my $wrkdir, $thisdir;
1.1 wiz 18: my %orig, %new;
19:
20: sub getfilename {
21: my $fname=shift;
22: local $_;
23: local *handle;
24: open(handle, $fname);
25: while (<handle>) {
1.2 wiz 26: next unless m/^\+\+\+[ ]([^ ]*)/;
1.1 wiz 27: close(handle);
1.2 wiz 28: $_ = $1;
29: chomp();
30: return $_;
1.1 wiz 31: }
32: close(handle);
33: return undef;
34: }
35:
36: sub putinhash {
37: my $hash=shift;
38: my $files=shift;
39: my $temp;
40: local *handle;
41: open(handle, "ls $files|");
42: while(<handle>) {
43: chomp;
44: $temp=getfilename($_);
1.3 ! skrll 45: $$hash{$temp}=File::Spec->abs2rel($_, $thisdir);
1.1 wiz 46: }
47: close(handle);
48: }
49:
50: getopts('d:h');
51:
52: if ($opt_h) {
53: ($prog) = ($0 =~ /([^\/]+)$/);
54: print STDERR <<EOF;
55: usage: $prog [-d output-directory]
56: -d dirname directory to compare the patches in patches/ to;
57: defaults to \$WRKDIR/.newpatches
58: EOF
59: exit 0;
60: };
61:
62: %orig=();
63: %new=();
1.3 ! skrll 64: $thisdir=cwd();
! 65: chomp($thisdir);
! 66: $oldpatchdir=$thisdir."/patches";
1.1 wiz 67:
68: $wrkdir=`make show-var VARNAME=WRKDIR` or
69: die ("can't find WRKDIR -- wrong dir?");
70: chomp($wrkdir);
71:
72: if ($opt_d) {
73: $newpatchdir = cwd()."/$opt_d";
74: }
75: else {
76: $newpatchdir="$wrkdir"."/.newpatches";
77: }
78:
79: if ( ! -d $oldpatchdir) {
80: print "No old patches found (directory $oldpatchdir not found)\n";
81: exit(0);
82: }
83: if ( ! -d $newpatchdir ) {
84: print "No new patches found (directory $newpatchdir not found)\n";
85: exit(0);
86: }
87: putinhash(\%orig,"$oldpatchdir/patch-*");
88: putinhash(\%new,"$newpatchdir/patch-*");
89: foreach $patch (keys%orig) {
90: print "Only in old: $orig{$patch} ($patch)\n" unless defined($new{$patch});
91: }
92: foreach $patch (keys%new) {
93: if (defined($orig{$patch})) {
94: # system("diff",$orig{$patch},$new{$patch});
95: $diff=`diff $orig{$patch} $new{$patch}`;
96: $diff=~s/^\dc\d\n..\$NetBSD.*\$\n---\n..\$NetBSD.*\$\n//m;
97: $diff=~s/^\dc\d\n..\+\+\+.*\n---\n..\+\+\+.*\n//m;
98: if ($diff) {
99: print "Comparing $orig{$patch} to $new{$patch}\n$diff";
100: }
101: } else {
102: print "Only in new: $new{$patch} ($patch)\n"
103: }
104: }
CVSweb <webmaster@jp.NetBSD.org>