From 859f2414c9f4b8533dcd3e6c1661f10031081630 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 3 Feb 2011 22:40:27 +0100 Subject: [PATCH] options to hide duplicates (simplify, ignore-case, unique) --- git-grep-footer | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/git-grep-footer b/git-grep-footer index 6952508..dcb24d4 100755 --- a/git-grep-footer +++ b/git-grep-footer @@ -8,6 +8,9 @@ use Getopt::Long; GetOptions(\my %opt, 'debug!', + 'simplify|s:s', + 'unique|u!', + 'ignore-case|i!', ) or die; local $| = 1; @@ -48,6 +51,40 @@ while (readline) { next LINE; }; + given ($opt{simplify} // 'no') { + when ('strict') { + $header[1] =~ s{ + \A + (?: [^:]+ )? + < [^@>]+ (?: @ | \h?\W? at \W?\h? ) [a-z0-9.-]+ > + \Z + }{<...>}imsx; + } + when (['text', '']) { + when ($header[0] =~ /[ _-] (?: by | to ) $/imsx) { + pop @header; + } + for ($header[1]) { + s{\b (https?)://\S+ }{[$1]}gmsx; # url + s{(?: < | \A ) [^@>\s]+ @ [^>]+ (?: > | \Z )}{<...>}igmsx; # address + s{\b [0-9]+ \b}{[num]}gmsx; # number + s{\b I? [0-9a-f]{40} \b}{[sha1]}gmsx; # hash + } + } + when (['all', 'any']) { + pop @header; + } + when ('no') { + } + default { + die "Unknown simplify option: '$_'\n"; + } + } + + if ($opt{'ignore-case'}) { + $_ = lc for @header; + } + push @headers, \@header; } @@ -58,6 +95,10 @@ while (readline) { } for (@headers) { + if ($opt{unique}) { + state $seen; + next if $seen->{ $_->[0] }->{ $_->[1] // '' }++; + } say join ': ', @$_; } -- 2.30.0