]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/bugreport.cgi
merge changes from don source
[debbugs.git] / cgi / bugreport.cgi
index 456bd69e9091d7264dc0de750e3bc0b36b50d8e3..790e1a2ce5dc1a23f9eb385f45ba6f3792e189b7 100755 (executable)
@@ -15,7 +15,7 @@ use Debbugs::Config qw(:globals :text);
 use Debbugs::Log qw(read_log_records);
 use Debbugs::CGI qw(:url :html :util);
 use Debbugs::CGI::Bugreport qw(:all);
-use Debbugs::Common qw(buglog getmaintainers);
+use Debbugs::Common qw(buglog getmaintainers make_list bug_status);
 use Debbugs::Packages qw(getpkgsrc);
 use Debbugs::Status qw(splitpackages get_bug_status isstrongseverity);
 
@@ -23,6 +23,9 @@ use Scalar::Util qw(looks_like_number);
 
 use Debbugs::Text qw(:templates);
 
+use List::Util qw(max);
+
+
 use CGI::Simple;
 my $q = new CGI::Simple;
 
@@ -58,20 +61,13 @@ my $reverse = $param{'reverse'} eq 'yes';
 my $mbox = $param{'mbox'} eq 'yes';
 my $mime = $param{'mime'} eq 'yes';
 
-my $trim_headers = ($param{trim} || ((defined $msg and $msg)?'no':'yes')) eq 'yes';
-
-my $mbox_status_message = $param{mboxstat} eq 'yes';
-my $mbox_maint = $param{mboxmaint} eq 'yes';
-$mbox = 1 if $mbox_status_message or $mbox_maint;
-
-
-# Not used by this script directly, but fetch these so that pkgurl() and
-# friends can propagate them correctly.
-my $archive = $param{'archive'} eq 'yes';
-my $repeatmerged = $param{'repeatmerged'} eq 'yes';
+my %bugusertags;
+my %ut;
+my %seen_users;
 
 my $buglog = buglog($ref);
-if (not defined $buglog) {
+my $bug_status = bug_status($ref);
+if (not defined $buglog or not defined $bug_status) {
      print $q->header(-status => "404 No such bug",
                      -type => "text/html",
                      -charset => 'utf-8',
@@ -84,11 +80,10 @@ if (not defined $buglog) {
      exit 0;
 }
 
-my @stat = stat $buglog;
-my $mtime = '';
-if (@stat) {
-     $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
-}
+# the log should almost always be newer, but just in case
+my $log_mtime = +(stat $buglog)[9] || time;
+my $status_mtime = +(stat $bug_status)[9] || time;
+my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime(max($status_mtime,$log_mtime));
 
 if ($q->request_method() eq 'HEAD' and not defined($att) and not $mbox) {
      print $q->header(-type => "text/html",
@@ -98,6 +93,38 @@ if ($q->request_method() eq 'HEAD' and not defined($att) and not $mbox) {
      exit 0;
 }
 
+for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
+    next unless length($user);
+    add_user($user,\%ut,\%bugusertags,\%seen_users);
+}
+
+if (defined $param{usertag}) {
+     for my $usertag (make_list($param{usertag})) {
+         my %select_ut = ();
+         my ($u, $t) = split /:/, $usertag, 2;
+         Debbugs::User::read_usertags(\%select_ut, $u);
+         unless (defined $t && $t ne "") {
+              $t = join(",", keys(%select_ut));
+         }
+         add_user($u,\%ut,\%bugusertags,\%seen_users);
+         push @{$param{tag}}, split /,/, $t;
+     }
+}
+
+
+my $trim_headers = ($param{trim} || ((defined $msg and $msg)?'no':'yes')) eq 'yes';
+
+my $mbox_status_message = $param{mboxstat} eq 'yes';
+my $mbox_maint = $param{mboxmaint} eq 'yes';
+$mbox = 1 if $mbox_status_message or $mbox_maint;
+
+
+# Not used by this script directly, but fetch these so that pkgurl() and
+# friends can propagate them correctly.
+my $archive = $param{'archive'} eq 'yes';
+my $repeatmerged = $param{'repeatmerged'} eq 'yes';
+
+
 
 my $buglogfh;
 if ($buglog =~ m/\.gz$/) {
@@ -110,7 +137,9 @@ if ($buglog =~ m/\.gz$/) {
 }
 
 
-my %status = %{get_bug_status(bug=>$ref)};
+my %status = %{get_bug_status(bug=>$ref,
+                             bugusertags => \%bugusertags,
+                            )};
 
 my @records;
 eval{
@@ -133,13 +162,17 @@ my @log;
 if ( $mbox ) {
      my $date = strftime "%a %b %d %T %Y", localtime;
      if (@records > 1) {
-         print qq(Content-Disposition: attachment; filename="bug_${ref}.mbox"\n);
-         print "Content-Type: text/plain\n\n";
+        print $q->header(-type => "text/plain",
+                         content_disposition => qq(attachment; filename="bug_${ref}.mbox"),
+                         (length $mtime)?(-last_modified => $mtime):(),
+                        );
      }
      else {
          $msg_num++;
-         print qq(Content-Disposition: attachment; filename="bug_${ref}_message_${msg_num}.mbox"\n);
-         print "Content-Type: message/rfc822\n\n";
+         print $q->header(-type => "message/rfc822",
+                          content_disposition => qq(attachment; filename="bug_${ref}_message_${msg_num}.mbox"),
+                          (length $mtime)?(-last_modified => $mtime):(),
+                         );
      }
      if ($mbox_status_message and @records > 1) {
          my $status_message='';
@@ -207,6 +240,7 @@ else {
                                     msg_num => $msg_num,
                                     att => $att,
                                     msg => $msg,
+                                    trim_headers => $trim_headers,
                                    );
          exit 0;
      }
@@ -258,10 +292,20 @@ my %package;
 my @packages = splitpackages($status{package});
 
 foreach my $pkg (@packages) {
-     $package{$pkg} = {maintainer => exists($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)',
-                      exists($pkgsrc{$pkg}) ? (source => $pkgsrc{$pkg}) : (),
-                      package    => $pkg,
-                     };
+     if ($pkg =~ /^src\:/) {
+         my ($srcpkg) = $pkg =~ /^src:(.*)/;
+         $package{$pkg} = {maintainer => exists($maintainer{$srcpkg}) ? $maintainer{$srcpkg} : '(unknown)',
+                           source     => $srcpkg,
+                           package    => $pkg,
+                           is_source  => 1,
+                          };
+     }
+     else {
+         $package{$pkg} = {maintainer => exists($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)',
+                           exists($pkgsrc{$pkg}) ? (source => $pkgsrc{$pkg}) : (),
+                           package    => $pkg,
+                          };
+     }
 }
 
 # fixup various bits of the status
@@ -328,6 +372,7 @@ print fill_in_template(template => 'cgi/bugreport',
                                     log           => $log,
                                     bug_num       => $ref,
                                     version_graph => $version_graph,
+                                    msg           => $msg,
                                     isstrongseverity => \&Debbugs::Status::isstrongseverity,
                                     html_escape   => \&Debbugs::CGI::html_escape,
                                     looks_like_number => \&Scalar::Util::looks_like_number,