[PATCH v3 09/11] contrib: cc-cmd: support multiple roles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently only the roles of 'author' and 'signer' and handler, but now
there's also 'reviewer' and 'acker'.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 contrib/cc-cmd/git-cc-cmd | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/contrib/cc-cmd/git-cc-cmd b/contrib/cc-cmd/git-cc-cmd
index 200da0d..67a276d 100755
--- a/contrib/cc-cmd/git-cc-cmd
+++ b/contrib/cc-cmd/git-cc-cmd
@@ -50,6 +50,12 @@ end
 
 get_aliases if $get_aliases
 
+KNOWN_ROLES = {
+  'Signed-off' => :signer,
+  'Reviewed' => :reviewer,
+  'Acked' => :acker,
+}
+
 class Commit
 
   attr_reader :id, :roles
@@ -61,27 +67,30 @@ class Commit
 
   def parse(data)
     author = msg = nil
-    roles = {}
+    # hash of arrays
+    roles = Hash.new { |hash, key| hash[key] = [] }
     data.each_line do |line|
       if not msg
         case line
         when /^author ([^<>]+) <(\S+)>$/
           author = $1, $2
-          roles[author] = :author
+          roles[author] << :author
         when /^$/
           msg = true
         end
       else
-        if line =~ /^(Signed-off|Reviewed|Acked)-by: ([^<>]+) <(\S+?)>$/
+        role_regex = KNOWN_ROLES.keys.join('|')
+        if line =~ /^(#{role_regex})-by: ([^<>]+) <(\S+?)>$/
           person = $2, $3
-          roles[person] = :signer if person != author
+          role = KNOWN_ROLES[$1]
+          roles[person] << role if person != author
         end
       end
     end
-    @roles = roles.map do |person, role|
+    @roles = roles.map do |person, roles|
       address = "%s <%s>" % person
       person = nil, $aliases[address] if $aliases.include?(address)
-      [person, role]
+      [person, roles]
     end
   end
 
@@ -220,9 +229,11 @@ end
 persons = Hash.new { |hash, key| hash[key] = {} }
 
 commits.items.values.each do |commit|
-  commit.roles.each do |person, role|
-    persons[person][role] ||= 0
-    persons[person][role] += 1
+  commit.roles.each do |person, roles|
+    roles.each do |role|
+      persons[person][role] ||= 0
+      persons[person][role] += 1
+    end
   end
 end
 
-- 
1.8.2.1.790.g4588561

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]