Skip Menu |

This queue is for tickets about the Text-Diff-Parser CPAN distribution.

Report information
The Basics
Id: 22357
Status: resolved
Priority: 0/
Queue: Text-Diff-Parser

People
Owner: Nobody in particular
Requestors: NIKC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.02
Fixed in: (no value)



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 );
Subject: Bug with new files that only contain one line
On Fri Oct 20 09:48:57 2006, NIKC wrote: Show quoted text
> 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 @@
I've checked, and again, this is not just with Subversion: % echo 'this is one line' > one-line % diff -u /dev/null one-line --- /dev/null Fri Oct 20 15:11:00 2006 +++ one-line Fri Oct 20 15:12:57 2006 @@ -0,0 +1 @@ +this is one line N
Subject: Zero length files
Thanks for the bug report! You will find this fixed in version 0.04, which I just uploaded to CPAN.
Subject: Hmm...
RT is insisting I send you another message to close this ticket.