Commit 205f5f1283c5ed1ed2471a616b449dae08ab616b
- Date: Mon May 19 21:16:41 +0000 2008
- Committer: Johan Sørensen (johan@johansorensen.com)
- Author: Johan Sørensen (johan@johansorensen.com)
- Commit SHA1: 205f5f1283c5ed1ed2471a616b449dae08ab616b
- Tree SHA1: 8df9b064bfbb9d8b08c93b601c18ef57ac82feaa
Fixed Repository#commit_graph_data_by_author edge case of the commit count being nil when multiple "authors" with the same name have different emails
Commit diff
| |   |
| 181 | 181 | def commit_graph_data_by_author(head = "master") |
| 182 | 182 | h = {} |
| 183 | 183 | emails = {} |
| 184 | | count_author_regexp = /^\s+(\d+)\s(.+)\s\<(\S+)\>$/.freeze |
| 185 | 184 | data = self.git.git.shortlog({:e => true, :s => true }, head) |
| 186 | 185 | data.each_line do |line| |
| 187 | | if line =~ count_author_regexp |
| 188 | | count = $1.to_i |
| 189 | | author = $2 |
| 190 | | email = $3 |
| 191 | | |
| 192 | | h[author] ||= 0 |
| 193 | | h[author] += count |
| 194 | | |
| 195 | | emails[email] = author |
| 196 | | end |
| 186 | count, actor = line.split("\t") |
| 187 | actor = Grit::Actor.from_string(actor) |
| 188 | |
| 189 | h[actor.name] ||= 0 |
| 190 | h[actor.name] += count.to_i |
| 191 | emails[actor.email] = actor.name |
| 197 | 192 | end |
| 198 | 193 | |
| 199 | 194 | users = User.find(:all, :conditions => ["email in (?)", emails.keys]) |
| 200 | 195 | users.each do |user| |
| 201 | 196 | author_name = emails[user.email] |
| 202 | | h[user.login] = h.delete(author_name) |
| 197 | if h[author_name] # in the event that a user with the same name has used two different emails, he'd be gone by now |
| 198 | h[user.login] = h.delete(author_name) |
| 199 | end |
| 203 | 200 | end |
| 204 | 201 | |
| 205 | 202 | h |
| toggle raw diff |
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -181,25 +181,22 @@ class Repository < ActiveRecord::Base
def commit_graph_data_by_author(head = "master")
h = {}
emails = {}
- count_author_regexp = /^\s+(\d+)\s(.+)\s\<(\S+)\>$/.freeze
data = self.git.git.shortlog({:e => true, :s => true }, head)
data.each_line do |line|
- if line =~ count_author_regexp
- count = $1.to_i
- author = $2
- email = $3
-
- h[author] ||= 0
- h[author] += count
-
- emails[email] = author
- end
+ count, actor = line.split("\t")
+ actor = Grit::Actor.from_string(actor)
+
+ h[actor.name] ||= 0
+ h[actor.name] += count.to_i
+ emails[actor.email] = actor.name
end
users = User.find(:all, :conditions => ["email in (?)", emails.keys])
users.each do |user|
author_name = emails[user.email]
- h[user.login] = h.delete(author_name)
+ if h[author_name] # in the event that a user with the same name has used two different emails, he'd be gone by now
+ h[user.login] = h.delete(author_name)
+ end
end
h |