]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Status.pm
* Stop useless overspecification of variables in Debbugs::Packages
[debbugs.git] / Debbugs / Status.pm
index c28dd08f91755841ebc9549d0a40476e3503c982..3a7df96bc5878607810e781c0bbf34f8390004c0 100644 (file)
@@ -28,10 +28,10 @@ use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
 use base qw(Exporter);
 
 use Params::Validate qw(validate_with :types);
-use Debbugs::Common qw(:util :lock);
+use Debbugs::Common qw(:util :lock :quit);
 use Debbugs::Config qw(:config);
 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
-use Debbugs::Packages qw(makesourceversions getversions);
+use Debbugs::Packages qw(makesourceversions getversions binarytosource);
 use Debbugs::Versions;
 use Debbugs::Versions::Dpkg;
 use POSIX qw(ceil);
@@ -47,7 +47,7 @@ BEGIN{
                               ],
                     read   => [qw(readbug read_bug lockreadbug)],
                     write  => [qw(writebug makestatus unlockwritebug)],
-                    versions => [qw(addfoundversion addfixedversion),
+                    versions => [qw(addfoundversions addfixedversions),
                                  qw(removefoundversions)
                                 ],
                    );
@@ -133,7 +133,7 @@ sub read_bug{
                                                 optional => 1,
                                                 regex    => qr/^\d+/,
                                                },
