Skip Menu |

This queue is for tickets about the SVN-Web CPAN distribution.

Report information
The Basics
Id: 39410
Status: resolved
Priority: 0/
Queue: SVN-Web

People
Owner: Nobody in particular
Requestors: salgar [...] gmx.net
Cc:
AdminCc:

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



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 ) = @_;
Subject: Re: [rt.cpan.org #39410] DiffParser fails to parse one line changes to existing files with one line.
Date: Fri, 19 Sep 2008 11:50:40 +0200
To: bug-SVN-Web [...] rt.cpan.org
From: salgar [...] gmx.net
Hi, I just saw, that this is already fixed in revision 1308 - sorry. I refactored the code which handles the hunk markers. I've attached a patch for revision 1308. With kind regards Pascal Hofmann
--- DiffParser.pm.1 2008-09-19 11:39:16.000000000 +0200 +++ /usr/share/perl5/SVN/Web/DiffParser.pm 2008-09-19 11:38:48.000000000 +0200 @@ -298,51 +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); - 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 are only one line long, but get changed look - # like "@@ -1 +1 @@". Handle that. - # This should *also* be refactored along the lines of the above. - if ( $line =~ /^\@\@ -(\d+) [+](\d+) \@\@$/ ) { - my @match = ($1, 1, $2, 1); - 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 are only one line long, and get new lines look - # like "@@ -1 +1,n @@". Handle that. - # This should *also* be refactored along the lines of the above. - if ( $line =~ /^\@\@ -(\d+) [+](\d+),(\d+) \@\@$/ ) { - my @match = ($1, 1, $2, $3); + my @match = $self->_detect_hunk_marker( $line ); + if(@match) { if( @{ $change->{lines} } ) { $change = $self->_new_chunk; } @@ -366,6 +324,34 @@ sub _unified_line $self->{state}{unified} = 0; } +sub _detect_hunk_marker +{ + my( $self, $line ) = @_; + # pretty standard change + # "@@ -l1,n1 +l2,n2 @@" + if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+),(\d+) \@\@$/ ) { + return ($1, $2, $3, $4); + } + + # New files with only one line. + # "@@ -0,0 +1 @@" + if( $line =~ /^\@\@ -(\d+),(\d+) [+](\d+) \@\@$/ ) { + return ($1, $2, $3, 1); + } + # Files that are only one line long, but get changed. + # "@@ -1 +1 @@" + if( $line =~ /^\@\@ -(\d+) [+](\d+) \@\@$/ ) { + return ($1, 1, $2, 1); + } + # Files that are only one line long, and get new line. + # "@@ -1 +1,n @@" + if( $line =~ /^\@\@ -(\d+) [+](\d+),(\d+) \@\@$/ ) { + return ($1, 1, $2, $3); + } + + return (); +} + sub _new_type { my( $self, $mod ) = @_;
On Fri Sep 19 05:51:01 2008, salgar@gmx.net wrote: Show quoted text
> Hi, > > I just saw, that this is already fixed in revision 1308 - sorry. > > I refactored the code which handles the hunk markers. I've attached a > patch for revision 1308. > > > With kind regards > > Pascal Hofmann >
Hi Pascal Can you send me a pull request on github (https://github.com/djzort/SVN-Web) and i will merge it. THanks
On Thu Feb 02 17:45:25 2012, djzort wrote: Show quoted text
> On Fri Sep 19 05:51:01 2008, salgar@gmx.net wrote:
> > Hi, > > > > I just saw, that this is already fixed in revision 1308 - sorry. > > > > I refactored the code which handles the hunk markers. I've attached a > > patch for revision 1308. > > > > > > With kind regards > > > > Pascal Hofmann > >
> > Hi Pascal > > Can you send me a pull request on github > (https://github.com/djzort/SVN-Web) and i will merge it. THanks
On Fri May 25 07:52:55 2012, djzort wrote: Show quoted text
> On Thu Feb 02 17:45:25 2012, djzort wrote:
> > On Fri Sep 19 05:51:01 2008, salgar@gmx.net wrote:
> > > Hi, > > > > > > I just saw, that this is already fixed in revision 1308 - sorry. > > > > > > I refactored the code which handles the hunk markers. I've attached a > > > patch for revision 1308. > > > > > > > > > With kind regards > > > > > > Pascal Hofmann > > >
> > > > Hi Pascal > > > > Can you send me a pull request on github > > (https://github.com/djzort/SVN-Web) and i will merge it. THanks
> >