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