]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Bugs.pm
make all of the options for get_bugs_* come from a single set of common options
[debbugs.git] / Debbugs / Bugs.pm
index f7a6fbb52f1b7870423bab84e25f02ada6ddb5ec..1e8eb701c1346686e4ac45fa57145aad555bfb82 100644 (file)
@@ -54,8 +54,8 @@ use Debbugs::Config qw(:config);
 use Params::Validate qw(validate_with :types);
 use IO::File;
 use Debbugs::Status qw(splitpackages get_bug_status);
-use Debbugs::Packages qw(getsrcpkgs);
-use Debbugs::Common qw(getparsedaddrs getmaintainers getmaintainers_reverse make_list);
+use Debbugs::Packages qw(getsrcpkgs getpkgsrc);
+use Debbugs::Common qw(getparsedaddrs package_maintainer getmaintainers make_list hash_slice);
 use Fcntl qw(O_RDONLY);
 use MLDBM qw(DB_File Storable);
 use List::Util qw(first);
@@ -152,55 +152,60 @@ bug should not.
 
 =cut
 
+my %_get_bugs_common_options =
+    (package   => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     src       => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     maint     => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     submitter => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     severity  => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     status    => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     tag       => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     owner     => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     dist      => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     correspondent => {type => SCALAR|ARRAYREF,
+                       optional => 1,
+                      },
+     affects   => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     function  => {type => CODEREF,
+                   optional => 1,
+                  },
+     bugs      => {type => SCALAR|ARRAYREF,
+                   optional => 1,
+                  },
+     archive   => {type => BOOLEAN|SCALAR,
+                   default => 0,
+                  },
+     usertags  => {type => HASHREF,
+                   optional => 1,
+                  },
+    );
+
+
+my $_get_bugs_options = {%_get_bugs_common_options};
 sub get_bugs{
      my %param = validate_with(params => \@_,
-                              spec   => {package   => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         src       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         maint     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         submitter => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         severity  => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         status    => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         tag       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         owner     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         dist      => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         correspondent => {type => SCALAR|ARRAYREF,
-                                                           optional => 1,
-                                                          },
-                                         affects   => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         function  => {type => CODEREF,
-                                                       optional => 1,
-                                                      },
-                                         bugs      => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         archive   => {type => BOOLEAN|SCALAR,
-                                                       default => 0,
-                                                      },
-                                         usertags  => {type => HASHREF,
-                                                       optional => 1,
-                                                      },
-                                        },
-                             );
+                              spec   => $_get_bugs_options,
+                              );
 
      # Normalize options
      my %options = %param;
