Doing more work with Subversion's diff, I've discovered that if a file
is newly added to the repo and only contains one line the hunk marker
looks like this:
@@ -0,0 +1 @@
The parsing code in Text::Diff::Parser doesn't handle that.
Here's a unified diff that kludges around the problem (and also fixes
the problem with line numbers starting at 0 I reported earlier.
--- /root/.cpan/build/Text-Diff-Parser-0.02/lib/Text/Diff/Parser.pm
Thu Oct
19 22:00:12 2006
+++ /usr/local/lib/perl5/site_perl/5.8.8/Text/Diff/Parser.pm Fri Oct
20 09:50
:48 2006
@@ -307,8 +307,25 @@
$change->{at2} = $change->{line2};
return;
}
+
+ # Subversion seems to sometimes generate diffs where the hunk marker
+ # looks like "@@ -0,0 +1 @@". This seems to be a file that's newly
+ # added with only one line. 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);
+ if( @{ $change->{lines} } ) {
+ $change = $self->_new_chunk;
+ }
+ @{ $change }{ qw( line1 size1 line2 size2 ) } = @match;
+ $change->{at1} = $change->{line1};
+ $change->{at2} = $change->{line2};
+ return;
+ }
+
die "Missing \@\@ line before $line at $self->{state}{context}\n"
- unless exists $change->{line1};
+ unless exists $change->{line1} and defined
$change->{li
ne1};
if( $line =~ /^([-+ ])(.*)$/) {
my( $mod, $text ) = ( $1, $2 );