3 |
use strict; |
use strict; |
4 |
use Data::Dumper; |
use Data::Dumper; |
5 |
$Data::Dumper::Indent= 1; |
$Data::Dumper::Indent= 1; |
6 |
|
use Getopt::Long; |
7 |
|
|
8 |
sub parseFilter { |
sub parseFilter { |
9 |
my @args= @_; |
my @args= @_; |
24 |
} |
} |
25 |
|
|
26 |
sub loadDiff { |
sub loadDiff { |
27 |
my ($fileName)= @_; |
my ($fileName, $verbose)= @_; |
28 |
|
|
29 |
open (DIFFIN, "<$fileName") |
open (DIFFIN, "<$fileName") |
30 |
or die ("miserably..."); |
or die ("miserably..."); |
33 |
|
|
34 |
my $line= <DIFFIN>; |
my $line= <DIFFIN>; |
35 |
while ($line) { |
while ($line) { |
36 |
while ($line=~ /^Only/) { |
# while ($line!~ /^diff/) { |
37 |
|
while ($line!~ /^Only/) { |
38 |
$line= <DIFFIN>; |
$line= <DIFFIN>; |
39 |
} |
} |
40 |
|
print STDERR $line |
41 |
|
if $verbose; |
42 |
chomp $line; |
chomp $line; |
43 |
my $patchedFile= $line; |
my $patchedFile= $line; |
44 |
$line= <DIFFIN>; |
$line= <DIFFIN>; |
57 |
my $chunkNo= 0; |
my $chunkNo= 0; |
58 |
$line= <DIFFIN>; |
$line= <DIFFIN>; |
59 |
while ($line and $line!~ /^diff / and $line!~ /^Only/) { |
while ($line and $line!~ /^diff / and $line!~ /^Only/) { |
60 |
|
# while ($line and $line!~ /^diff/) { |
61 |
|
print STDERR $line |
62 |
|
if $verbose; |
63 |
chomp $line; |
chomp $line; |
64 |
my ($oStart, $oSize, $nStart, $nSize)= $line=~ /^\@\@ \-(\d+),(\d+) \+(\d+),(\d+) \@\@$/; |
my ($oStart, $oSize, $nStart, $nSize)= $line=~ /^\@\@ \-(\d+),(\d+) \+(\d+),(\d+) \@\@/; |
65 |
|
print STDERR "@@ -$oStart,$oSize +$nStart,$nSize @@\n\n" |
66 |
|
if $verbose; |
67 |
my $addedLines= $nSize-$oSize; |
my $addedLines= $nSize-$oSize; |
68 |
push @{$patch{$patchedFile}{'chunks'}}, ({ |
push @{$patch{$patchedFile}{'chunks'}}, ({ |
69 |
# 'header'=> $line, |
# 'header'=> $line, |
73 |
|
|
74 |
$line= <DIFFIN>; |
$line= <DIFFIN>; |
75 |
while ($line and $line!~ /^\@\@.*\@\@$/ and $line!~ /^diff/ and $line!~ /^Only/) { |
while ($line and $line!~ /^\@\@.*\@\@$/ and $line!~ /^diff/ and $line!~ /^Only/) { |
76 |
|
# while ($line and $line=~ /^[ \+\-]/) { |
77 |
chomp $line; |
chomp $line; |
78 |
push @{$patch{$patchedFile}{'chunks'}[$chunkNo]{'lines'}}, ($line); |
push @{$patch{$patchedFile}{'chunks'}[$chunkNo]{'lines'}}, ($line); |
79 |
$line= <DIFFIN>; |
$line= <DIFFIN>; |
80 |
} |
} |
81 |
$chunkNo++; |
$chunkNo++; |
82 |
|
# while ($line and $line=~ /^diff/) { |
83 |
|
# $line= <DIFFIN>; |
84 |
|
# } |
85 |
} |
} |
86 |
} |
} |
87 |
return \%patch; |
return \%patch; |
131 |
} |
} |
132 |
} |
} |
133 |
|
|
134 |
|
my $verbose; |
135 |
|
my $options= GetOptions ('verbose'=> \$verbose); |
136 |
my $fileName= shift @ARGV; |
my $fileName= shift @ARGV; |
137 |
my $patch= loadDiff ($fileName); |
my $patch= loadDiff ($fileName, $verbose); |
138 |
my $filter= parseFilter (@ARGV); |
my $filter= parseFilter (@ARGV); |
139 |
printPatch ($patch, $filter); |
printPatch ($patch, $filter); |