Handle file renames inside directories.
[git-plot.git] / files.sh
blob9c8e8be66f8a19f120af603893581ccb53ecbfd7
1 #!/bin/bash
3 if [ $# -lt 1 ]; then
4 echo "Usage: $0 <output folder> [geometry]" >&2;
5 exit 1;
6 fi
8 output="$1"
9 echo "Outputting to image $output"
11 if [ -e $output ]; then
12 echo "Output directory $output already exists" >&2;
13 exit 2;
16 x=600
17 y=400
19 if [ $# -gt 1 ]; then
20 x=$2;
21 y=$3;
24 git log -C --numstat --reverse --pretty=format:"%H %an" | perl -e '
25 use strict;
27 my %files;
29 my $output = ".gitblaai";
30 mkdir($output) or die("Failed to create directory $output. Exiting.\n");
32 my $author;
33 my $commit;
34 my $ncommits = 0;
35 sub add_commit {
36 my ($file, $ins, $del) = @_;
38 my $size;
39 if( exists $files{ $file } ) {
40 my $prevsize = $files{$file}[ $#{ $files{$file} } ];
41 # print "ADD $file prev = $prevsize";
42 $size = $prevsize;
43 } else {
44 # print "NEW $file";
46 my $i;
47 for($i = 0; $i < $ncommits; ++$i ) {
48 push( @{ $files{$file} }, 0 );
50 $size = 0;
53 $size += ($ins - $del);
54 # print " => $size ($commit)\n";
55 push( @{ $files{$file} }, $size );
58 sub rename_file {
59 my ($old, $new) = @_;
61 if( not exists $files{ $old } ) {
62 print STDERR "$old does not exist\n";
63 } else {
64 $files{ $new } = $files{ $old };
65 delete $files{ $old };
68 # print "MV \"$old\" \"$new\"\n";
71 sub push_empty {
72 my $file;
73 foreach $file (keys %files) {
74 if( $#{ $files{ $file } } < $ncommits ) {
75 my $prevsize = $files{$file}[ $#{ $files{$file} } ];
76 push( @{ $files{$file} }, $prevsize );
81 while( <> ) {
82 if( $_ =~ /^[0-9]+[\t ]+[0-9]+\s+\{[\w\/]+ => [\w\/]+\}\// ) {
83 my ($ins, $del, $fromdir, $todir, $file) = split(/[\s\{(=>)\}]+/, $_);
84 &rename_file("$fromdir$file", "$todir$file");
85 } elsif( $_ =~ /^\d+\s+\d+\s+[\w\/]+\{[\w\.\/]+ => [\w\.\/]+\}/ ) {
86 my ($ins, $del, $path, $from, $to) = split(/[\s\{(=>)\}]+/, $_);
87 print "RENAME $path,$from,$to\n";
88 &rename_file("$path$from", "$path$to");
90 my $file = "$path$to";
91 &add_commit($file, $ins, $del);
92 } elsif( $_ =~ /^[0-9]+[\t ]+[0-9]+/ ) {
93 my ($ins, $del, $file, $arrow, $new) = split;
94 if( $arrow eq "=>" ) {
95 &rename_file($file, $new);
96 $file = $new;
99 &add_commit($file, $ins, $del);
100 } elsif( $_ =~ /^[0-9a-z]+/ ) {
101 if( $ncommits != 1 ) {
102 &push_empty();
105 ($commit, $author) = split(/\s+/, $_, 2);
106 $ncommits++;
110 my $file;
111 foreach $file (keys %files) {
112 my $filename = $file;
113 $filename =~ s/\//_/g;
114 open( FILE, ">>$output/$filename" );
115 my $i;
116 for $i ( 0 .. $#{ $files{$file} } ) {
117 print FILE "$file $files{$file}[$i]\n";
120 close(FILE)
122 ' # > $TMP
124 mv .gitblaai $output
126 ls $output/ | while read file; do
127 echo $file
128 gnuplot << _EOF_
129 set terminal png nocrop medium size $x,$y
130 set output '$output/$file.png'
131 plot "$output/$file" using 2 with points
132 _EOF_
133 done