diff options
author | Joe Thornber <ejt@redhat.com> | 2018-06-01 13:04:12 +0100 |
---|---|---|
committer | Joe Thornber <ejt@redhat.com> | 2018-06-01 13:04:12 +0100 |
commit | dbba1e9b93bac348c0df556b160676234cc8a8c4 (patch) | |
tree | b1db4389e0288231ad36d7a6de607bcc38f38c3a /scripts | |
parent | 89fdc0b5889d24fe785e7fa4c2be13659d1ed0b2 (diff) | |
parent | cb379c86c4b468858b781695934d5ad5957108d2 (diff) | |
download | lvm2-dbba1e9b93bac348c0df556b160676234cc8a8c4.tar.gz |
Merge branch 'master' into 2018-05-11-fork-libdm
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/code-stats.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/scripts/code-stats.rb b/scripts/code-stats.rb new file mode 100755 index 000000000..d73343be9 --- /dev/null +++ b/scripts/code-stats.rb @@ -0,0 +1,90 @@ +#! /usr/bin/env ruby + +require 'date' +require 'pp' +require 'set' + +REGEX = /(\w+)\s+'(.+)'\s+(.*)/ + +Commit = Struct.new(:hash, :time, :author, :stats) +CommitStats = Struct.new(:files, :nr_added, :nr_deleted) + +def calc_stats(diff) + changed = Set.new + added = 0 + deleted = 0 + + diff.lines.each do |l| + case l.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') + when /^\+\+\+ (\S+)/ + changed << $1 + when /^\+/ + added = added + 1 + when /^---/ + # do nothing + when /^\-/ + deleted = deleted + 1 + end + end + + CommitStats.new(changed, added, deleted) +end + +def select_commits(&block) + commits = [] + + input = `git log --format="%h '%aI' %an"` + input.lines.each do |l| + m = REGEX.match(l) + + raise "couldn't parse: ${l}" unless m + + hash = m[1] + time = DateTime.iso8601(m[2]) + author = m[3] + + if block.call(hash, time, author) + diff = `git log -1 -p #{hash} | filterdiff -X configure` + commits << Commit.new(hash, time, author, calc_stats(diff)) + end + end + + commits +end + +def since(date) + lambda do |hash, time, author| + time >= date + end +end + +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(Set.new, 0, 0)} + +commits.each do |c| + author_stats = authors[c.author] + 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.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 |