Annotation of pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl, revision 1.8

1.6       jlam        1: #!@PERL5@
1.1       wiz         2: #
1.8     ! joerg       3: # $NetBSD: patchdiff.pl,v 1.7 2005/12/13 12:05:08 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
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();
                     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);
1.5       seb        66: $oldpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
                     67:     die ("can't find PATCHDIR -- wrong dir?");
                     68: chomp($oldpatchdir);
1.1       wiz        69: 
1.4       wiz        70: $wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or 
1.1       wiz        71:     die ("can't find WRKDIR -- wrong dir?");
                     72: chomp($wrkdir);
                     73: 
                     74: if ($opt_d) {
                     75:     $newpatchdir = cwd()."/$opt_d";
                     76: } 
                     77: else {
                     78:     $newpatchdir="$wrkdir"."/.newpatches";
                     79: }
                     80: 
                     81: if ( ! -d $oldpatchdir) {
                     82:     print "No old patches found (directory $oldpatchdir not found)\n";
                     83:     exit(0);
                     84: }
                     85: if ( ! -d $newpatchdir ) {
                     86:     print "No new patches found (directory $newpatchdir not found)\n";
                     87:     exit(0);
                     88: }
                     89: putinhash(\%orig,"$oldpatchdir/patch-*");
                     90: putinhash(\%new,"$newpatchdir/patch-*");
                     91: foreach $patch (keys%orig) {
                     92:     print "Only in old: $orig{$patch} ($patch)\n" unless defined($new{$patch});
                     93: }
                     94: foreach $patch (keys%new) {
                     95:     if (defined($orig{$patch})) {
                     96: #      system("diff",$orig{$patch},$new{$patch});
                     97:        $diff=`diff $orig{$patch} $new{$patch}`;
1.8     ! joerg      98:        $diff=~s/^\dc\d\n..\$[N]etBSD.*\$\n---\n..\$[N]etBSD.*\$\n//m;
1.1       wiz        99:        $diff=~s/^\dc\d\n..\+\+\+.*\n---\n..\+\+\+.*\n//m;
                    100:        if ($diff) {
                    101:             print "Comparing $orig{$patch} to $new{$patch}\n$diff";
                    102:        }
                    103:      } else {
                    104:        print "Only in new: $new{$patch} ($patch)\n" 
                    105:      }
                    106: }

CVSweb <webmaster@jp.NetBSD.org>