-                                        location => {type => SCALAR,
+                                        location => {type => SCALAR|UNDEF,
                                                      optional => 1,
                                                     },
                                         summary  => {type => SCALAR,
@@ -189,6 +189,8 @@ sub read_bug{
         $data{$field} = [split ' ', $data{$field}];
     }
     for my $field (qw(found fixed)) {
+        # create the found/fixed hashes which indicate when a
+        # particular version was marked found or marked fixed.
         @{$data{$field}}{@{$data{"${field}_versions"}}} =
              (('') x (@{$data{"${field}_date"}} - @{$data{"${field}_versions"}}),
               @{$data{"${field}_date"}});
@@ -257,7 +259,7 @@ sub makestatus {
     }
 
     for my $field (qw(found_versions fixed_versions found_date fixed_date)) {
-        $newdata{$field} = [split ' ', $newdata{$field}];
+        $newdata{$field} = join ' ', @{$newdata{$field}||[]};
     }
 
     if ($version < 3) {
@@ -268,7 +270,7 @@ sub makestatus {
 
     if ($version == 1) {
         for my $field (@v1fieldorder) {
-            if (exists $newdata{$field}) {
+            if (exists $newdata{$field} and defined $newdata{$field}) {
                 $contents .= "$newdata{$field}\n";
             } else {
                 $contents .= "\n";
@@ -279,7 +281,8 @@ sub makestatus {
         # further extensibility in the future.
         $contents .= "Format-Version: $version\n";
         for my $field (keys %fields) {
-            if (exists $newdata{$field} and $newdata{$field} ne '') {
+            if (exists $newdata{$field} and defined $newdata{$field}
+               and $newdata{$field} ne '') {
                 # Output field names in proper case, e.g. 'Merged-With'.
                 my $properfield = $fields{$field};
                 $properfield =~ s/(?:^|(?<=-))([a-z])/\u$1/g;
@@ -572,41 +575,45 @@ sub bug_archiveable{
          return $cannot_archive;
      }
      # At this point, we have to get the versioning information for this bug.
-
      # We examine the set of distribution tags. If a bug has no distribution
      # tags set, we assume a default set, otherwise we use the tags the bug
      # has set.
-     my %dist_tags;
-     @dist_tags{@{$config{removal_distribution_tags}}} =
-         (1) x @{$config{removal_distribution_tags}};
-     my %dists;
-     @dists{@{$config{removal_default_distribution_tags}}} = 
-         (1) x @{$config{removal_default_distribution_tags}};
-     for my $tag (split ' ', $status->{tags}) {
-         next unless $dist_tags{$tag};
-         $dists{$tag} = 1;
-     }
-     my %source_versions;
-     for my $dist (keys %dists){
-         my @versions;
-         @versions = getversions($status->{package},
-                                 $dist,
-                                 undef);
-         # TODO: This should probably be handled further out for efficiency and
-         # for more ease of distinguishing between pkg= and src= queries.
-         my @sourceversions = makesourceversions($status->{package},
-                                                 $dist,
-                                                 @versions);
-         @source_versions{@sourceversions} = (1) x @sourceversions;
-     }
-     if ('found' eq max_buggy(bug => $param{bug},
-                             sourceversions => [keys %source_versions],
-                             found          => $status->{found_versions},
-                             fixed          => $status->{fixed_versions},
-                             version_cache  => $version_cache,
-                             package        => $status->{package},
-                            )) {
-         return $cannot_archive;
+
+     # There must be fixed_versions for us to look at the versioning
+     # information
+     if (@{$status->{fixed_versions}}) {
+         my %dist_tags;
+         @dist_tags{@{$config{removal_distribution_tags}}} =
+              (1) x @{$config{removal_distribution_tags}};
+         my %dists;
+         @dists{@{$config{removal_default_distribution_tags}}} = 
+              (1) x @{$config{removal_default_distribution_tags}};
+         for my $tag (split ' ', $status->{tags}) {
+              next unless $dist_tags{$tag};
+              $dists{$tag} = 1;
+         }
+         my %source_versions;
+         for my $dist (keys %dists){
+              my @versions;
+              @versions = getversions($status->{package},
+                                      $dist,
+                                      undef);
+              # TODO: This should probably be handled further out for efficiency and
+              # for more ease of distinguishing between pkg= and src= queries.
+              my @sourceversions = makesourceversions($status->{package},
+                                                      $dist,
+                                                      @versions);
+              @source_versions{@sourceversions} = (1) x @sourceversions;
+         }
+         if ('found' eq max_buggy(bug => $param{bug},
+                                  sourceversions => [keys %source_versions],
+                                  found          => $status->{found_versions},
+                                  fixed          => $status->{fixed_versions},
+                                  version_cache  => $version_cache,
+                                  package        => $status->{package},
+                                 )) {
+              return $cannot_archive;
+         }
      }
      # 6. at least 28 days have passed since the last action has occured or the bug was closed
      # XXX We still need some more work here before we actually can archive;
@@ -896,7 +903,8 @@ sub buggy {
          $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp);
          foreach my $source (keys %sources) {
               my $srchash = substr $source, 0, 1;
-              my $version_fh = new IO::File "$config{version_packages_dir}/$srchash/$source", 'r';
+              my $version_fh = new IO::File "$config{version_packages_dir}/$srchash/$source", 'r' or
+                   warn "Unable to open $config{version_packages_dir}/$srchash/$source: $!" and next;
               $version->load($version_fh);
          }
          if (defined $param{version_cache}) {
@@ -938,13 +946,13 @@ sub update_realtime {
        }
 
        if ($new eq "NOCHANGE") {
-               print IDXNEW $line if ($line ne "" && $line[1] == $bug);
+               print IDXNEW $line if ($line ne ""  and $line[1] == $bug);
        } elsif ($new eq "REMOVE") {
                0;
        } else {
                print IDXNEW $new;
        }
-       if ($line ne "" && $line[1] > $bug) {
+       if (defined $line and $line ne "" and  @line and $line[1] > $bug) {
                print IDXNEW $line;
                $line = "";
        }
@@ -983,8 +991,8 @@ sub bughook {
        (my $pkglist = $data->{package}) =~ s/[,\s]+/,/g;
        $pkglist =~ s/^,+//;
        $pkglist =~ s/,+$//;
-       $whendone = "forwarded" if length $data->{forwarded};
-       $whendone = "done" if length $data->{done};
+       $whendone = "forwarded" if defined $data->{forwarded} and length $data->{forwarded};
+       $whendone = "done" if defined $data->{done} and length $data->{done};
        $severity = $data->{severity} if length $data->{severity};
 
        my $k = sprintf "%s %d %d %s [%s] %s %s\n",