Annotation of pkgsrc/pkgtools/pkgdiff/files/patchdiff.pl, revision 1.15
1.6 jlam 1: #!@PERL5@
1.1 wiz 2: #
1.15 ! wiz 3: # $NetBSD: patchdiff.pl,v 1.14 2011/02/02 23:35:11 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.15 ! wiz 72: getopts('Dd:h');
1.1 wiz 73:
74: if ($opt_h) {
75: ($prog) = ($0 =~ /([^\/]+)$/);
76: print STDERR <<EOF;
1.15 ! wiz 77: usage: $prog [-D | -d dir]
! 78: -D look at patches in \$WRKDIR/.newpatches
! 79: -d dir look at patches in this directory
1.1 wiz 80: EOF
81: exit 0;
82: };
83:
84: %orig=();
85: %new=();
1.3 skrll 86: $thisdir=cwd();
87: chomp($thisdir);
1.15 ! wiz 88: $wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or
! 89: die ("can't find WRKDIR -- wrong dir?");
! 90: chomp($wrkdir);
! 91: $origpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or
1.5 seb 92: die ("can't find PATCHDIR -- wrong dir?");
1.15 ! wiz 93: chomp($origpatchdir);
! 94:
! 95: if ($opt_D) {
! 96: $patchdir = "$wrkdir/.newpatches";
! 97: } elsif ($opt_d) {
! 98: if (-d "/$opt_d") {
! 99: $patchdir = $opt_d;
! 100: } else {
! 101: $patchdir = "$thisdir/$opt_d";
! 102: }
! 103: } else {
! 104: $patchdir = $origpatchdir;
! 105: }
1.1 wiz 106:
1.13 wiz 107: if ( ! -d $patchdir) {
108: print "No patches found (directory $patchdir not found)\n";
109: exit(0);
1.1 wiz 110: }
111:
1.13 wiz 112: open(HANDLE, "find ${patchdir} -type f -name \\\*.orig |");
113:
114: foreach (sort <HANDLE>) {
115: $orig = $_;
116: chomp($orig);
117: $new = $orig;
118: $new =~ s/.orig$//;
119:
120: if (! -f "$new") {
121: print "File $new removed\n";
122: } else {
1.1 wiz 123: # system("diff",$orig{$patch},$new{$patch});
1.13 wiz 124: $diff=`diff $orig $new`;
1.10 wiz 125: # the following regex try to eliminate uninteresting differences
126: # The general structure of the diffs-to-be-removed is:
127: # 25c25
128: # < --- something.orig 2008-08-08 08:08
129: # ---
130: # > --- something.orig 2008-08-08 18:08
131: #
132: # In particular, remove hunks with:
133: # . NetBSD RCS Id tag differences
1.11 sbd 134: $diff=~s/^[\d,]+c[\d,]+\n..\$[N]etBSD.*\$\n---\n..\$[N]etBSD.*\$\n//m;
1.12 sbd 135: # . the name of the input file changed
1.13 wiz 136: # (if the name of the output file has changed, patches
137: # won't get matched up anyway)
1.12 sbd 138: # . time of the input and/or output file changed
139: # . line numbers changed
1.13 wiz 140: $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 141: # . only line numbers changed
1.11 sbd 142: $diff=~s/^[\d,]+c[\d,]+\n.\s@@\s.*\s@@.*\n---\n.\s@@\s.*\s@@.*\n//mg;
1.1 wiz 143: if ($diff) {
1.13 wiz 144: if (! -s $orig) {
145: print "New file $new\n";
146: } else {
147: print "Comparing $orig to $new\n$diff";
148: }
149: } else {
150: # restore previous version to get rid of uninteresting diffs
151: rename "$orig", "$new";
1.1 wiz 152: }
1.13 wiz 153: }
1.1 wiz 154: }
CVSweb <webmaster@jp.NetBSD.org>