No functional changes.

Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
---
 contrib/related/git-related | 80 +++++++++++++++++++++++++++++++--------------
 1 file changed, 56 insertions(+), 24 deletions(-)

diff --git a/contrib/related/git-related b/contrib/related/git-related
index 7be2829..df13148 100755
--- a/contrib/related/git-related
+++ b/contrib/related/git-related
@@ -8,10 +8,6 @@ require 'optparse'
 $since = '5-years-ago'
 $min_percent = 10
 
-def fmt_person(name, email)
-  name ? '%s <%s>' % [name, email] : email
-end
-
 begin
   OptionParser.new do |opts|
     opts.program_name = 'git related'
@@ -27,13 +23,59 @@ begin
 rescue OptionParser::InvalidOption
 end
 
-class Commit
+class Person
+
+  attr_reader :roles
+
+  def initialize(name, email)
+    @name = name
+    @email = email
+    @commits = {}
+  end
+
+  def add_role(commit)
+    @commits[commit] = true
+  end
+
+  def <=>(b)
+    self.size <=> b.size
+  end
+
+  def size
+    @commits.size
+  end
+
+  def to_s
+    @name ? '%s <%s>' % [@name, @email] : @email
+  end
+
+end
 
-  attr_reader :persons
+class Persons
+
+  @@index = {}
+
+  include Enumerable
+
+  def each(&block)
+    @@index.values.each(&block)
+  end
+
+  def self.get(name, email)
+    id = [name, email]
+    person = @@index[id]
+    if not person
+      person = @@index[id] = Person.new(name, email)
+    end
+    person
+  end
+
+end
+
+class Commit
 
   def initialize(id)
     @id = id
-    @persons = []
   end
 
   def parse(data)
@@ -42,17 +84,18 @@ class Commit
       if not msg
         case line
         when /^author ([^<>]+) <(\S+)> (.+)$/
-          @persons << fmt_person($1, $2)
+          author = Persons.get($1, $2)
+          author.add_role(@id)
         when /^$/
           msg = true
         end
       else
         if line =~ /^(Signed-off|Reviewed|Acked)-by: ([^<>]+) <(\S+?)>$/
-          @persons << fmt_person($2, $3)
+          person = Persons.get($2, $3)
+          person.add_role(@id)
         end
       end
     end
-    @persons.uniq!
   end
 
 end
@@ -126,21 +169,10 @@ commits = Commits.new
 commits.from_patch(ARGV[0])
 commits.import
 
-count_per_person = Hash.new(0)
-
-commits.each do |id, commit|
-  commit.persons.each do |person|
-    count_per_person[person] += 1
-  end
-end
-
-# sort by number of participations
-count_sort = lambda do |a, b|
-  b[1] <=> a[1]
-end
+persons = Persons.new
 
-count_per_person.sort(&count_sort).each do |person, count|
-  percent = count.to_f * 100 / commits.size
+persons.sort.reverse.each do |person|
+  percent = person.size.to_f * 100 / commits.size
   next if percent < $min_percent
   puts '%s (involved: %u%%)' % [person, percent]
 end
-- 
1.8.3.rc2.542.g24820ba

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to