@@ -325,7 +330,7 @@ sub bug_filter {
                                                          optional => 1,
                                                         },
                                          repeat_merged => {type => BOOLEAN,
-                                                           optional => 1,
+                                                           default => 1,
                                                           },
                                          include => {type => HASHREF,
                                                      optional => 1,
@@ -388,45 +393,17 @@ searches.
 
 =cut
 
+
+my $_get_bugs_by_idx_options =
+   {hash_slice(%_get_bugs_common_options,
+               (qw(package submitter severity tag archive),
+                qw(owner src maint bugs correspondent),
+                qw(affects usertags))
+              )
+   };
 sub get_bugs_by_idx{
      my %param = validate_with(params => \@_,
-                              spec   => {package   => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         submitter => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         severity  => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         tag       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         archive   => {type => BOOLEAN,
-                                                       default => 0,
-                                                      },
-                                         owner     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         src       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         maint     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         bugs      => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         correspondent => {type => SCALAR|ARRAYREF,
-                                                           optional => 1,
-                                                          },
-                                         affects => {type => SCALAR|ARRAYREF,
-                                                     optional => 1,
-                                                    },
-                                         usertags  => {type => HASHREF,
-                                                       optional => 1,
-                                                      },
-                                        },
+                              spec   => $_get_bugs_by_idx_options
                              );
      my %bugs = ();
 
@@ -504,55 +481,15 @@ searches. [Or at least, that's the idea.]
 
 =cut
 
+my $_get_bugs_flatfile_options =
+   {hash_slice(%_get_bugs_common_options,
+               map {$_ eq 'dist'?():($_)} keys %_get_bugs_common_options
+              )
+   };
+
 sub get_bugs_flatfile{
      my %param = validate_with(params => \@_,
-                              spec   => {package   => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         src       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         maint     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         submitter => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         severity  => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         status    => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         tag       => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         owner     => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         correspondent => {type => SCALAR|ARRAYREF,
-                                                           optional => 1,
-                                                          },
-                                         affects   => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-# not yet supported
-#                                        dist      => {type => SCALAR|ARRAYREF,
-#                                                      optional => 1,
-#                                                     },
-                                         bugs      => {type => SCALAR|ARRAYREF,
-                                                       optional => 1,
-                                                      },
-                                         archive   => {type => BOOLEAN,
-                                                       default => 1,
-                                                      },
-                                         usertags  => {type => HASHREF,
-                                                       optional => 1,
-                                                      },
-                                         function  => {type => CODEREF,
-                                                       optional => 1,
-                                                      },
-                                        },
+                              spec   => $_get_bugs_flatfile_options
                              );
      my $flatfile;
      if ($param{archive}) {
@@ -572,20 +509,27 @@ sub get_bugs_flatfile{
      }
      my $unmaintained_packages = 0;
      # unmaintained packages is a special case
-     for my $maint (make_list(exists $param{maint}?$param{maint}:[])) {
+     my @maints = make_list(exists $param{maint}?$param{maint}:[]);
+     $param{maint} = [];
+     for my $maint (@maints) {
          if (defined $maint and $maint eq '' and not $unmaintained_packages) {
               $unmaintained_packages = 1;
               our %maintainers = %{getmaintainers()};
-              $param{function} = [exists $param{function}?
-                                  (ref $param{function}?@{$param{function}}:$param{function}):(),
+              $param{function} = [(exists $param{function}?
+                                   (ref $param{function}?@{$param{function}}:$param{function}):()),
                                   sub {my %d=@_;
-                                       foreach my $try (splitpackages($d{"pkg"})) {
+                                       foreach my $try (make_list($d{"pkg"})) {
+                                            next unless length $try;
+                                            ($try) = $try =~ m/^(?:src:)?(.+)/;
                                             return 1 if not exists $maintainers{$try};
                                        }
                                        return 0;
                                   }
                                  ];
          }
+         elsif (defined $maint and $maint ne '') {
+              push @{$param{maint}},$maint;
+         }
      }
      # We handle src packages, maint and maintenc by mapping to the
      # appropriate binary packages, then removing all packages which
@@ -616,7 +560,7 @@ sub get_bugs_flatfile{
      }
      my @bugs;
      BUG: while (<$flatfile>) {
-         next unless m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/;
+         next unless m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*(.*)\s*\]\s+(\w+)\s+(.*)$/;
          my ($pkg,$bug,$time,$status,$submitter,$severity,$tags) = ($1,$2,$3,$4,$5,$6,$7);
          next if $grep_bugs and not exists $bugs{$bug};
          if (exists $param{package}) {
@@ -711,22 +655,34 @@ sub __handle_pkg_src_and_maint{
          # We only want to increment the number of keys if there is
          # something to match
          my $key_inc = 0;
-         for my $package ((map { getsrcpkgs($_)} make_list($param{src}))) {
-              $packages{$package}++;
+         # in case there are binaries with the same name as the
+         # source
+         my %_temp_p = ();
+         for my $package ((map {getsrcpkgs($_)} make_list($param{src}))) {
+              $packages{$package}++ unless exists $_temp_p{$package};
+              $_temp_p{$package} = 1;
               $key_inc=1;
          }
          for my $package (make_list($param{src})) {
-              $packages{"src:$package"}++;
+              $packages{"src:$package"}++ unless exists $_temp_p{"src:$package"};
+              $_temp_p{"src:$package"} = 1;
               $key_inc=1;
+              # As a temporary hack, we will also include $param{src}
+              # in this list for packages passed which do not have a
+              # corresponding binary package
+              if (not exists getpkgsrc()->{$package}) {
+                  $packages{$package}++ unless exists $_temp_p{$package};
+                  $_temp_p{$package} = 1;
+              }
          }
          $package_keys += $key_inc;
      }
      if (exists $param{maint}) {
          my $key_inc = 0;
-         my $maint_rev = getmaintainers_reverse();
-         for my $package (map { exists $maint_rev->{$_}?@{$maint_rev->{$_}}:()}
-                          make_list($param{maint})) {
-              $packages{$package}++;
+         my %_temp_p = ();
+         for my $package (package_maintainer(maintainer=>$param{maint})) {
+              $packages{$package}++ unless exists $_temp_p{$package};
+              $_temp_p{$package} = 1;
               $key_inc = 1;
          }
          $package_keys += $key_inc;
@@ -756,7 +712,11 @@ sub __bug_matches {
     my ($hash, $status) = @_;
     foreach my $key( keys( %$hash ) ) {
         my $value = $hash->{$key};
+       next unless exists $field_match{$key};
        my $sub = $field_match{$key};
+       if (not defined $sub) {
+           die "No defined subroutine for key: $key";
+       }
        return 1 if ($sub->($key, $value, $status));
     }
     return 0;