Subject: | [PATCH] DiffParser fails to parse one line changes to existing files with one line. |
Date: | Fri, 19 Sep 2008 11:32:14 +0200 |
To: | bug-SVN-Web [...] rt.cpan.org |
From: | salgar [...] gmx.net |
Hi,
here's a patch that fixes parsing of diffs with changes to an existing
file with one line.
SVN-Web Version 0.53
Error message: Missing @@ line before @@ -1, +1 ...
With kind regards
Pascal Hofmann
--- /old/SVN/Web/DiffParser.pm 2008-09-19 10:22:15.000000000 +0200
+++ /new/SVN/Web/DiffParser.pm 2008-09-19 11:05:20.000000000 +0200
@@ -298,23 +298,9 @@ sub _unified_line
}
die "Missing +++ line before $line"
unless exists $change->{filename2} and defined $change->{filename2};
- if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+),(\d+) \@\@$/ ) {
- my @match = ($1, $2, $3, $4);
- if( @{ $change->{lines} } ) {
- $change = $self->_new_chunk;
- }
- @{ $change }{ qw( line1 size1 line2 size2 ) } = @match;
- $change->{at1} = $change->{line1};
- $change->{at2} = $change->{line2};
- return;
- }
- # Files that have been newly added and only contain one line have
- # a hunk marker that looks like "@@ -0,0 +1 @@". Handle that.
- # This code should be refactored with the code above, since only
- # the regexp and the assignment to @match are different.
- if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+) \@\@$/ ) {
- my @match = ($1, $2, $3, 1);
+ my @match = $self->_detect_hunk_line( $line );
+ if(@match) {
if( @{ $change->{lines} } ) {
$change = $self->_new_chunk;
}
@@ -338,6 +324,26 @@ sub _unified_line
$self->{state}{unified} = 0;
}
+sub _detect_hunk_line
+{
+ my( $self, $line ) = @_;
+ # pretty standard change - hunk marker is something like "@@ -10,2 +10,3 @@"
+ if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+),(\d+) \@\@$/ ) {
+ return ($1, $2, $3, $4);
+ }
+
+ # new file, only one line - hunk marker "@@ -0,0 +1 @@"
+ if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+) \@\@$/ ) {
+ return ($1, $2, $3, 1);
+ }
+ # first line changed, file only has one line - hunk marker "@@ -1 +1 @@"
+ if( $line =~ /^\@\@ -(\d+) [+](\d+) \@\@$/ ) {
+ return ($1, 1, $2, 1);
+ }
+
+ return ();
+}
+
sub _new_type
{
my( $self, $mod ) = @_;