]> rtime.felk.cvut.cz Git - git-graphs.git/blob - commit-graph.pl
Added first universal commit-graph script
[git-graphs.git] / commit-graph.pl
1 #!/usr/bin/perl -w
2
3 use Getopt::Std;
4 use Data::Dumper;
5
6 my ($opt_l);
7 &getopts("l");
8
9 open GNUPLOT, "|gnuplot -persist";
10 $data = "/tmp/commit-graph-$$.dat";
11 print "Using file $data\n";
12 open DATA, ">$data";
13 use FileHandle;
14 GNUPLOT->autoflush(1);
15 print GNUPLOT <<EOF;
16 set xdata time
17 set timefmt "%s"
18 set format x "%y/%m/%d" 
19 set xlabel "Date"
20 set grid
21 set key left top
22 EOF
23
24 open MAILMAP,`git rev-parse --show-cdup`.".mailmap";
25 @mailmap = <MAILMAP>;
26
27 # Determin which authors commited something
28 @author_list = `git log --pretty=format:"%an <%ae>" @ARGV|sort -u`;
29 %emails = {};
30
31 sub add_author
32 {
33     ($author, $email) = @_;
34     
35     if (!defined $emails{$2}) {
36         $authors{$1}{$2}=1;
37         $emails{$2} = $1;
38     }
39 }
40
41
42 foreach $a(@author_list) {
43     chomp $a;
44     ($an, $ae) = $a =~ /(.*) <(.*)>/;
45     local $mailmapped;
46     $mailmapped = 0;
47
48     foreach (@mailmap) {
49         if (/\s*([^<]*) <(.*)>\s*$/) {
50             if ($2 eq $ae) {
51                 add_author($1, $2);
52                 $mailmapped = 1;
53             }
54         } else {
55             print STDERR "Unhandled mailmap line: $_\n";
56         }
57     }
58     add_author($an, $ae) unless $mailmapped;
59 }
60 #print Dumper({%authors});
61
62 foreach $author(sort keys %authors) {
63      @emails = keys %{ $authors{$author} };
64      $email_re = '\('.join('\|', @emails).'\)';
65
66      $cmd = qq/git log --pretty=format:"commit %ct %s" --author='$email_re' --no-merges --reverse --numstat @ARGV/;
67         print "$cmd\n";
68         @log = `$cmd`;
69         $num_commits = 0;
70         $added_lines = 0;
71         foreach (@log) {
72             chomp;
73             if (/^commit (\d+)/) { $time=$1; $num_commits++; $printed=0; }
74             elsif (/(\d+)\s+(\d+)/) {
75                 $added_lines += $1;
76             } elsif (!$_) {
77                 print DATA "$time $num_commits $added_lines\n";
78                 $printed=1;
79             }
80         }
81         if ($num_commits > 0) {
82             if (!$printed) {
83                 print DATA "$time $num_commits $added_lines\n";
84             }
85             print DATA "\n\n";
86         } else {
87             delete $authors{$author};
88         }
89 }
90
91 if (!$opt_l) {
92     @plots = ();
93     $i=0;
94     foreach $author(sort keys %authors) {
95         push @plots, qq/"$data" index $i using 1:2 with linespoints title "$author"/;
96         $i++;
97     }
98     print GNUPLOT "set ylabel \"Number of commits\"\n";
99     print GNUPLOT "plot ", join(", ", @plots), ";\n";
100 } else {
101     @plots = ();
102     $i=0;
103     foreach $author(sort keys %authors) {
104         push @plots, qq/"$data" index $i using 1:3 with linespoints title "$author"/;
105         $i++;
106     }
107     print GNUPLOT "set ylabel \"Added lines\"\n";
108     # print GNUPLOT "set logscale y\n";
109     print GNUPLOT "plot ", join(", ", @plots), ";\n";
110 }