Author: stef-guest
Date: 2008-09-23 23:11:54 +0000 (Tue, 23 Sep 2008)
New Revision: 9877

Modified:
   bin/check-new-issues
Log:
if automatic search gives only a few results, display all of them instead of 
just the count (-a 0 gives the old behaviour)

Modified: bin/check-new-issues
===================================================================
--- bin/check-new-issues        2008-09-23 22:14:19 UTC (rev 9876)
+++ bin/check-new-issues        2008-09-23 23:11:54 UTC (rev 9877)
@@ -7,7 +7,7 @@
 use Term::ReadLine;
 
 my %opts;
-getopts('ln:fhi:t:Tc', \%opts);
+getopts('ln:fhi:t:Tca:', \%opts);
 
 if ($opts{h}) {
     print <<'EOF';
@@ -36,6 +36,8 @@
 -t regexp : use regexp to select todos (default: '^\s+TODO: check$' )
 -T       : same as -t '^\s+TODO: check' (note the missing $)
 -c        : only do syntax check of embedded-code-copies
+-a <n>    : If automatic apt-cache/apt-file search gives more than n results,
+            display only the count (default 10)
 
 EOF
 
@@ -76,6 +78,8 @@
 
 my $issue_regexp= $opts{i} || 'CVE-200[3-9]';
 my $todo_regexp= $opts{t} || ( $opts{T} ? '^\s+TODO: check' : '^\s+TODO: 
check$' );
+my $auto_display_limit = 10;
+$auto_display_limit = $opts{a} if defined $opts{a};
 
 my $editor=$ENV{EDITOR} || $ENV{VISUAL} || "vi";
 
@@ -285,9 +289,13 @@
        if ($prog) {
                my $prog_esc = quotemeta($prog);
                print "doing apt-cache search...";
-               my $ac=`apt-cache search $prog_esc |wc -l`;
-               chomp $ac;
-               print "\r$ac results from apt-cache search $prog\n";
+               my @ac=`apt-cache search $prog_esc`;
+               if (scalar @ac > $auto_display_limit || scalar @ac == 0) {
+                       print "\r", scalar @ac, " results from apt-cache search 
$prog_esc\n";
+               }
+               else {
+                       print "\r=== apt-cache search $prog_esc:\n", @ac, 
"===\n";
+               }
 
                foreach my $p (split /\s+/, $prog) {
                        search_embed($p);
@@ -300,10 +308,22 @@
                if (! exists $afcache{$file}) {
                        my $file_esc = quotemeta($file);
                        print "doing apt-file search...";
-                       $afcache{$file}=`apt-file -i search $file_esc |wc -l`;
-                       chomp $afcache{$file};
+                       $afcache{$file}=[`apt-file -i search $file_esc`];
+                       if (scalar @{$afcache{$file}} > $auto_display_limit) {
+                               # replace with empty array to save mem
+                               my $num = scalar @{$afcache{$file}};
+                               $afcache{$file} = [];
+                               $afcache{$file}->[$num-1] = undef;
+                       }
                }
-               print "\r$afcache{$file} results from apt-file -i search 
$file\n";
+               if (scalar @{$afcache{$file}} > $auto_display_limit ||
+                   scalar @{$afcache{$file}} == 0) {
+                       print "\r", scalar @{$afcache{$file}},
+                             " results from apt-file -i search $file\n";
+               }
+               else {
+                       print "\r=== apt-file -i search $file:\n", 
@{$afcache{$file}}, "===\n";
+               }
        }
 }
 


_______________________________________________
Secure-testing-commits mailing list
Secure-testing-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/secure-testing-commits

Reply via email to