@@ -296,6 +296,8 @@ sub do_grep($$) {
296
296
my $matches = 0;
297
297
my $quick_regexp = escape_parens($regexp );
298
298
my $fd = open_data_pipeline($data );
299
+ my $stream_results = $Conf -> {streaming };
300
+ tty_human_status(' ' ) if $stream_results ;
299
301
debug(1, " Pipeline open, waiting for input" );
300
302
while (<$fd >) {
301
303
@@ -305,13 +307,18 @@ sub do_grep($$) {
305
307
next if !( ( $fname , $pkgs ) = /$regexp /o );
306
308
307
309
debug_line " ." ;
308
- # Put leading slash on file name
309
- push (@{ $ret -> {" /$fname " } },
310
- # ... and extract the package name
311
- map { basename($_ ) } split (m / ,/ , $pkgs )
312
- );
313
- if (++$matches % 10 == 0) {
314
- tty_human_status(" Searching, found $matches results so far ..." );
310
+
311
+ if ($stream_results ) {
312
+ stream_results(" /$fname " , map { basename($_ ) } split (m / ,/ , $pkgs ));
313
+ } else {
314
+ # Put leading slash on file name
315
+ push (@{ $ret -> {" /$fname " } },
316
+ # ... and extract the package name
317
+ map { basename($_ ) } split (m / ,/ , $pkgs )
318
+ );
319
+ if (++$matches % 10 == 0) {
320
+ tty_human_status(" Searching, found $matches results so far ..." );
321
+ }
315
322
}
316
323
}
317
324
close ($fd );
@@ -321,9 +328,22 @@ sub do_grep($$) {
321
328
error(" A subprocess exited uncleanly (raw: $? )" );
322
329
}
323
330
debug(1, ' Read all input' );
331
+ return if $stream_results ;
324
332
return reverse_hash($ret );
325
333
}
326
334
335
+ sub stream_results {
336
+ my ($filename , @pkgs ) = @_ ;
337
+ if ($Conf -> {package_only }) {
338
+ print map { " $_ \n " } @pkgs ;
339
+ } else {
340
+ for my $pkg (@pkgs ) {
341
+ print " $pkg : $filename \n " ;
342
+ }
343
+ }
344
+ return ;
345
+ }
346
+
327
347
sub escape_parens {
328
348
my $pattern = shift ;
329
349
@@ -577,6 +597,7 @@ Other options:
577
597
--config -c <file> Parse the given APT config file [R]
578
598
--option -o <A::B>=<V> Set the APT config option A::B to "V" [R]
579
599
--package-only -l Only display packages name
600
+ --stream-results Emit results immediately (without deduplication)
580
601
--verbose -v run in verbose mode [R]
581
602
--help -h Show this help.
582
603
-- End of options (necessary if pattern
@@ -606,6 +627,7 @@ sub get_options() {
606
627
" fixed-string|F" => \$Conf -> {fixed_strings },
607
628
" from-file|f" => \$Conf -> {from_file },
608
629
" from-deb|D" => \$Conf -> {from_deb },
630
+ ' stream-results' => \$Conf -> {streaming },
609
631
' filter-suites=s' => sub { _set_option(' in-suites' , CONFIG_SEARCH_FILTER_SUITES, $_ [1]); },
610
632
' filter-origins=s' => sub { _set_option(' from-origin' , CONFIG_SEARCH_FILTER_ORIGINS, $_ [1]); },
611
633
' config-file|c=s@' => \&_parse_apt_config_file,
0 commit comments