Many time patches come from various source (email for example)
This is a quick patch to run patches through fiterdiff such that
the rest of the CS patch parsing engine can handle the patch.
-Russell Cattelan
Index: codestriker/lib/Codestriker/FileParser/UnidiffUtils.pm
===================================================================
--- codestriker.orig/lib/Codestriker/FileParser/UnidiffUtils.pm 2007-07-16 14:59:37.896175000 -0500
+++ codestriker/lib/Codestriker/FileParser/UnidiffUtils.pm 2007-07-16 15:14:10.506488000 -0500
@@ -43,7 +43,7 @@ sub read_unidiff_text($$$$) {
# Now read in the diff text until finished.
my $diff = "";
$line = <$fh>;
- while (defined $line) {
+ while (defined $line && !($line =~ /^\-{3}.*/o)) {
# Skip lines line "\ No newline at end of file".
if ($line !~ /^[\\]/o) {
Index: codestriker/lib/Codestriker/FileParser/PatchUnidiff.pm
===================================================================
--- codestriker.orig/lib/Codestriker/FileParser/PatchUnidiff.pm 2007-07-16 14:59:37.892052000 -0500
+++ codestriker/lib/Codestriker/FileParser/PatchUnidiff.pm 2007-07-16 15:14:10.502111000 -0500
@@ -61,7 +61,7 @@ sub parse ($$) {
} elsif ($line =~ /^\-\-\- \/dev\/null/o) {
# File has been added.
$revision = $Codestriker::ADDED_REVISION;
- } elsif ($line =~ /^\-\-\- (.*)\t/o) {
+ } elsif ($line =~ /^\-\-\-\s*([\w\/\-\.;<>\*\|`&\$!#\?\(\)\[\]\{\}:'"]+).*/o) {
$filename = $1;
} else {
return ();
@@ -76,7 +76,7 @@ sub parse ($$) {
if ($line =~ /^\+\+\+ \/dev\/null/o) {
# File has been removed.
$revision = $Codestriker::REMOVED_REVISION;
- } elsif ($line =~ /^\+\+\+ (.*)\t/o) {
+ } elsif ($line =~ /^\+{3}\s*([\w\/\-\.;<>\*\|`&\$!#\?\(\)\[\]\{\}:'"]+).*/o) {
$filename = $1;
} else {
return ();
Index: codestriker/lib/Codestriker/FileParser/Parser.pm
===================================================================
--- codestriker.orig/lib/Codestriker/FileParser/Parser.pm 2007-07-16 14:59:37.888314000 -0500
+++ codestriker/lib/Codestriker/FileParser/Parser.pm 2007-07-16 15:15:59.000000000 -0500
@@ -7,7 +7,7 @@
# the terms of the GPL.
# Main delegate parser object, which tries a bunch of parsers to determine what
-# format the input review is in. The last resort, is to view it as
+# format the input review is in. The last resort, is to view it as
# unstructured text, if it is content-type plain/text, otherwise indicate
# an error.
@@ -44,14 +44,20 @@ sub parse ($$$$$$) {
# the wiser. Note the temporary file is automatically deleted
# once this function has finished.
my $tmpfh;
+ my $tmpfh2;
+ my $tmpfn;
+ my $tmpfn2;
if (defined $Codestriker::tmpdir && $Codestriker::tmpdir ne "") {
- $tmpfh = tempfile(DIR => $Codestriker::tmpdir);
+ ($tmpfh,$tmpfn) = tempfile(DIR => $Codestriker::tmpdir);
+ ($tmpfh2,$tmpfn2) = tempfile(DIR => $Codestriker::tmpdir);
}
else {
- $tmpfh = tempfile();
+ ($tmpfh,$tmpfn) = tempfile();
+ ($tmpfh2,$tmpfn2) = tempfile();
}
binmode $tmpfh, ':utf8';
-
+ binmode $tmpfh2, ':utf8';
+
if (!$tmpfh) {
die "Unable to create temporary parse file: $!";
}
@@ -75,7 +81,7 @@ sub parse ($$$$$$) {
seek($tmpfh, 0, 0) ||
die "Unable to seek to the start of the temporary file: $!";
@diffs =
- Codestriker::FileParser::CvsUnidiff->parse($tmpfh,
+ Codestriker::FileParser::CvsUnidiff->parse($tmpfh2,
$repository);
}
@@ -119,8 +125,17 @@ sub parse ($$$$$$) {
if ($#diffs == -1) {
seek($tmpfh, 0, 0) ||
die "Unable to seek to the start of the temporary file: $!";
+
+ open(FILTERDIFF,"filterdiff $tmpfn |") || warn "| filterdiff $tmpfn: $!";
+ while (<FILTERDIFF>) {
+ print $tmpfh2 $_;
+ }
+ close FILTERDIFF;
+ seek($tmpfh2, 0, 0) ||
+ die "Unable to seek to the start of the temporary file: $!";
+
@diffs =
- Codestriker::FileParser::PatchUnidiff->parse($tmpfh,
+ Codestriker::FileParser::PatchUnidiff->parse($tmpfh2,
$repository);
}
@@ -185,10 +200,8 @@ sub parse ($$$$$$) {
push @trimmed_diffs, $curr;
}
}
-
+
# Return the diffs found, if any.
return @trimmed_diffs;
}
-
1;
-
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Codestriker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-user