Created Codestriker topic at:
http://codestriker.sourceforge.net/cgi-bin/codestriker.pl?topic=7610490&action=view
User: sits
Date: 05/07/14 05:08:14
Modified: lib/Codestriker/FileParser UnidiffUtils.pm
Log:
Tightened the unidiff parsing code to handle obscure cases from
non-complaint texts generated from Perforce.
Index: UnidiffUtils.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/FileParser/UnidiffUtils.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UnidiffUtils.pm 22 May 2005 22:26:04 -0000 1.4
+++ UnidiffUtils.pm 14 Jul 2005 12:08:10 -0000 1.5
@@ -22,10 +22,16 @@
my $lastpos = tell $fh;
my $line = <$fh>;
while (defined $line &&
- $line =~ /[EMAIL PROTECTED]@ \-(\d+)(\,\d+)? \+(\d+)(\,\d+)? [EMAIL
PROTECTED]@(.*)$/) {
+ $line =~ /[EMAIL PROTECTED]@ \-(\d+)(\,)?(\d+)? \+(\d+)(\,)?(\d+)?
[EMAIL PROTECTED]@(.*)$/) {
my $old_linenumber = $1;
- my $new_linenumber = $3;
- my $function_name = $5;
+ my $number_old_lines = 1;
+ $number_old_lines = $3 if defined $3;
+ my $new_linenumber = $4;
+ my $number_new_lines = 1;
+ $number_new_lines = $6 if defined $6;
+ my $function_name = $7;
+ my $num_matched_old_lines = 0;
+ my $num_matched_new_lines = 0;
if (length($function_name) > 1) {
$function_name =~ s/^ //;
@@ -34,13 +40,34 @@
$function_name = "";
}
- # Now read in the diff text until finished. Note Perforce
- # diffs can contain empty lines.
+ # Now read in the diff text until finished.
my $diff = "";
$line = <$fh>;
- while (defined $line && ($line =~ /^$/o || $line =~ /^[ \-\+\\]/o)) {
+ while (defined $line) {
# Skip lines line "\ No newline at end of file".
- $diff .= $line unless $line =~ /^[\\]/o;
+ if ($line !~ /^[\\]/o) {
+
+ # Check if the diff block with the trailing context has been
+ # read. Note Perforce diffs can contain empty lines.
+ if ($num_matched_old_lines >= $number_old_lines &&
+ $num_matched_new_lines >= $number_new_lines) {
+ last unless $line =~ /^ /o || $line =~ /^$/o;
+ }
+ else {
+ if ($line =~ /^\-/o) {
+ $num_matched_old_lines++;
+ } elsif ($line =~ /^\+/o) {
+ $num_matched_new_lines++;
+ } elsif ($line =~ /^ /o || $line =~ /^$/o) {
+ $num_matched_old_lines++;
+ $num_matched_new_lines++;
+ }
+ }
+
+ # Add the line to the diff chunk.
+ $diff .= $line;
+ }
+
$lastpos = tell $fh;
$line = <$fh>;
}
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits