Commit f0a6fbaae3b8d06c43eef6879afbcbbfdca52f1d

Authored by Dmitriy Zaporozhets
1 parent b28ab896

Improve Commits stats code

app/views/repositories/stats.html.haml
... ... @@ -2,12 +2,12 @@
2 2 .row
3 3 .span5
4 4 %h4
5   - Stats for #{@project.root_ref}:
  5 + Stats:
6 6 %p
7 7 %b Total commits:
8 8 %span= @stats.commits_count
9 9 %p
10   - %b Total files:
  10 + %b Total files in #{@project.root_ref}:
11 11 %span= @stats.files_count
12 12 %p
13 13 %b Authors:
... ... @@ -30,10 +30,12 @@
30 30 :javascript
31 31 $(function(){
32 32 var labels = [#{@graph.labels.to_json}];
  33 + var commits = [#{@graph.commits.join(', ')}];
33 34 var r = Raphael('activity-chart');
34 35 r.text(160, 10, "Commit activity for last #{@graph.weeks} weeks").attr({ font: "13px sans-serif" });
35 36 r.barchart(
36 37 10, 10, 400, 160,
37   - [[#{@graph.commits.join(', ')}]]
  38 + [commits],
  39 + {colors:["#456"]}
38 40 ).label(labels, true);
39 41 })
... ...
lib/gitlab/git_stats.rb
... ... @@ -15,7 +15,8 @@ module Gitlab
15 15 end
16 16  
17 17 def files_count
18   - repo.git.sh("git ls-tree -r --name-only #{ref} | wc -l").first.to_i
  18 + args = [ref, '-r', '--name-only' ]
  19 + repo.git.run(nil, 'ls-tree', nil, {}, args).split("\n").count
19 20 end
20 21  
21 22 def authors_count
... ... @@ -52,15 +53,11 @@ module Gitlab
52 53  
53 54 def build_graph n = 4
54 55 from, to = (Date.today - n.weeks), Date.today
  56 + args = ['--all', "--since=#{from.to_s(:date)}", '--format=%ad' ]
  57 + rev_list = repo.git.run(nil, 'rev-list', nil, {}, args).split("\n")
55 58  
56   - format = "--pretty=format:'%h|%at|%ai|%aE'"
57   - commits_strings = repo.git.sh("git rev-list --since #{from.to_s(:date)} #{format} #{ref} | grep -v commit")[0].split("\n")
58   -
59   - commits_dates = commits_strings.map do |string|
60   - data = string.split("|")
61   - date = data[2]
62   - Time.parse(date).to_date.to_s(:date)
63   - end
  59 + commits_dates = rev_list.values_at(* rev_list.each_index.select {|i| i.odd?})
  60 + commits_dates = commits_dates.map { |date_str| Time.parse(date_str).to_date.to_s(:date) }
64 61  
65 62 commits_per_day = from.upto(to).map do |day|
66 63 commits_dates.count(day.to_date.to_s(:date))
... ...