diff options
Diffstat (limited to 'Bugzilla/PatchReader')
-rw-r--r-- | Bugzilla/PatchReader/AddCVSContext.pm | 81 | ||||
-rw-r--r-- | Bugzilla/PatchReader/Base.pm | 3 | ||||
-rw-r--r-- | Bugzilla/PatchReader/CVSClient.pm | 45 | ||||
-rw-r--r-- | Bugzilla/PatchReader/DiffPrinter/raw.pm | 6 | ||||
-rw-r--r-- | Bugzilla/PatchReader/DiffPrinter/template.pm | 72 | ||||
-rw-r--r-- | Bugzilla/PatchReader/FilterPatch.pm | 2 | ||||
-rw-r--r-- | Bugzilla/PatchReader/FixPatchRoot.pm | 50 | ||||
-rw-r--r-- | Bugzilla/PatchReader/NarrowPatch.pm | 7 | ||||
-rw-r--r-- | Bugzilla/PatchReader/PatchInfoGrabber.pm | 13 | ||||
-rw-r--r-- | Bugzilla/PatchReader/Raw.pm | 86 |
10 files changed, 217 insertions, 148 deletions
diff --git a/Bugzilla/PatchReader/AddCVSContext.pm b/Bugzilla/PatchReader/AddCVSContext.pm index 4e7da5661..094ef6ed8 100644 --- a/Bugzilla/PatchReader/AddCVSContext.pm +++ b/Bugzilla/PatchReader/AddCVSContext.pm @@ -9,7 +9,8 @@ use Bugzilla::PatchReader::CVSClient; use Cwd; use File::Temp; -@Bugzilla::PatchReader::AddCVSContext::ISA = qw(Bugzilla::PatchReader::FilterPatch); +@Bugzilla::PatchReader::AddCVSContext::ISA + = qw(Bugzilla::PatchReader::FilterPatch); # XXX If you need to, get the entire patch worth of files and do a single # cvs update of all files as soon as you find a file where you need to do a @@ -31,7 +32,8 @@ sub my_rmtree { foreach my $file (glob("$dir/*")) { if (-d $file) { $this->my_rmtree($file); - } else { + } + else { trick_taint($file); unlink $file; } @@ -43,6 +45,7 @@ sub my_rmtree { sub end_patch { my $this = shift; if (exists($this->{TMPDIR})) { + # Set as variable to get rid of taint # One would like to use rmtree here, but that is not taint-safe. $this->my_rmtree($this->{TMPDIR}); @@ -52,10 +55,10 @@ sub end_patch { sub start_file { my $this = shift; my ($file) = @_; - $this->{HAS_CVS_CONTEXT} = !$file->{is_add} && !$file->{is_remove} && - $file->{old_revision}; - $this->{REVISION} = $file->{old_revision}; - $this->{FILENAME} = $file->{filename}; + $this->{HAS_CVS_CONTEXT} + = !$file->{is_add} && !$file->{is_remove} && $file->{old_revision}; + $this->{REVISION} = $file->{old_revision}; + $this->{FILENAME} = $file->{filename}; $this->{SECTION_END} = -1; $this->{TARGET}->start_file(@_) if $this->{TARGET}; } @@ -66,7 +69,7 @@ sub end_file { if ($this->{FILE}) { close $this->{FILE}; - unlink $this->{FILE}; # If it fails, it fails ... + unlink $this->{FILE}; # If it fails, it fails ... delete $this->{FILE}; } $this->{TARGET}->end_file(@_) if $this->{TARGET}; @@ -76,10 +79,12 @@ sub next_section { my $this = shift; my ($section) = @_; $this->{NEXT_PATCH_LINE} = $section->{old_start}; - $this->{NEXT_NEW_LINE} = $section->{new_start}; + $this->{NEXT_NEW_LINE} = $section->{new_start}; foreach my $line (@{$section->{lines}}) { + # If this is a line requiring context ... if ($line =~ /^[-\+]/) { + # Determine how much context is needed for both the previous section line # and this one: # - If there is no old line, start new section @@ -89,20 +94,23 @@ sub next_section { # space and therefore we end the old section and start the new one # - Else we add (old start context line through new line) context to # existing section - if (! exists($this->{SECTION})) { + if (!exists($this->{SECTION})) { $this->_start_section(); - } elsif ($this->{CONTEXT} eq "file") { + } + elsif ($this->{CONTEXT} eq "file") { $this->push_context_lines($this->{SECTION_END} + 1, - $this->{NEXT_PATCH_LINE} - 1); - } else { + $this->{NEXT_PATCH_LINE} - 1); + } + else { my $start_context = $this->{NEXT_PATCH_LINE} - $this->{CONTEXT}; $start_context = $start_context > 0 ? $start_context : 0; if (($this->{SECTION_END} + $this->{CONTEXT} + 1) < $start_context) { $this->flush_section(); $this->_start_section(); - } else { + } + else { $this->push_context_lines($this->{SECTION_END} + 1, - $this->{NEXT_PATCH_LINE} - 1); + $this->{NEXT_PATCH_LINE} - 1); } } push @{$this->{SECTION}{lines}}, $line; @@ -110,16 +118,19 @@ sub next_section { $this->{SECTION}{plus_lines}++; $this->{SECTION}{new_lines}++; $this->{NEXT_NEW_LINE}++; - } else { + } + else { $this->{SECTION_END}++; $this->{SECTION}{minus_lines}++; $this->{SECTION}{old_lines}++; $this->{NEXT_PATCH_LINE}++; } - } else { + } + else { $this->{NEXT_PATCH_LINE}++; $this->{NEXT_NEW_LINE}++; } + # If this is context, for now lose it (later we should try and determine if # we can just use it instead of pulling the file all the time) } @@ -130,7 +141,8 @@ sub determine_start { return 0 if $line < 0; if ($this->{CONTEXT} eq "file") { return 1; - } else { + } + else { my $start = $line - $this->{CONTEXT}; $start = $start > 0 ? $start : 1; return $start; @@ -146,23 +158,26 @@ sub _start_section { $this->{SECTION}{old_lines} = 0; $this->{SECTION}{new_lines} = 0; $this->{SECTION}{minus_lines} = 0; - $this->{SECTION}{plus_lines} = 0; - $this->{SECTION_END} = $this->{SECTION}{old_start} - 1; + $this->{SECTION}{plus_lines} = 0; + $this->{SECTION_END} = $this->{SECTION}{old_start} - 1; $this->push_context_lines($this->{SECTION}{old_start}, - $this->{NEXT_PATCH_LINE} - 1); + $this->{NEXT_PATCH_LINE} - 1); } sub flush_section { my $this = shift; if ($this->{SECTION}) { + # Add the necessary context to the end if ($this->{CONTEXT} eq "file") { $this->push_context_lines($this->{SECTION_END} + 1, "file"); - } else { + } + else { $this->push_context_lines($this->{SECTION_END} + 1, - $this->{SECTION_END} + $this->{CONTEXT}); + $this->{SECTION_END} + $this->{CONTEXT}); } + # Send the section and line notifications $this->{TARGET}->next_section($this->{SECTION}) if $this->{TARGET}; delete $this->{SECTION}; @@ -172,35 +187,41 @@ sub flush_section { sub push_context_lines { my $this = shift; + # Grab from start to end my ($start, $end) = @_; return if $end ne "file" && $start > $end; # If it's an added / removed file, don't do anything - return if ! $this->{HAS_CVS_CONTEXT}; + return if !$this->{HAS_CVS_CONTEXT}; # Get and open the file if necessary if (!$this->{FILE}) { my $olddir = getcwd(); - if (! exists($this->{TMPDIR})) { + if (!exists($this->{TMPDIR})) { $this->{TMPDIR} = File::Temp::tempdir(); - if (! -d $this->{TMPDIR}) { + if (!-d $this->{TMPDIR}) { die "Could not get temporary directory"; } } chdir($this->{TMPDIR}) or die "Could not cd $this->{TMPDIR}"; - if (Bugzilla::PatchReader::CVSClient::cvs_co_rev($this->{CVSROOT}, $this->{REVISION}, $this->{FILENAME})) { - die "Could not check out $this->{FILENAME} r$this->{REVISION} from $this->{CVSROOT}"; + if (Bugzilla::PatchReader::CVSClient::cvs_co_rev( + $this->{CVSROOT}, $this->{REVISION}, $this->{FILENAME} + )) + { + die + "Could not check out $this->{FILENAME} r$this->{REVISION} from $this->{CVSROOT}"; } open(my $fh, '<', $this->{FILENAME}) or die "Could not open $this->{FILENAME}"; - $this->{FILE} = $fh; + $this->{FILE} = $fh; $this->{NEXT_FILE_LINE} = 1; - trick_taint($olddir); # $olddir comes from getcwd() + trick_taint($olddir); # $olddir comes from getcwd() chdir($olddir) or die "Could not cd back to $olddir"; } # Read through the file to reach the line we need - die "File read too far!" if $this->{NEXT_FILE_LINE} && $this->{NEXT_FILE_LINE} > $start; + die "File read too far!" + if $this->{NEXT_FILE_LINE} && $this->{NEXT_FILE_LINE} > $start; my $fh = $this->{FILE}; while ($this->{NEXT_FILE_LINE} < $start) { my $dummy = <$fh>; diff --git a/Bugzilla/PatchReader/Base.pm b/Bugzilla/PatchReader/Base.pm index 26cb9a9a0..58b08fd25 100644 --- a/Bugzilla/PatchReader/Base.pm +++ b/Bugzilla/PatchReader/Base.pm @@ -17,7 +17,8 @@ sub sends_data_to { my $this = shift; if (defined($_[0])) { $this->{TARGET} = $_[0]; - } else { + } + else { return $this->{TARGET}; } } diff --git a/Bugzilla/PatchReader/CVSClient.pm b/Bugzilla/PatchReader/CVSClient.pm index 7a8875dc8..3f2a852f2 100644 --- a/Bugzilla/PatchReader/CVSClient.pm +++ b/Bugzilla/PatchReader/CVSClient.pm @@ -14,37 +14,36 @@ use strict; use warnings; sub parse_cvsroot { - my $cvsroot = $_[0]; - # Format: :method:[user[:password]@]server[:[port]]/path - if ($cvsroot =~ /^:([^:]*):(.*?)(\/.*)$/) { - my %retval; - $retval{protocol} = $1; - $retval{rootdir} = $3; - my $remote = $2; - if ($remote =~ /^(([^\@:]*)(:([^\@]*))?\@)?([^:]*)(:(.*))?$/) { - $retval{user} = $2; - $retval{password} = $4; - $retval{server} = $5; - $retval{port} = $7; - return %retval; - } + my $cvsroot = $_[0]; + + # Format: :method:[user[:password]@]server[:[port]]/path + if ($cvsroot =~ /^:([^:]*):(.*?)(\/.*)$/) { + my %retval; + $retval{protocol} = $1; + $retval{rootdir} = $3; + my $remote = $2; + if ($remote =~ /^(([^\@:]*)(:([^\@]*))?\@)?([^:]*)(:(.*))?$/) { + $retval{user} = $2; + $retval{password} = $4; + $retval{server} = $5; + $retval{port} = $7; + return %retval; } + } - return ( - rootdir => $cvsroot - ); + return (rootdir => $cvsroot); } sub cvs_co { - my ($cvsroot, @files) = @_; - my $cvs = $::cvsbin || "cvs"; - return system($cvs, "-Q", "-d$cvsroot", "co", @files); + my ($cvsroot, @files) = @_; + my $cvs = $::cvsbin || "cvs"; + return system($cvs, "-Q", "-d$cvsroot", "co", @files); } sub cvs_co_rev { - my ($cvsroot, $rev, @files) = @_; - my $cvs = $::cvsbin || "cvs"; - return system($cvs, "-Q", "-d$cvsroot", "co", "-r$rev", @files); + my ($cvsroot, $rev, @files) = @_; + my $cvs = $::cvsbin || "cvs"; + return system($cvs, "-Q", "-d$cvsroot", "co", "-r$rev", @files); } 1 diff --git a/Bugzilla/PatchReader/DiffPrinter/raw.pm b/Bugzilla/PatchReader/DiffPrinter/raw.pm index b7a0d8db2..81e01c283 100644 --- a/Bugzilla/PatchReader/DiffPrinter/raw.pm +++ b/Bugzilla/PatchReader/DiffPrinter/raw.pm @@ -29,7 +29,8 @@ sub start_file { my $fh = $this->{OUTFILE}; if ($file->{rcs_filename}) { print $fh "Index: $file->{filename}\n"; - print $fh "===================================================================\n"; + print $fh + "===================================================================\n"; print $fh "RCS file: $file->{rcs_filename}\n"; } my $old_file = $file->{is_add} ? "/dev/null" : $file->{filename}; @@ -53,7 +54,8 @@ sub next_section { return unless $section->{old_start} || $section->{new_start}; my $fh = $this->{OUTFILE}; - print $fh "@@ -$section->{old_start},$section->{old_lines} +$section->{new_start},$section->{new_lines} @@ $section->{func_info}\n"; + print $fh + "@@ -$section->{old_start},$section->{old_lines} +$section->{new_start},$section->{new_lines} @@ $section->{func_info}\n"; foreach my $line (@{$section->{lines}}) { $line =~ s/(\r?\n?)$/\n/; print $fh $line; diff --git a/Bugzilla/PatchReader/DiffPrinter/template.pm b/Bugzilla/PatchReader/DiffPrinter/template.pm index 4120f1d8a..54f3b4419 100644 --- a/Bugzilla/PatchReader/DiffPrinter/template.pm +++ b/Bugzilla/PatchReader/DiffPrinter/template.pm @@ -11,10 +11,10 @@ sub new { bless $this, $class; $this->{TEMPLATE_PROCESSOR} = $_[0]; - $this->{HEADER_TEMPLATE} = $_[1]; - $this->{FILE_TEMPLATE} = $_[2]; - $this->{FOOTER_TEMPLATE} = $_[3]; - $this->{ARGS} = $_[4] || {}; + $this->{HEADER_TEMPLATE} = $_[1]; + $this->{FILE_TEMPLATE} = $_[2]; + $this->{FOOTER_TEMPLATE} = $_[3]; + $this->{ARGS} = $_[4] || {}; $this->{ARGS}{file_count} = 0; return $this; @@ -23,20 +23,20 @@ sub new { sub start_patch { my $this = shift; $this->{TEMPLATE_PROCESSOR}->process($this->{HEADER_TEMPLATE}, $this->{ARGS}) - || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); + || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); } sub end_patch { my $this = shift; $this->{TEMPLATE_PROCESSOR}->process($this->{FOOTER_TEMPLATE}, $this->{ARGS}) - || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); + || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); } sub start_file { my $this = shift; $this->{ARGS}{file_count}++; - $this->{ARGS}{file} = shift; - $this->{ARGS}{file}{plus_lines} = 0; + $this->{ARGS}{file} = shift; + $this->{ARGS}{file}{plus_lines} = 0; $this->{ARGS}{file}{minus_lines} = 0; @{$this->{ARGS}{sections}} = (); } @@ -45,9 +45,11 @@ sub end_file { my $this = shift; my $file = $this->{ARGS}{file}; if ($file->{canonical} && $file->{old_revision} && $this->{ARGS}{bonsai_url}) { - $this->{ARGS}{bonsai_prefix} = "$this->{ARGS}{bonsai_url}/cvsblame.cgi?file=$file->{filename}&rev=$file->{old_revision}"; + $this->{ARGS}{bonsai_prefix} + = "$this->{ARGS}{bonsai_url}/cvsblame.cgi?file=$file->{filename}&rev=$file->{old_revision}"; } if ($file->{canonical} && $this->{ARGS}{lxr_url}) { + # Cut off the lxr root, if any my $filename = $file->{filename}; $filename = substr($filename, length($this->{ARGS}{lxr_root})); @@ -55,7 +57,7 @@ sub end_file { } $this->{TEMPLATE_PROCESSOR}->process($this->{FILE_TEMPLATE}, $this->{ARGS}) - || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); + || ::ThrowTemplateError($this->{TEMPLATE_PROCESSOR}->error()); @{$this->{ARGS}{sections}} = (); delete $this->{ARGS}{file}; } @@ -64,47 +66,46 @@ sub next_section { my $this = shift; my ($section) = @_; - $this->{ARGS}{file}{plus_lines} += $section->{plus_lines}; + $this->{ARGS}{file}{plus_lines} += $section->{plus_lines}; $this->{ARGS}{file}{minus_lines} += $section->{minus_lines}; # Get groups of lines and print them my $last_line_char = ''; - my $context_lines = []; - my $plus_lines = []; - my $minus_lines = []; + my $context_lines = []; + my $plus_lines = []; + my $minus_lines = []; foreach my $line (@{$section->{lines}}) { $line =~ s/\r?\n?$//; if ($line =~ /^ /) { if ($last_line_char ne ' ') { - push @{$section->{groups}}, {context => $context_lines, - plus => $plus_lines, - minus => $minus_lines}; + push @{$section->{groups}}, + {context => $context_lines, plus => $plus_lines, minus => $minus_lines}; $context_lines = []; - $plus_lines = []; - $minus_lines = []; + $plus_lines = []; + $minus_lines = []; } $last_line_char = ' '; push @{$context_lines}, substr($line, 1); - } elsif ($line =~ /^\+/) { + } + elsif ($line =~ /^\+/) { if ($last_line_char eq ' ' || $last_line_char eq '-' && @{$plus_lines}) { - push @{$section->{groups}}, {context => $context_lines, - plus => $plus_lines, - minus => $minus_lines}; - $context_lines = []; - $plus_lines = []; - $minus_lines = []; + push @{$section->{groups}}, + {context => $context_lines, plus => $plus_lines, minus => $minus_lines}; + $context_lines = []; + $plus_lines = []; + $minus_lines = []; $last_line_char = ''; } $last_line_char = '+'; push @{$plus_lines}, substr($line, 1); - } elsif ($line =~ /^-/) { + } + elsif ($line =~ /^-/) { if ($last_line_char eq '+' && @{$minus_lines}) { - push @{$section->{groups}}, {context => $context_lines, - plus => $plus_lines, - minus => $minus_lines}; - $context_lines = []; - $plus_lines = []; - $minus_lines = []; + push @{$section->{groups}}, + {context => $context_lines, plus => $plus_lines, minus => $minus_lines}; + $context_lines = []; + $plus_lines = []; + $minus_lines = []; $last_line_char = ''; } $last_line_char = '-'; @@ -112,9 +113,8 @@ sub next_section { } } - push @{$section->{groups}}, {context => $context_lines, - plus => $plus_lines, - minus => $minus_lines}; + push @{$section->{groups}}, + {context => $context_lines, plus => $plus_lines, minus => $minus_lines}; push @{$this->{ARGS}{sections}}, $section; } diff --git a/Bugzilla/PatchReader/FilterPatch.pm b/Bugzilla/PatchReader/FilterPatch.pm index 330f6329b..3891e4e57 100644 --- a/Bugzilla/PatchReader/FilterPatch.pm +++ b/Bugzilla/PatchReader/FilterPatch.pm @@ -11,7 +11,7 @@ use Bugzilla::PatchReader::Base; sub new { my $class = shift; $class = ref($class) || $class; - my $this = $class->SUPER::new(); + my $this = $class->SUPER::new(); bless $this, $class; return $this; diff --git a/Bugzilla/PatchReader/FixPatchRoot.pm b/Bugzilla/PatchReader/FixPatchRoot.pm index 1b0d250ad..a06682ba8 100644 --- a/Bugzilla/PatchReader/FixPatchRoot.pm +++ b/Bugzilla/PatchReader/FixPatchRoot.pm @@ -7,7 +7,8 @@ use warnings; use Bugzilla::PatchReader::FilterPatch; use Bugzilla::PatchReader::CVSClient; -@Bugzilla::PatchReader::FixPatchRoot::ISA = qw(Bugzilla::PatchReader::FilterPatch); +@Bugzilla::PatchReader::FixPatchRoot::ISA + = qw(Bugzilla::PatchReader::FilterPatch); sub new { my $class = shift; @@ -26,26 +27,29 @@ sub diff_root { my $this = shift; if (@_) { $this->{DIFF_ROOT} = $_[0]; - } else { + } + else { return $this->{DIFF_ROOT}; } } sub flush_delayed_commands { my $this = shift; - return if ! $this->{DELAYED_COMMANDS}; + return if !$this->{DELAYED_COMMANDS}; my $commands = $this->{DELAYED_COMMANDS}; delete $this->{DELAYED_COMMANDS}; $this->{FORCE_COMMANDS} = 1; foreach my $command_arr (@{$commands}) { my $command = $command_arr->[0]; - my $arg = $command_arr->[1]; + my $arg = $command_arr->[1]; if ($command eq "start_file") { $this->start_file($arg); - } elsif ($command eq "end_file") { + } + elsif ($command eq "end_file") { $this->end_file($arg); - } elsif ($command eq "section") { + } + elsif ($command eq "section") { $this->next_section($arg); } } @@ -60,10 +64,12 @@ sub end_patch { sub start_file { my $this = shift; my ($file) = @_; + # If the file is new, it will not have a filename that fits the repository # root and therefore needs to be fixed up to have the same root as everyone # else. At the same time we need to fix DIFF_ROOT too. if (exists($this->{DIFF_ROOT})) { + # XXX Return error if there are multiple roots in the patch by verifying # that the DIFF_ROOT is not different from the calculated diff root on this # filename @@ -71,31 +77,35 @@ sub start_file { $file->{filename} = $this->{DIFF_ROOT} . $file->{filename}; $file->{canonical} = 1; - } elsif ($file->{rcs_filename} && - substr($file->{rcs_filename}, 0, length($this->{REPOSITORY_ROOT})) eq - $this->{REPOSITORY_ROOT}) { + } + elsif ($file->{rcs_filename} + && substr($file->{rcs_filename}, 0, length($this->{REPOSITORY_ROOT})) eq + $this->{REPOSITORY_ROOT}) + { # Since we know the repository we can determine where the user was in the # repository when they did the diff by chopping off the repository root # from the rcs filename - $this->{DIFF_ROOT} = substr($file->{rcs_filename}, - length($this->{REPOSITORY_ROOT})); + $this->{DIFF_ROOT} + = substr($file->{rcs_filename}, length($this->{REPOSITORY_ROOT})); $this->{DIFF_ROOT} =~ s/,v$//; + # If the RCS file exists in the Attic then we need to correct for # this, stripping off the '/Attic' suffix in order to reduce the name # to just the CVS root. if ($this->{DIFF_ROOT} =~ m/Attic/) { $this->{DIFF_ROOT} = substr($this->{DIFF_ROOT}, 0, -6); } + # XXX More error checking--that filename exists and that it is in fact # part of the rcs filename - $this->{DIFF_ROOT} = substr($this->{DIFF_ROOT}, 0, - -length($file->{filename})); + $this->{DIFF_ROOT} = substr($this->{DIFF_ROOT}, 0, -length($file->{filename})); $this->flush_delayed_commands(); $file->{filename} = $this->{DIFF_ROOT} . $file->{filename}; $file->{canonical} = 1; - } else { + } + else { # DANGER Will Robinson. The first file in the patch is new. We will try # "delayed command mode" # @@ -104,7 +114,7 @@ sub start_file { # whatever the hell was in the patch) if (!$this->{FORCE_COMMANDS}) { - push @{$this->{DELAYED_COMMANDS}}, [ "start_file", { %{$file} } ]; + push @{$this->{DELAYED_COMMANDS}}, ["start_file", {%{$file}}]; return; } } @@ -114,8 +124,9 @@ sub start_file { sub end_file { my $this = shift; if (exists($this->{DELAYED_COMMANDS})) { - push @{$this->{DELAYED_COMMANDS}}, [ "end_file", { %{$_[0]} } ]; - } else { + push @{$this->{DELAYED_COMMANDS}}, ["end_file", {%{$_[0]}}]; + } + else { $this->{TARGET}->end_file(@_) if $this->{TARGET}; } } @@ -123,8 +134,9 @@ sub end_file { sub next_section { my $this = shift; if (exists($this->{DELAYED_COMMANDS})) { - push @{$this->{DELAYED_COMMANDS}}, [ "section", { %{$_[0]} } ]; - } else { + push @{$this->{DELAYED_COMMANDS}}, ["section", {%{$_[0]}}]; + } + else { $this->{TARGET}->next_section(@_) if $this->{TARGET}; } } diff --git a/Bugzilla/PatchReader/NarrowPatch.pm b/Bugzilla/PatchReader/NarrowPatch.pm index 1441e8366..2dd1a647f 100644 --- a/Bugzilla/PatchReader/NarrowPatch.pm +++ b/Bugzilla/PatchReader/NarrowPatch.pm @@ -6,7 +6,8 @@ use 5.10.1; use strict; use warnings; -@Bugzilla::PatchReader::NarrowPatch::ISA = qw(Bugzilla::PatchReader::FilterPatch); +@Bugzilla::PatchReader::NarrowPatch::ISA + = qw(Bugzilla::PatchReader::FilterPatch); sub new { my $class = shift; @@ -22,7 +23,9 @@ sub new { sub start_file { my $this = shift; my ($file) = @_; - if (grep { $_ eq substr($file->{filename}, 0, length($_)) } @{$this->{INCLUDE_FILES}}) { + if (grep { $_ eq substr($file->{filename}, 0, length($_)) } + @{$this->{INCLUDE_FILES}}) + { $this->{IS_INCLUDED} = 1; $this->{TARGET}->start_file(@_) if $this->{TARGET}; } diff --git a/Bugzilla/PatchReader/PatchInfoGrabber.pm b/Bugzilla/PatchReader/PatchInfoGrabber.pm index 6fb35fd16..96d20d0ba 100644 --- a/Bugzilla/PatchReader/PatchInfoGrabber.pm +++ b/Bugzilla/PatchReader/PatchInfoGrabber.pm @@ -6,7 +6,8 @@ use 5.10.1; use strict; use warnings; -@Bugzilla::PatchReader::PatchInfoGrabber::ISA = qw(Bugzilla::PatchReader::FilterPatch); +@Bugzilla::PatchReader::PatchInfoGrabber::ISA + = qw(Bugzilla::PatchReader::FilterPatch); sub new { my $class = shift; @@ -31,16 +32,18 @@ sub start_patch { sub start_file { my $this = shift; my ($file) = @_; - $this->{PATCH_INFO}{files}{$file->{filename}} = { %{$file} }; - $this->{FILE} = { %{$file} }; + $this->{PATCH_INFO}{files}{$file->{filename}} = {%{$file}}; + $this->{FILE} = {%{$file}}; $this->{TARGET}->start_file(@_) if $this->{TARGET}; } sub next_section { my $this = shift; my ($section) = @_; - $this->{PATCH_INFO}{files}{$this->{FILE}{filename}}{plus_lines} += $section->{plus_lines}; - $this->{PATCH_INFO}{files}{$this->{FILE}{filename}}{minus_lines} += $section->{minus_lines}; + $this->{PATCH_INFO}{files}{$this->{FILE}{filename}}{plus_lines} + += $section->{plus_lines}; + $this->{PATCH_INFO}{files}{$this->{FILE}{filename}}{minus_lines} + += $section->{minus_lines}; $this->{TARGET}->next_section(@_) if $this->{TARGET}; } diff --git a/Bugzilla/PatchReader/Raw.pm b/Bugzilla/PatchReader/Raw.pm index bb5a6cefd..06055c103 100644 --- a/Bugzilla/PatchReader/Raw.pm +++ b/Bugzilla/PatchReader/Raw.pm @@ -25,7 +25,7 @@ use Bugzilla::PatchReader::Base; sub new { my $class = shift; $class = ref($class) || $class; - my $this = $class->SUPER::new(); + my $this = $class->SUPER::new(); bless $this, $class; return $this; @@ -49,7 +49,8 @@ sub next_line { if ($1 eq "/dev/null") { $this->{FILE_STATE}{is_add} = 1; - } else { + } + else { $this->{FILE_STATE}{filename} = $1; } $this->{FILE_STATE}{old_date_str} = $2; @@ -57,7 +58,8 @@ sub next_line { $this->{IN_HEADER} = 1; - } elsif ($line =~ /^\+\+\+\s*([\S ]+)\s*\t([^\t\r\n]*)(\S*)/) { + } + elsif ($line =~ /^\+\+\+\s*([\S ]+)\s*\t([^\t\r\n]*)(\S*)/) { if ($1 eq "/dev/null") { $this->{FILE_STATE}{is_remove} = 1; } @@ -66,45 +68,57 @@ sub next_line { $this->{IN_HEADER} = 1; - } elsif ($line =~ /^RCS file: ([\S ]+)/) { + } + elsif ($line =~ /^RCS file: ([\S ]+)/) { $this->{FILE_STATE}{rcs_filename} = $1; $this->{IN_HEADER} = 1; - } elsif ($line =~ /^retrieving revision (\S+)/) { + } + elsif ($line =~ /^retrieving revision (\S+)/) { $this->{FILE_STATE}{old_revision} = $1; $this->{IN_HEADER} = 1; - } elsif ($line =~ /^Index:\s*([\S ]+)/) { + } + elsif ($line =~ /^Index:\s*([\S ]+)/) { $this->_maybe_end_file(); $this->{FILE_STATE}{filename} = $1; $this->{IN_HEADER} = 1; - } elsif ($line =~ /^diff\s*(-\S+\s*)*(\S+)\s*(\S*)/ && $3) { + } + elsif ($line =~ /^diff\s*(-\S+\s*)*(\S+)\s*(\S*)/ && $3) { + # Simple diff <dir> <dir> $this->_maybe_end_file(); $this->{FILE_STATE}{filename} = $2; $this->{IN_HEADER} = 1; - # section parsing - } elsif ($line =~ /^@@\s*-(\d+),?(\d*)\s*\+(\d+),?(\d*)\s*(?:@@\s*(.*))?/) { + # section parsing + } + elsif ($line =~ /^@@\s*-(\d+),?(\d*)\s*\+(\d+),?(\d*)\s*(?:@@\s*(.*))?/) { $this->{IN_HEADER} = 0; $this->_maybe_start_file(); $this->_maybe_end_section(); $2 = 0 if !defined($2); $4 = 0 if !defined($4); - $this->{SECTION_STATE} = { old_start => $1, old_lines => $2, - new_start => $3, new_lines => $4, - func_info => $5, - minus_lines => 0, plus_lines => 0, - }; + $this->{SECTION_STATE} = { + old_start => $1, + old_lines => $2, + new_start => $3, + new_lines => $4, + func_info => $5, + minus_lines => 0, + plus_lines => 0, + }; + + } + elsif ($line =~ /^(\d+),?(\d*)([acd])(\d+),?(\d*)/) { - } elsif ($line =~ /^(\d+),?(\d*)([acd])(\d+),?(\d*)/) { # Non-universal diff. Calculate as though it were universal. $this->{IN_HEADER} = 0; @@ -116,44 +130,56 @@ sub next_line { my $new_start; my $new_lines; if ($3 eq 'a') { + # 'a' has the old number one off from diff -u ("insert after this line" # vs. "insert at this line") $old_start = $1 + 1; $old_lines = 0; - } else { + } + else { $old_start = $1; $old_lines = $2 ? ($2 - $1 + 1) : 1; } if ($3 eq 'd') { + # 'd' has the new number one off from diff -u ("delete after this line" # vs. "delete at this line") $new_start = $4 + 1; $new_lines = 0; - } else { + } + else { $new_start = $4; $new_lines = $5 ? ($5 - $4 + 1) : 1; } - $this->{SECTION_STATE} = { old_start => $old_start, old_lines => $old_lines, - new_start => $new_start, new_lines => $new_lines, - minus_lines => 0, plus_lines => 0 - }; + $this->{SECTION_STATE} = { + old_start => $old_start, + old_lines => $old_lines, + new_start => $new_start, + new_lines => $new_lines, + minus_lines => 0, + plus_lines => 0 + }; } # line parsing (only when inside a section) return if $this->{IN_HEADER}; if ($line =~ /^ /) { push @{$this->{SECTION_STATE}{lines}}, $line; - } elsif ($line =~ /^-/) { + } + elsif ($line =~ /^-/) { $this->{SECTION_STATE}{minus_lines}++; push @{$this->{SECTION_STATE}{lines}}, $line; - } elsif ($line =~ /^\+/) { + } + elsif ($line =~ /^\+/) { $this->{SECTION_STATE}{plus_lines}++; push @{$this->{SECTION_STATE}{lines}}, $line; - } elsif ($line =~ /^< /) { + } + elsif ($line =~ /^< /) { $this->{SECTION_STATE}{minus_lines}++; push @{$this->{SECTION_STATE}{lines}}, "-" . substr($line, 2); - } elsif ($line =~ /^> /) { + } + elsif ($line =~ /^> /) { $this->{SECTION_STATE}{plus_lines}++; push @{$this->{SECTION_STATE}{lines}}, "+" . substr($line, 2); } @@ -179,14 +205,15 @@ sub end_lines { sub _init_state { my $this = shift; $this->{SECTION_STATE}{minus_lines} ||= 0; - $this->{SECTION_STATE}{plus_lines} ||= 0; + $this->{SECTION_STATE}{plus_lines} ||= 0; } sub _maybe_start_file { my $this = shift; $this->_init_state(); - if (exists($this->{FILE_STATE}) && !$this->{FILE_STARTED} || - $this->{FILE_NEVER_STARTED}) { + if (exists($this->{FILE_STATE}) && !$this->{FILE_STARTED} + || $this->{FILE_NEVER_STARTED}) + { $this->_start_file(); } } @@ -198,6 +225,7 @@ sub _maybe_end_file { $this->_maybe_end_section(); if (exists($this->{FILE_STATE})) { + # Handle empty patch sections (if the file has not been started and we're # already trying to end it, start it first!) if (!$this->{FILE_STARTED}) { @@ -216,7 +244,7 @@ sub _start_file { # Send start notification and set state if (!$this->{FILE_STATE}) { - $this->{FILE_STATE} = { filename => "file_not_specified_in_diff" }; + $this->{FILE_STATE} = {filename => "file_not_specified_in_diff"}; } # Send start notification and set state |