mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
scripts/code-stats.rb: count files better, handle bad utf8
This commit is contained in:
parent
64dd656ef7
commit
3417d6229d
@ -2,21 +2,22 @@
|
|||||||
|
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
require 'set'
|
||||||
|
|
||||||
REGEX = /(\w+)\s+'(.+)'\s+(.*)/
|
REGEX = /(\w+)\s+'(.+)'\s+(.*)/
|
||||||
|
|
||||||
Commit = Struct.new(:hash, :time, :author, :stats)
|
Commit = Struct.new(:hash, :time, :author, :stats)
|
||||||
CommitStats = Struct.new(:nr_files, :nr_added, :nr_deleted)
|
CommitStats = Struct.new(:files, :nr_added, :nr_deleted)
|
||||||
|
|
||||||
def calc_stats(diff)
|
def calc_stats(diff)
|
||||||
changed = 0
|
changed = Set.new
|
||||||
added = 0
|
added = 0
|
||||||
deleted = 0
|
deleted = 0
|
||||||
|
|
||||||
diff.lines.each do |l|
|
diff.lines.each do |l|
|
||||||
case l
|
case l.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
||||||
when /^\+\+\+/
|
when /^\+\+\+ (\S+)/
|
||||||
changed = changed + 1
|
changed << $1
|
||||||
when /^\+/
|
when /^\+/
|
||||||
added = added + 1
|
added = added + 1
|
||||||
when /^---/
|
when /^---/
|
||||||
@ -61,20 +62,29 @@ def pad(str, col)
|
|||||||
str + (' ' * (col - str.size))
|
str + (' ' * (col - str.size))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def code_delta(s)
|
||||||
|
s.nr_added + s.nr_deleted
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmp_stats(lhs, rhs)
|
||||||
|
code_delta(rhs) <=> code_delta(lhs)
|
||||||
|
end
|
||||||
|
|
||||||
#-----------------------------------
|
#-----------------------------------
|
||||||
|
|
||||||
commits = select_commits(&since(DateTime.now - 14))
|
commits = select_commits(&since(DateTime.now - 14))
|
||||||
|
|
||||||
authors = Hash.new {|hash, key| hash[key] = CommitStats.new(0, 0, 0)}
|
authors = Hash.new {|hash, key| hash[key] = CommitStats.new(Set.new, 0, 0)}
|
||||||
|
|
||||||
commits.each do |c|
|
commits.each do |c|
|
||||||
author_stats = authors[c.author]
|
author_stats = authors[c.author]
|
||||||
author_stats.nr_files = author_stats.nr_files + c.stats.nr_files
|
author_stats.files.merge(c.stats.files)
|
||||||
author_stats.nr_added = author_stats.nr_added + c.stats.nr_added
|
author_stats.nr_added = author_stats.nr_added + c.stats.nr_added
|
||||||
author_stats.nr_deleted = author_stats.nr_deleted + c.stats.nr_deleted
|
author_stats.nr_deleted = author_stats.nr_deleted + c.stats.nr_deleted
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "#{pad("Author", 20)}\tChanged files\tInsertions\tDeletions"
|
puts "#{pad("Author", 20)}\tChanged files\tInsertions\tDeletions"
|
||||||
authors.each_pair do |k, v|
|
authors.keys.sort {|a1, a2| cmp_stats(authors[a1], authors[a2])}.each do |k|
|
||||||
puts "#{pad(k, 20)}\t#{v.nr_files}\t\t#{v.nr_added}\t\t#{v.nr_deleted}"
|
v = authors[k]
|
||||||
|
puts "#{pad(k, 20)}\t#{v.files.size}\t\t#{v.nr_added}\t\t#{v.nr_deleted}"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user