-
Notifications
You must be signed in to change notification settings - Fork 3
/
count_lines_git_dir.rb
78 lines (66 loc) · 2.12 KB
/
count_lines_git_dir.rb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env ruby
# encoding: utf-8
impact = Hash.new(0)
#$FOLDERS = Array["conf", "idp", "saf", "sas", "sigh", "soc", "conf/base" ]
$FOLDERS = Array["metaconfiguracion", "metapersona", "metafarmacia", "metastock", "metaasistencial", "metasocial", "metastock/base", "metasec", "sigh" ]
#$BASE_DIR = "/home/arturo/develop/facultad/stable"
$BASE_DIR = Dir.pwd
total = 0;
totalS = "Total"
char_per_line = 51
def get_name(name)
if name.strip! == "Arturo Volpe" then
return "Arturo Volpe Torres"
end
if name.start_with? "Jorge" then
return "Jorge Ramírez"
end
if name == "ovianconi" then
return "Osmar Vianconi"
end
name
end
$FOLDERS.each{ |folder|
tmp = $BASE_DIR + "/" + folder
Dir.chdir(tmp)
current = Hash.new(0)
current_total = 0
IO.popen("git log --pretty=format:\"%an\" --shortstat #{ARGV.join(' ')}") do |f|
prev_line = ''
while line = f.gets
changes = /(\d+) insertions.*((\d+) deletions)?/.match(line)
if changes
add = changes[1].to_i
minus = 0
if changes[2]
minus = changes[2].to_i
end
changes_commit = add + minus
impact[prev_line] += changes_commit
current[prev_line] += changes_commit
total += changes_commit
current_total += changes_commit
end
prev_line = get_name(line) # Nombres en la primera linea
end
end
puts "".ljust(char_per_line, "-")
puts "Folder: #{folder}".ljust(char_per_line, "-")
puts "".ljust(char_per_line, "-")
current.sort_by { |a,i| -i }.each { |author, impactado|
porcentaje = impactado * 100 / current_total
puts "#{author.strip.ljust(30)}: #{impactado.to_s.rjust(10)} L (#{porcentaje.to_s.rjust(3)}%)"
}
puts "#{totalS.ljust(30)}: #{current_total.to_s.rjust(10)} L (100%)"
puts "".ljust(char_per_line, "-")
}
puts
puts "".ljust(char_per_line, "-")
puts "Summary".ljust(char_per_line, "-")
puts "".ljust(char_per_line, "-")
impact.sort_by { |a,i| -i }.each { |author, impactado|
porcentaje = impactado * 100 / total
puts "#{author.strip.ljust(30)}: #{impactado.to_s.rjust(10)} L (#{porcentaje.to_s.rjust(3)}%)"
}
puts "#{totalS.ljust(30)}: #{total.to_s.rjust(10)} L (100%)"
puts "".ljust(char_per_line, "-")