Tweak output format, add warning
[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 die "Feed this the output of 'get-followups -d'\n" if -t 0;
8
9 while ( <> ) {
10     unless ( /([0-da-f]{8}) .*/ ) {
11         print;
12         next;
13     }
14     my $cid = $1;
15     my $line = $_;
16     $line =~ s/^\s*//;
17     if ( $cid eq 'd02b48c6' ) {
18         print "931 +17534 -0 ", $_;
19         next;
20     }
21     my $pattern = "$cid^..$cid";
22     my $files = 0;
23     my $adds = 0;
24     my $dels = 0;
25     my $name = '';
26     open my $F, "git diff --numstat $pattern|"
27         || die "Can't open git diff, $!\n";
28     while ( <$F> ) {
29         $files++;
30         next unless /(\d+)\s+(\d+)\s+(.*)/;
31         $adds += int($1);
32         $dels += int($2);
33         $name = $3 if $name eq '';
34     }
35     close $F || die "Can't close git diff, $!\n";
36     if ( $files == 1 ) {
37         print "$name +$adds -$dels $line";
38     } else {
39         print "$files +$adds -$dels $line";
40     }
41 }