Commit 4b96998f3b5c19a84ac69d9a4ace5ca2d8c6e1ae
- Date: Tue Apr 29 20:45:17 +0000 2008
- Committer: David A. Cuadrado (krawek@gmail.com)
- Author: David A. Cuadrado (krawek@gmail.com)
- Commit SHA1: 4b96998f3b5c19a84ac69d9a4ace5ca2d8c6e1ae
- Tree SHA1: 17ed215d99ea46e146c10b9c80d4c456a183d5bd
commits-by-author graph should use gitorious username (if found)
Signed-off-by: David A. Cuadrado <krawek@gmail.com>
Commit diff
| |   |
| 180 | 180 | # TODO: caching |
| 181 | 181 | def commit_graph_data_by_author(head = "master") |
| 182 | 182 | h = {} |
| 183 | | count_author_regexp = /^\s+(\d+)\s(.+)$/.freeze |
| 184 | | data = self.git.git.shortlog({:s => true }, head) |
| 183 | emails = {} |
| 184 | count_author_regexp = /^\s+(\d+)\s(.+)\s\<(\S+)\>$/.freeze |
| 185 | data = self.git.git.shortlog({:e => true, :s => true }, head) |
| 185 | 186 | data.each_line do |line| |
| 186 | 187 | if line =~ count_author_regexp |
| 187 | 188 | count = $1.to_i |
| 188 | 189 | author = $2 |
| 190 | email = $3 |
| 189 | 191 | |
| 190 | 192 | h[author] ||= 0 |
| 191 | 193 | h[author] += count |
| 194 | |
| 195 | emails[email] = author |
| 192 | 196 | end |
| 193 | 197 | end |
| 194 | 198 | |
| 199 | users = User.find(:all, :conditions => ["email in (?)", emails.keys]) |
| 200 | users.each do |user| |
| 201 | author_name = emails[user.email] |
| 202 | h[user.login] = h.delete(author_name) |
| 203 | end |
| 204 | |
| 195 | 205 | h |
| 196 | 206 | end |
| 197 | 207 | |
| toggle raw diff |
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -180,18 +180,28 @@ class Repository < ActiveRecord::Base
# TODO: caching
def commit_graph_data_by_author(head = "master")
h = {}
- count_author_regexp = /^\s+(\d+)\s(.+)$/.freeze
- data = self.git.git.shortlog({:s => true }, head)
+ 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
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)
+ end
+
h
end
|