From 8ec8da0491ad89604700b3e29a227966f6d84ba1 Mon Sep 17 00:00:00 2001 From: Perl Tidy Date: Wed, 5 Dec 2018 15:38:52 -0500 Subject: no bug - reformat all the code using the new perltidy rules --- Bugzilla/PatchReader/Raw.pm | 86 ++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 29 deletions(-) (limited to 'Bugzilla/PatchReader/Raw.pm') 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 $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 -- cgit v1.2.3-24-g4f1b