Add add-counts filter
[omc-tools.git] / add-counts
1 #! /usr/bin/env perl
2 # Annotate the output of "get-followups -d" to show the stats
3 # of each commit.
4 use strict;
5 use warnings;
6
7 while ( <> ) {
8     unless ( /([0-da-f]{8}) .*/ ) {
9         print;
10         next;
11     }
12     my $cid = $1;
13     my $line = $_;
14     if ( $cid eq 'd02b48c6' ) {
15         print "931 +17534 -0 ", $_;
16         next;
17     }
18     my $pattern = "$cid^..$cid";
19     my $files = 0;
20     my $adds = 0;
21     my $dels = 0;
22     open my $F, "git diff --numstat $pattern|"
23         || die "Can't open git diff, $!\n";
24     while ( <$F> ) {
25         $files++;
26         next unless /(\d+)\s+(\d+)/;
27         $adds += int($1);
28         $dels += int($2);
29     }
30     close $F || die "Can't close git diff, $!\n";
31     print "$files +$adds -$dels $line";
32 }