Annotation of pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl, revision 1.10
1.6 jlam 1: #!@PERL5@
1.1 wiz 2: #
1.10 ! wiz 3: # $NetBSD: patchdiff.pl,v 1.9 2008/02/16 22:21:35 apb 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
1.7 wiz 9: # Thomas Klausner <wiz@NetBSD.org>
1.1 wiz 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();
1.9 apb 30: s/^\.\///; # ignore leading "./", if any.
1.2 wiz 31: return $_;
1.1 wiz 32: }
33: close(handle);
34: return undef;
35: }
36:
37: sub putinhash {
38: my $hash=shift;
39: my $files=shift;
40: my $temp;
41: local *handle;
42: open(handle, "ls $files|");
43: while(<handle>) {
44: chomp;
45: $temp=getfilename($_);
1.3 skrll 46: $$hash{$temp}=File::Spec->abs2rel($_, $thisdir);
1.1 wiz 47: }
48: close(handle);
49: }
50:
51: getopts('d:h');
52:
53: if ($opt_h) {
54: ($prog) = ($0 =~ /([^\/]+)$/);
55: print STDERR <<EOF;
56: usage: $prog [-d output-directory]
57: -d dirname directory to compare the patches in patches/ to;
58: defaults to \$WRKDIR/.newpatches
59: EOF
60: exit 0;
61: };
62:
63: %orig=();
64: %new=();
1.3 skrll 65: $thisdir=cwd();
66: chomp($thisdir);
1.5 seb 67: $oldpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
68: die ("can't find PATCHDIR -- wrong dir?");
69: chomp($oldpatchdir);
1.1 wiz 70:
1.4 wiz 71: $wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or
1.1 wiz 72: die ("can't find WRKDIR -- wrong dir?");
73: chomp($wrkdir);
74:
75: if ($opt_d) {
76: $newpatchdir = cwd()."/$opt_d";
77: }
78: else {
79: $newpatchdir="$wrkdir"."/.newpatches";
80: }
81:
82: if ( ! -d $oldpatchdir) {
83: print "No old patches found (directory $oldpatchdir not found)\n";
84: exit(0);
85: }
86: if ( ! -d $newpatchdir ) {
87: print "No new patches found (directory $newpatchdir not found)\n";
88: exit(0);
89: }
90: putinhash(\%orig,"$oldpatchdir/patch-*");
91: putinhash(\%new,"$newpatchdir/patch-*");
92: foreach $patch (keys%orig) {
93: print "Only in old: $orig{$patch} ($patch)\n" unless defined($new{$patch});
94: }
95: foreach $patch (keys%new) {
96: if (defined($orig{$patch})) {
97: # system("diff",$orig{$patch},$new{$patch});
98: $diff=`diff $orig{$patch} $new{$patch}`;
1.10 ! wiz 99: # the following regex try to eliminate uninteresting differences
! 100: # The general structure of the diffs-to-be-removed is:
! 101: # 25c25
! 102: # < --- something.orig 2008-08-08 08:08
! 103: # ---
! 104: # > --- something.orig 2008-08-08 18:08
! 105: #
! 106: # In particular, remove hunks with:
! 107: # . NetBSD RCS Id tag differences
! 108: $diff=~s/^\d+c\d+\n..\$[N]etBSD.*\$\n---\n..\$[N]etBSD.*\$\n//m;
! 109: # . only the name or date of the output file changed
! 110: $diff=~s/^\d+c\d+\n..\+\+\+.*\n---\n..\+\+\+.*\n//m;
! 111: # . only the name or date of the input file changed
! 112: $diff=~s/^\d+c\d+\n.\s---\s.*\.orig\s.*\n---\n.\s---\s.*\n//m;
! 113: $diff=~s/^\d+c\d+\n.\s---\s.*\n---\n.\s---\s.*\.orig\s.*\n//m;
! 114: # . only line numbers changed
! 115: $diff=~s/^\d+c\d+\n.\s@@\s.*\s@@.*\n---\n.\s@@\s.*\s@@.*\n//mg;
1.1 wiz 116: if ($diff) {
117: print "Comparing $orig{$patch} to $new{$patch}\n$diff";
118: }
119: } else {
120: print "Only in new: $new{$patch} ($patch)\n"
121: }
122: }
CVSweb <webmaster@jp.NetBSD.org>