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

1.6       jlam        1: #!@PERL5@
1.1       wiz         2: #
1.13    ! wiz         3: # $NetBSD: patchdiff.pl,v 1.12 2010/07/04 22:20:04 sbd Exp $
1.1       wiz         4: #
1.13    ! wiz         5: # patchdiff: compares a set of patches in the patch dir with their predecessors
1.1       wiz         6: #
1.13    ! wiz         7: # Copyright (c) 2000, 2011 by Dieter Baron <dillo@giga.or.at> and
        !             8: #                             Thomas Klausner <wiz@NetBSD.org>  
1.1       wiz         9: # All Rights Reserved.  Absolutely no warranty.  
                     10: 
                     11: use Getopt::Std;
                     12: use Cwd;
1.3       skrll      13: use File::Spec;
1.1       wiz        14: 
1.13    ! wiz        15: my $patchdir, $patchdir;
1.3       skrll      16: my $wrkdir, $thisdir;
1.1       wiz        17: my %orig, %new;
                     18: 
                     19: sub getfilename {
                     20:     my $fname=shift;
                     21:     local $_;
                     22:     local *handle;
                     23:     open(handle, $fname);
                     24:     while (<handle>) {
1.11      sbd        25:        next unless m/^\+\+\+[   ]([^   ]*)/;
1.1       wiz        26:        close(handle);
1.2       wiz        27:        $_ = $1;
                     28:        chomp();
1.9       apb        29:        s/^\.\///; # ignore leading "./", if any.
1.2       wiz        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: 
1.13    ! wiz        50: getopts('h');
1.1       wiz        51: 
                     52: if ($opt_h) {
                     53:                ($prog) = ($0 =~ /([^\/]+)$/);
                     54:                print STDERR <<EOF;
1.13    ! wiz        55: usage: $prog
1.1       wiz        56: EOF
                     57:                exit 0;
                     58: };
                     59: 
                     60: %orig=();
                     61: %new=();
1.3       skrll      62: $thisdir=cwd();
                     63: chomp($thisdir);
1.13    ! wiz        64: $patchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
1.5       seb        65:     die ("can't find PATCHDIR -- wrong dir?");
1.13    ! wiz        66: chomp($patchdir);
1.1       wiz        67: 
1.13    ! wiz        68: if ( ! -d $patchdir) {
        !            69:     print "No patches found (directory $patchdir not found)\n";
        !            70:     exit(0);
1.1       wiz        71: }
                     72: 
1.13    ! wiz        73: open(HANDLE, "find ${patchdir} -type f -name \\\*.orig |");
        !            74: 
        !            75: foreach (sort <HANDLE>) {
        !            76:     $orig = $_;
        !            77:     chomp($orig);
        !            78:     $new = $orig;
        !            79:     $new =~ s/.orig$//;
        !            80: 
        !            81:     if (! -f "$new") {
        !            82:        print "File $new removed\n";
        !            83:     } else {
1.1       wiz        84: #      system("diff",$orig{$patch},$new{$patch});
1.13    ! wiz        85:        $diff=`diff $orig $new`;
1.10      wiz        86:        # the following regex try to eliminate uninteresting differences
                     87:        # The general structure of the diffs-to-be-removed is:
                     88:        # 25c25
                     89:        # < --- something.orig 2008-08-08 08:08
                     90:        # ---
                     91:        # > --- something.orig 2008-08-08 18:08
                     92:        #
                     93:        # In particular, remove hunks with:
                     94:        # . NetBSD RCS Id tag differences
1.11      sbd        95:        $diff=~s/^[\d,]+c[\d,]+\n..\$[N]etBSD.*\$\n---\n..\$[N]etBSD.*\$\n//m;
1.12      sbd        96:        # . the name of the input file changed
1.13    ! wiz        97:        #   (if the name of the output file has changed, patches
        !            98:        #    won't get matched up anyway)
1.12      sbd        99:        # . time of the input and/or output file changed
                    100:        # . line numbers changed
1.13    ! wiz       101:        $diff=~s/^[\d,]+c[\d,]+\n(?:.\s---\s(:?\S+).*\n)?(?:.\s\+\+\+\s(\S+).*\n)?(?:.\s@@\s(?:.*)\s@@.*\n)?---\n(?:.\s---\s\S+.*\n)?(?:.\s\+\+\+\s\S+.*\n)?(?:.\s@@\s.*\s@@.*\n)?//m;
1.10      wiz       102:        # . only line numbers changed
1.11      sbd       103:        $diff=~s/^[\d,]+c[\d,]+\n.\s@@\s.*\s@@.*\n---\n.\s@@\s.*\s@@.*\n//mg;
1.1       wiz       104:        if ($diff) {
1.13    ! wiz       105:            if (! -s $orig) {
        !           106:                print "New file $new\n";
        !           107:            } else {
        !           108:                print "Comparing $orig to $new\n$diff";
        !           109:            }
        !           110:        } else {
        !           111:            # restore previous version to get rid of uninteresting diffs
        !           112:            rename "$orig", "$new";
1.1       wiz       113:        }
1.13    ! wiz       114:     }
1.1       wiz       115: }

CVSweb <webmaster@jp.NetBSD.org>