From: doogie <> Date: Wed, 17 Sep 2003 03:32:13 +0000 (-0800) Subject: [project @ 2003-09-16 20:32:12 by doogie] X-Git-Tag: release/2.6.0~794 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fd97b9e7ecdd0fb29790e726b65d105069f1306f;p=debbugs.git [project @ 2003-09-16 20:32:12 by doogie] * Rewrite filtering in common.pl, to make it completely generic. Filtering can now work against any field. * Rewrite grouping logic in cgi's common.pl, to make it completely generic. There is now no longer 2 nested loops, to do the grouping. This makes adding new grouping levels simpler for the future. --- diff --git a/cgi/common.pl b/cgi/common.pl index 103a0c80..ada69ecc 100644 --- a/cgi/common.pl +++ b/cgi/common.pl @@ -19,73 +19,119 @@ my %common_include = (); my %common_exclude = (); my $common_raw_sort = 0; my $common_bug_reverse = 0; -my $common_pending_reverse = 0; -my $common_severity_reverse = 0; -my @common_pending_include = (); -my @common_pending_exclude = (); -my @common_severity_include = (); -my @common_severity_exclude = (); +my %common_reverse = ( + 'pending' => 0, + 'severity' => 0, +); +sub exact_field_match { + my ($field, $values, $status) = @_; + my @values = @$values; + my @ret = grep {$_ eq $status->{$field} } @values; + $#ret != -1; +} +sub contains_field_match { + my ($field, $values, $status) = @_; + foreach my $data (@$values) { + return 1 if (index($status->{$field}, $data) > -1); + } + return 0; +} + +my %field_match = ( + 'subject' => \&contains_field_match, + 'tags' => sub { + my ($field, $values, $status) = @_; + my %values = map {$_=>1} @$values; + foreach my $t (split /\s+/, $status->{$field}) { + return 1 if (defined $values{$t}); + } + return 0; + }, + 'severity' => \&exact_field_match, + 'pending' => \&exact_field_match, + 'originator' => \%contains_field_match, + 'forwarded' => \%contains_field_match, + 'owner' => \%contains_field_match, +); +my @common_grouping = ( 'severity', 'pending' ); +my %common_grouping_order = ( + 'pending' => [ qw( pending forwarded pending-fixed fixed done absent ) ], + 'severity' => \@debbugs::gSeverityList, +); +my %common_headers = ( + 'pending' => { + "pending" => "outstanding", + "pending-fixed" => "pending upload", + "fixed" => "fixed in NMU", + "done" => "resolved", + "forwarded" => "forwarded to upstream software authors", + "absent" => "not applicable to this version", + }, + 'severity' => \%debbugs::gSeverityDisplay, +); + my $common_version; my $common_dist; my $common_arch; my $debug = 0; +sub array_option($) { + my ($val) = @_; + my @vals; + @vals = ( $val ) if (ref($val) eq "" && $val ); + @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val ); + @vals = @{$val} if (ref($val) eq "ARRAY" ); + return @vals; +} + +sub filter_include_exclude($\%) { + my ($val, $filter_map) = @_; + my @vals = array_option($val); + my @data = map { + if (/^([^:]*):(.*)$/) { if ($1 eq 'subj') { ['subject', $2]; } else { [$1, $2] } } else { ['tags', $_] } + } split /[\s,]+/, join ',', @vals; + foreach my $data (@data) { + &quitcgi("Invalid filter key: '$data->[0]'") if (!exists($filter_map->{$data->[0]})); + push @{$filter_map->{$data->[0]}}, $data->[1]; + } +} + +sub filter_option($$\%) { + my ($key, $val, $filter_map) = @_; + my @vals = array_option($val); + foreach $val (@vals) { + push @{$filter_map->{$key}}, $val; + } +} + sub set_option { my ($opt, $val) = @_; if ($opt eq "archive") { $common_archive = $val; } if ($opt eq "repeatmerged") { $common_repeatmerged = $val; } if ($opt eq "exclude") { - my @vals; - @vals = ( $val ) if (ref($val) eq "" && $val ); - @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - %common_exclude = map { - if (/^([^:]*):(.*)$/) { ($1, $2) } else { ($_, 1) } - } split /[\s,]+/, join ',', @vals; + filter_include_exclude($val, %common_exclude); } if ($opt eq "include") { - my @vals; - @vals = ( $val, ) if (ref($val) eq "" && $val ); - @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - %common_include = map { - if (/^([^:]*):(.*)$/) { ($1, $2) } else { ($_, 1) } - } split /[\s,]+/, join ',', @vals; + filter_include_exclude($val, %common_include); } if ($opt eq "raw") { $common_raw_sort = $val; } if ($opt eq "bug-rev") { $common_bug_reverse = $val; } - if ($opt eq "pend-rev") { $common_pending_reverse = $val; } - if ($opt eq "sev-rev") { $common_severity_reverse = $val; } + if ($opt eq "pend-rev") { $common_reverse{pending} = $val; } + if ($opt eq "sev-rev") { $common_reverse{severity} = $val; } if ($opt eq "pend-exc") { - my @vals; - @vals = ( $val ) if (ref($val) eq "" && $val ); - @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - @common_pending_exclude = @vals if (@vals); + filter_option('pending', $val, %common_exclude); } if ($opt eq "pend-inc") { - my @vals; - @vals = ( $val, ) if (ref($val) eq "" && $val ); - @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - @common_pending_include = @vals if (@vals); + filter_option('pending', $val, %common_include); } if ($opt eq "sev-exc") { - my @vals; - @vals = ( $val ) if (ref($val) eq "" && $val ); - @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - @common_severity_exclude = @vals if (@vals); + filter_option('severity', $val, %common_exclude); } if ($opt eq "sev-inc") { - my @vals; - @vals = ( $val ) if (ref($val) eq "" && $val ); - @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val ); - @vals = @{$val} if (ref($val) eq "ARRAY" ); - @common_severity_include = @vals if (@vals); + filter_option('severity', $val, %common_include); } if ($opt eq "version") { $common_version = $val; } if ($opt eq "dist") { $common_dist = $val; } @@ -393,19 +439,35 @@ sub allbugs { return @{getbugs(sub { 1 })}; } +sub bugmatches(\%\%) { + my ($hash, $status) = @_; + while ((my ($key, $value) = each(%$hash))) { + my $sub = $field_match{$key}; + return 1 if ($sub->($key, $value, $status)); + } + return 0; +} +sub bugfilter($%) { + my ($bug, %status) = @_; + local (%seenmerged); + if (%common_include) { + return 1 if (!bugmatches(%common_include, %status)); + } + if (%common_exclude) { + return 1 if (bugmatches(%common_exclude, %status)); + } + my @merged = sort {$a<=>$b} $bug, split(/ /, $status{mergedwith}); + return 1 unless ($common_repeatmerged || !$seenmerged{$merged[0]}); + $seenmerged{$merged[0]} = 1; + return 0; +} + sub htmlizebugs { $b = $_[0]; my @bugs = @$b; - my @rawsort; - - my %section = (); + my $anydone = 0; - my %displayshowpending = ("pending", "outstanding", - "pending-fixed", "pending upload", - "fixed", "fixed in NMU", - "done", "resolved", - "forwarded", "forwarded to upstream software authors", - "absent", "not applicable to this version"); + my @status = (); if (@bugs == 0) { return "