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

1.6       jlam        1: #!@PERL5@
1.1       wiz         2: #
1.14    ! wiz         3: # $NetBSD: patchdiff.pl,v 1.13 2011/02/02 10:23:02 wiz 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.14    ! wiz         9: # All rights reserved.
        !            10: #
        !            11: # Redistribution and use in source and binary forms, with or without
        !            12: # modification, are permitted provided that the following conditions
        !            13: # are met:
        !            14: # 1. Redistributions of source code must retain the above copyright
        !            15: #    notice, this list of conditions and the following disclaimer.
        !            16: # 2. Redistributions in binary form must reproduce the above copyright
        !            17: #    notice, this list of conditions and the following disclaimer in the
        !            18: #    documentation and/or other materials provided with the distribution.
        !            19: #
        !            20: # THIS SOFTWARE IS PROVIDED BY THE AUTHORS
        !            21: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            22: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            23: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS
        !            24: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            25: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            26: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            27: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            28: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            29: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            30: # POSSIBILITY OF SUCH DAMAGE.
        !            31: #
1.1       wiz        32: 
                     33: use Getopt::Std;
                     34: use Cwd;
1.3       skrll      35: use File::Spec;
1.1       wiz        36: 
1.13      wiz        37: my $patchdir, $patchdir;
1.3       skrll      38: my $wrkdir, $thisdir;
1.1       wiz        39: my %orig, %new;
                     40: 
                     41: sub getfilename {
                     42:     my $fname=shift;
                     43:     local $_;
                     44:     local *handle;
                     45:     open(handle, $fname);
                     46:     while (<handle>) {
1.11      sbd        47:        next unless m/^\+\+\+[   ]([^   ]*)/;
1.1       wiz        48:        close(handle);
1.2       wiz        49:        $_ = $1;
                     50:        chomp();
1.9       apb        51:        s/^\.\///; # ignore leading "./", if any.
1.2       wiz        52:        return $_;
1.1       wiz        53:      }
                     54:      close(handle);
                     55:      return undef;
                     56: }
                     57: 
                     58: sub putinhash {
                     59:     my $hash=shift;
                     60:     my $files=shift;
                     61:     my $temp;
                     62:     local *handle;
                     63:     open(handle, "ls $files|");
                     64:     while(<handle>) {
                     65:        chomp;
                     66:        $temp=getfilename($_);
1.3       skrll      67:        $$hash{$temp}=File::Spec->abs2rel($_, $thisdir);
1.1       wiz        68:      }
                     69:      close(handle);
                     70: }
                     71: 
1.13      wiz        72: getopts('h');
1.1       wiz        73: 
                     74: if ($opt_h) {
                     75:                ($prog) = ($0 =~ /([^\/]+)$/);
                     76:                print STDERR <<EOF;
1.13      wiz        77: usage: $prog
1.1       wiz        78: EOF
                     79:                exit 0;
                     80: };
                     81: 
                     82: %orig=();
                     83: %new=();
1.3       skrll      84: $thisdir=cwd();
                     85: chomp($thisdir);
1.13      wiz        86: $patchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
1.5       seb        87:     die ("can't find PATCHDIR -- wrong dir?");
1.13      wiz        88: chomp($patchdir);
1.1       wiz        89: 
1.13      wiz        90: if ( ! -d $patchdir) {
                     91:     print "No patches found (directory $patchdir not found)\n";
                     92:     exit(0);
1.1       wiz        93: }
                     94: 
1.13      wiz        95: open(HANDLE, "find ${patchdir} -type f -name \\\*.orig |");
                     96: 
                     97: foreach (sort <HANDLE>) {
                     98:     $orig = $_;
                     99:     chomp($orig);
                    100:     $new = $orig;
                    101:     $new =~ s/.orig$//;
                    102: 
                    103:     if (! -f "$new") {
                    104:        print "File $new removed\n";
                    105:     } else {
1.1       wiz       106: #      system("diff",$orig{$patch},$new{$patch});
1.13      wiz       107:        $diff=`diff $orig $new`;
1.10      wiz       108:        # the following regex try to eliminate uninteresting differences
                    109:        # The general structure of the diffs-to-be-removed is:
                    110:        # 25c25
                    111:        # < --- something.orig 2008-08-08 08:08
                    112:        # ---
                    113:        # > --- something.orig 2008-08-08 18:08
                    114:        #
                    115:        # In particular, remove hunks with:
                    116:        # . NetBSD RCS Id tag differences
1.11      sbd       117:        $diff=~s/^[\d,]+c[\d,]+\n..\$[N]etBSD.*\$\n---\n..\$[N]etBSD.*\$\n//m;
1.12      sbd       118:        # . the name of the input file changed
1.13      wiz       119:        #   (if the name of the output file has changed, patches
                    120:        #    won't get matched up anyway)
1.12      sbd       121:        # . time of the input and/or output file changed
                    122:        # . line numbers changed
1.13      wiz       123:        $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       124:        # . only line numbers changed
1.11      sbd       125:        $diff=~s/^[\d,]+c[\d,]+\n.\s@@\s.*\s@@.*\n---\n.\s@@\s.*\s@@.*\n//mg;
1.1       wiz       126:        if ($diff) {
1.13      wiz       127:            if (! -s $orig) {
                    128:                print "New file $new\n";
                    129:            } else {
                    130:                print "Comparing $orig to $new\n$diff";
                    131:            }
                    132:        } else {
                    133:            # restore previous version to get rid of uninteresting diffs
                    134:            rename "$orig", "$new";
1.1       wiz       135:        }
1.13      wiz       136:     }
1.1       wiz       137: }

CVSweb <webmaster@jp.NetBSD.org>