reset (debug) junk counter between blocks
[git-grep-footer.git] / git-grep-footer
index 53f6f1cf49d15e0d6f63d062c91e844c7bb24c6d..c39222fd9d6a3280cd817d88d72e1d086bfc8a64 100755 (executable)
@@ -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);