diff options
author | Joe Thornber <ejt@redhat.com> | 2018-05-17 09:52:13 +0100 |
---|---|---|
committer | Joe Thornber <ejt@redhat.com> | 2018-05-17 09:52:13 +0100 |
commit | 3417d6229dcdcb2e1c9595026a8f97d10f25804a (patch) | |
tree | 52bd2b40e93481cbab3da7d3d2e655f72530835e | |
parent | 64dd656ef7943f9991c83802dfa5f762c902e1fb (diff) | |
download | lvm2-3417d6229dcdcb2e1c9595026a8f97d10f25804a.tar.gz |
scripts/code-stats.rb: count files better, handle bad utf8
-rwxr-xr-x | scripts/code-stats.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/scripts/code-stats.rb b/scripts/code-stats.rb index e87de26a9..d73343be9 100755 --- a/scripts/code-stats.rb +++ b/scripts/code-stats.rb @@ -2,21 +2,22 @@ require 'date' require 'pp' +require 'set' REGEX = /(\w+)\s+'(.+)'\s+(.*)/ 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) - changed = 0 + changed = Set.new added = 0 deleted = 0 diff.lines.each do |l| - case l - when /^\+\+\+/ - changed = changed + 1 + case l.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') + when /^\+\+\+ (\S+)/ + changed << $1 when /^\+/ added = added + 1 when /^---/ @@ -61,20 +62,29 @@ def pad(str, col) str + (' ' * (col - str.size)) 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)) -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| 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_deleted = author_stats.nr_deleted + c.stats.nr_deleted end puts "#{pad("Author", 20)}\tChanged files\tInsertions\tDeletions" -authors.each_pair do |k, v| - puts "#{pad(k, 20)}\t#{v.nr_files}\t\t#{v.nr_added}\t\t#{v.nr_deleted}" +authors.keys.sort {|a1, a2| cmp_stats(authors[a1], authors[a2])}.each do |k| + v = authors[k] + puts "#{pad(k, 20)}\t#{v.files.size}\t\t#{v.nr_added}\t\t#{v.nr_deleted}" end |