aboutsummaryrefslogtreecommitdiff
path: root/desiredata/src/plusminus
blob: 553f84fa7bbf5da387f9596045006ad6aa4d188e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
# plusminus, Copyright © 2004 by Mathieu Bouchard
# this program makes stats about a unified diff (diff -u) output.
# for example, run this command: cvs diff -u | ./plusminus
# NOTE: the -u option is required! (you can put it in ~/.cvsrc)

puts "-"*64

$plustot=0
$minustot=0

def show
  printf "%20s %+5d %+5d (net %+5d)\n", $file, $plus, -$minus, $plus-$minus
end

loop{
  line = gets
  break if not line
  if /^diff/.match line then
    x = line.split(/\s+/)
    $plustot+=$plus if $plus
    $minustot+=$minus if $minus
    show if $file
    $file = x[-1]
    $on=false
    $plus=0
    $minus=0
  elsif /^\@\@/ =~ line then $on=true
  elsif $on and /^\+/ =~ line then $plus+=1
  elsif $on and /^\-/ =~ line then $minus+=1
  end
}

$plustot+=$plus if $plus
$minustot+=$minus if $minus
show if $file

$file="total"
$plus=$plustot
$minus=$minustot
puts "-"*64
show