From 066d6bfbde6376d094d43142b0727cf7d432b644 Mon Sep 17 00:00:00 2001
From: ajt <>
Date: Thu, 11 Aug 2005 07:48:09 -0800
Subject: [PATCH] [project @ 2005-08-11 08:48:09 by ajt] * remove "use
 IO::Lines" line from bugreport.cgi   * add "report spam" link to
 bugreport.cgi   * improve by-*.idx handling to support archive indexes and be
 slightly faster   * add link to archived bug pages to pkgreport.cgi

---
 cgi/bugreport.cgi |  3 ++-
 cgi/common.pl     | 47 +++++++++++++++++++++++++++++++++++++++++------
 cgi/pkgreport.cgi |  6 ++++++
 3 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/cgi/bugreport.cgi b/cgi/bugreport.cgi
index a07fc0d4..9c8e8135 100755
--- a/cgi/bugreport.cgi
+++ b/cgi/bugreport.cgi
@@ -7,7 +7,6 @@ use POSIX qw(strftime tzset);
 use MIME::Parser;
 use MIME::Decoder;
 use IO::Scalar;
-use IO::Lines;
 use IO::File;
 
 #require '/usr/lib/debbugs/errorlib';
@@ -493,6 +492,8 @@ print "$descriptivehead\n";
 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
 print "<HR>";
 print "$log";
+print "<HR>";
+print "Report that <a href=\"/cgi-bin/bugspam.cgi?bug=$ref\">this bug log contains spam</a>.<HR>\n";
 print $tail_html;
 
 print "</BODY></HTML>\n";
diff --git a/cgi/common.pl b/cgi/common.pl
index b02bed43..6270f89c 100644
--- a/cgi/common.pl
+++ b/cgi/common.pl
@@ -101,6 +101,8 @@ my $common_dist;
 my $common_arch;
 
 my $debug = 0;
+my $use_bug_idx = 0;
+my %bugidx;
 
 sub array_option($) {
     my ($val) = @_;
@@ -133,6 +135,17 @@ sub filter_option($$\%) {
 
 sub set_option {
     my ($opt, $val) = @_;
+    if ($opt eq "use-bug-idx") {
+	$use_bug_idx = $val;
+	if ( $val ) {
+	    $common_headers{pending}{open} = $common_headers{pending}{pending};
+	    my $bugidx = tie %bugidx, MLDBM => "$debbugs::gSpoolDir/realtime/bug.idx", O_RDONLY
+		or quitcgi( "$0: can't open $debbugs::gSpoolDir/realtime/bug.idx ($!)\n" );
+	    $bugidx->RemoveTaint(1);
+	} else {
+	    untie %bugidx;
+	}
+    }
     if ($opt =~ m/^show_list_(foot|head)er$/) { $common{$opt} = $val; }
     if ($opt eq "archive") { $common_archive = $val; }
     if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
@@ -643,18 +656,33 @@ sub getbugs {
 
     my @result = ();
 
-    if (!$common_archive && defined $opt && 
-        -e "$debbugs::gSpoolDir/by-$opt.idx") 
-    {
+    my $fastidx;
+    if (!defined $opt) {
+        # leave $fastidx undefined;
+    } elsif (!$common_archive) {
+        $fastidx = "$debbugs::gSpoolDir/by-$opt.idx";
+    } else {
+        $fastidx = "$debbugs::gSpoolDir/by-$opt-arc.idx";
+    }
+
+    if (defined $fastidx && -e $fastidx) {
         my %lookup;
 print STDERR "optimized\n" if ($debug);
-        tie %lookup, DB_File => "$debbugs::gSpoolDir/by-$opt.idx", O_RDONLY
-            or die "$0: can't open $debbugs::gSpoolDir/by-$opt.idx ($!)\n";
+        tie %lookup, DB_File => $fastidx, O_RDONLY
+            or die "$0: can't open $fastidx ($!)\n";
 	while ($key = shift) {
             my $bugs = $lookup{$key};
             if (defined $bugs) {
                 push @result, (unpack 'N*', $bugs);
-            }
+            } elsif (defined $lookup{"count $key"}) {
+		my $which = 0;
+		while (1) {
+		    $bugs = $lookup{"$which $key"};
+		    last unless defined $bugs;
+		    push @result, (unpack 'N*', $bugs);
+		    $which += 100;
+		}
+	    }
         }
 	untie %lookup;
 print STDERR "done optimized\n" if ($debug);
@@ -753,6 +781,13 @@ sub getbugstatus {
 
     my %status;
 
+    if ( $use_bug_idx eq 1 && exists( $bugidx{ $bugnum } ) ) {
+	%status = %{ $bugidx{ $bugnum } };
+	$status{ pending } = $status{ status };
+	$status{ id } = $bugnum;
+	return \%status;
+    }
+
     my $location = getbuglocation( $bugnum, 'summary' );
     return {} if ( !$location );
     %status = %{ readbug( $bugnum, $location ) };
diff --git a/cgi/pkgreport.cgi b/cgi/pkgreport.cgi
index 74bf6065..1f80561e 100755
--- a/cgi/pkgreport.cgi
+++ b/cgi/pkgreport.cgi
@@ -114,6 +114,7 @@ set_option("sev-inc", $sev_inc);
 set_option("version", $version);
 set_option("dist", $dist);
 set_option("arch", $arch);
+set_option("use-bug-idx", defined($param{'use-bug-idx'}) ? $param{'use-bug-idx'} : 0);
 set_option("show_list_header", $show_list_header);
 set_option("show_list_footer", $show_list_footer);
 
@@ -301,6 +302,11 @@ if (defined $pkg || defined $src) {
 		push @references, sprintf "to the source package <a href=\"%s\">%s</a>'s bug page", srcurl($srcforpkg), htmlsanit($srcforpkg);
 	    }
 	}
+	if ($pkg) {
+	    set_option("archive", !$archive);
+	    push @references, sprintf "to the <a href=\"%s\">%s reports for %s</a>", pkgurl($pkg), ($archive ? "active" : "archived"), htmlsanit($pkg);
+	    set_option("archive", $archive);
+	}
 	if (@references) {
 	    $references[$#references] = "or $references[$#references]" if @references > 1;
 	    print "<p>You might like to refer ", join(", ", @references), ".</p>\n";
-- 
2.39.5