bugfix: git-rank-contributor not counting quite right
[git-walkthrough-commit.git] / bin / git-rank-contributors
blobdb213aad49ea61b0d59204f2ae3771b4e29ae22b
1 #!/usr/bin/env ruby
3 ## git-rank-contributors: a simple script to trace through the logs and
4 ## rank contributors by the total size of the diffs they're responsible for.
5 ## A change counts twice as much as a plain addition or deletion.
6 ##
7 ## Output may or may not be suitable for inclusion in a CREDITS file.
8 ## Probably not without some editing, because people often commit from more
9 ## than one address.
11 ## git-rank-contributors Copyright 2008 William Morgan <wmorgan-git-wt-add@masanjin.net>.
12 ## This program is free software: you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation, either version 3 of the License, or (at
15 ## your option) any later version.
17 ## This program is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
22 ## You can find the GNU General Public License at:
23 ## http://www.gnu.org/licenses/
25 class String
26 def obfuscate; gsub(/@/, " at the ").gsub(/\.(\w+)(>|$)/, ' dot \1s\2') end
27 end
29 lines = {}
30 verbose = ARGV.delete("-v")
31 obfuscate = ARGV.delete("-o")
33 author = nil
34 state = :pre_author
35 `git log -p --no-color`.each do |l|
36 case
37 when (state == :pre_author || state == :post_author) && l =~ /Author: (.*)$/
38 author = $1
39 state = :post_author
40 lines[author] ||= 0
41 when state == :post_author && l =~ /^\+\+\+/
42 state = :in_diff
43 when state == :in_diff && l =~ /^[\+\-]/
44 lines[author] += 1
45 when state == :in_diff && l =~ /^commit /
46 state = :pre_author
47 end
48 end
50 lines.sort_by { |a, c| -c }.each do |a, c|
51 a = a.obfuscate if obfuscate
52 if verbose
53 puts "#{a}: #{c} lines of diff"
54 else
55 puts a
56 end
57 end