X-Git-Url: http://git.shiar.net/git-grep-footer.git/blobdiff_plain/d65a750ab292d2c34da412720ae675d0abb2d1ac..77f33263e87e436c6e2a962c69a68f12c4520bf8:/git-grep-footer diff --git a/git-grep-footer b/git-grep-footer index 53f6f1c..c39222f 100755 --- a/git-grep-footer +++ b/git-grep-footer @@ -12,6 +12,7 @@ GetOptions(\my %opt, 'count|c!', 'simplify|s:s', 'ignore-case|i!', + 'fuzzy!', 'min|min-count|unique|u:i', 'max|max-count|show|n:i', 'version|V' => sub { Getopt::Long::VersionMessage() }, @@ -27,7 +28,7 @@ my $HEADERMATCH = qr/ [a-z]+ (?: (?:-\w+)+ | \ by ) /ix; my (%headercount, @headercache); while (readline) { - s/(.+)\n//m; + s/^([0-9a-f]{4,40})\n//m and my $hash = $1; # strip commit seperator @@ -39,12 +40,12 @@ while (readline) { # if invalid, assume it's latin1 $_ = decode(cp1252 => $_) if $@; - my $prefix = 0; my %attr; BLOCK: for (reverse split /\n\n/) { my @headers; + my $prefix = 0; LINE: for (split /\n/) { @@ -62,6 +63,18 @@ while (readline) { push @header, $_ if defined $opt{max}; + if ($opt{fuzzy}) { + for ($header[0]) { + tr/ _/-/; + + state $BY = qr{ (?: -? b[yu] )? \Z }ix; + s{^ si (?:ge?n|n?g) (?:e?[dt])? -? (?:of+)? $BY}{Signed-off-by}ix; + s{^ ack (?:ed|de)? $BY}{Acked-by}ix; + s{^ review (?:e?d)? $BY}{Reviewed-by}ix; + s{^ teste[dt] $BY}{Tested-by}ix; + } + } + given ($opt{simplify} // 'none') { when (['email', 'authors']) { $header[1] =~ s{ @@ -105,11 +118,13 @@ while (readline) { next BLOCK if not @headers; if ($opt{debug} and $prefix) { - say "infix junk in commit $hash"; + say sprintf ': invalid lines in %s (%s)', $hash // 'block', $prefix; } for (@headers) { my $line = $_->[2] // join(': ', @$_); + $line =~ s/^/$hash / if defined $hash; + if (defined $opt{min} or $opt{max}) { my $counter = \$headercount{ $_->[0] }->{ $_->[1] // '' }; my $excess = $$counter++ - ($opt{min} // 0);