[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/01: lintian: Limit output when stdout is a tty



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit 54bd77582743cdcd17642daa245b7ff22e78e1f9
Author: Niels Thykier <niels@thykier.net>
Date:   Wed Jan 20 21:45:33 2016 +0000

    lintian: Limit output when stdout is a tty
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 debian/changelog      |  5 +++++
 frontend/lintian      | 23 ++++++++++++++++++++++-
 lib/Lintian/Output.pm | 31 ++++++++++++++++++++++++++-----
 man/lintian.pod.in    |  7 +++++++
 4 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index de78ca1..094ec89 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -43,6 +43,11 @@ lintian (2.5.40) UNRELEASED; urgency=medium
   * debian/rules:
     + [NT] Convert to dh7 style build.
 
+  * frontend/lintian:
+    + [NT] Limit the number of instances of the same tag when output is a
+      TTY.  Add --no-tag-display-limit to disable this feature.  Thanks
+      to Thijs Kinkhorst for the report.  (Closes: #775667)
+
   * lib/Lintian/Check.pm:
     + [JW] Remove work-around for Email::Valid bug (#663663), which is now
       fixed even in oldstable.
diff --git a/frontend/lintian b/frontend/lintian
index c7b8994..c96ed31 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -97,7 +97,8 @@ my $BANNER = "Lintian v$LINTIAN_VERSION"; #Version Banner - text form
 my %conf_opt;                   #names of options set in the cfg file
 my %opt = (                     #hash of some flags from cmd or cfg
     # Init some cmd-line value defaults
-    'debug' => 0,
+    'debug'             => 0,
+    'tag-display-limit' => 'auto',
 );
 
 # The search path - affected by --include-dir X, --[no-]user-dirs
@@ -211,6 +212,16 @@ Behaviour options:
     --hide-overrides          do not output tags that have been overridden (default)
     --suppress-tags T,...     don\'t show the specified tags
     --suppress-tags-from-file X don\'t show the tags listed in file X
+EOT-EOT-EOT
+    if ($show_extended) {
+        # Not a special option per se, but most people will probably
+        # not need it
+        print <<"EOT-EOT-EOT";
+    --no-tag-display-limit    Disable "tag per package" display limit
+EOT-EOT-EOT
+    }
+
+    print <<"EOT-EOT-EOT";
 Configuration options:
     --cfg CONFIGFILE          read CONFIGFILE for configuration
     --no-cfg                  do not read any config files
@@ -551,6 +562,7 @@ my %opthash = (
     'allow-root' => \$opt{'allow-root'},
     'fail-on-warnings' => \$opt{'fail-on-warnings'},
     'keep-lab' => \$opt{'keep-lab'},
+    'no-tag-display-limit' => sub { $opt{'tag-display-limit'} = 0; },
 
     # ------------------ configuration options
     'cfg=s' => \$opt{'LINTIAN_CFG'},
@@ -1537,6 +1549,14 @@ sub configure_output {
             'The color value must be one of',
             "\"never\", \"always\", \"auto\" or \"html\"\n");
     }
+    if ($opt{'tag-display-limit'} eq 'auto') {
+        if (-t STDOUT) {
+            $opt{'tag-display-limit'}
+              = Lintian::Output::DEFAULT_INTERACTIVE_TAG_LIMIT();
+        } else {
+            $opt{'tag-display-limit'} = 0;
+        }
+    }
 
     if ($opt{'debug'}) {
         $opt{'verbose'} = 1;
@@ -1581,6 +1601,7 @@ sub configure_output {
     $Lintian::Output::GLOBAL->verbosity_level($opt{'verbose'});
     $Lintian::Output::GLOBAL->debug($opt{'debug'});
     $Lintian::Output::GLOBAL->color($opt{'color'});
+    $Lintian::Output::GLOBAL->tag_display_limit($opt{'tag-display-limit'});
     $Lintian::Output::GLOBAL->showdescription($opt{'info'});
 
     $Lintian::Output::GLOBAL->perf_debug($opt{'perf-debug'});
diff --git a/lib/Lintian/Output.pm b/lib/Lintian/Output.pm
index 53ae397..fb22839 100644
--- a/lib/Lintian/Output.pm
+++ b/lib/Lintian/Output.pm
@@ -23,6 +23,8 @@ use warnings;
 
 use v5.8.0; # for PerlIO
 use parent qw(Class::Accessor::Fast);
+# The limit is includin the "use --foo to see all tags".
+use constant DEFAULT_INTERACTIVE_TAG_LIMIT => 4;
 
 use Exporter qw(import);
 
@@ -123,6 +125,10 @@ Whether to show the description of a tag when printing it.
 
 Hash containing the names of tags which have been issued.
 
+=item tag_display_limit
+
+Get/Set the number of times a tag is emitted per processable.
+
 =back
 
 =cut
@@ -130,7 +136,7 @@ Hash containing the names of tags which have been issued.
 Lintian::Output->mk_accessors(
     qw(verbosity_level debug color colors stdout
       stderr perf_log_fd perf_debug showdescription
-      issuedtags)
+      issuedtags tag_display_limit)
 );
 
 # for the non-OO interface
@@ -154,6 +160,7 @@ sub new {
     $self->perf_log_fd(\*STDOUT);
     $self->colors({%default_colors});
     $self->issuedtags({});
+    $self->{'proc_id2tag_count'} = {};
 
     # Set defaults to avoid "uninitialized" warnings
     $self->verbosity_level(0);
@@ -329,20 +336,34 @@ sub print_tag {
     my $code = $tag_info->code;
     my $tag_color = $self->{colors}{$code};
     my $fpkg_info = $self->_format_pkg_info($pkg_info, $tag_info, $override);
-
+    my $tag_name = $tag_info->tag;
+    my $limit = $self->tag_display_limit;
     my $tag;
+
+    # Limit the output so people do not drown in tags.  Some tags are
+    # insanely noisy (hi static-library-has-unneeded-section)
+    if ($limit) {
+        my $proc_id = $pkg_info->{'processable'}->identifier;
+        my $emitted_count
+          = $self->{'proc_id2tag_count'}{$proc_id}{$tag_name}++;
+        return if $emitted_count >= $limit;
+        my $msg
+          = ' ... use --no-tag-display-limit to see all (or pipe to a file/program)';
+        $information = $self->_quote_print($msg)
+          if $emitted_count >= $limit-1;
+    }
     if ($self->_do_color) {
         if ($self->color eq 'html') {
-            my $escaped = $tag_info->{tag};
+            my $escaped = $tag_name;
             $escaped =~ s/&/&amp;/g;
             $escaped =~ s/</&lt;/g;
             $escaped =~ s/>/&gt;/g;
             $tag .= qq(<span style="color: $tag_color">$escaped</span>);
         } else {
-            $tag .= Term::ANSIColor::colored($tag_info->tag, $tag_color);
+            $tag .= Term::ANSIColor::colored($tag_name, $tag_color);
         }
     } else {
-        $tag .= $tag_info->tag;
+        $tag .= $tag_name;
     }
 
     if ($override && @{ $override->comments }) {
diff --git a/man/lintian.pod.in b/man/lintian.pod.in
index 16fe167..fd28498 100644
--- a/man/lintian.pod.in
+++ b/man/lintian.pod.in
@@ -403,6 +403,13 @@ the exit status of Lintian.
 Tags parsed from the file will be handled as if they had been given to
 the B<--suppress-tags> option (e.g. ignored if B<--tags> is used).
 
+=item B<--no-tag-display-limit>
+
+By default, lintian limits itself to emitting at most 4 instances of each
+tag per processable when STDOUT is a TTY.  This option disables that limit.
+
+When STDOUT is not a TTY, lintian has no limit.
+
 =back
 
 Configuration options:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: