Commit f0a6fbaae3b8d06c43eef6879afbcbbfdca52f1d
1 parent
b28ab896
Exists in
master
and in
4 other branches
Improve Commits stats code
Showing
2 changed files
with
11 additions
and
12 deletions
Show diff stats
app/views/repositories/stats.html.haml
@@ -2,12 +2,12 @@ | @@ -2,12 +2,12 @@ | ||
2 | .row | 2 | .row |
3 | .span5 | 3 | .span5 |
4 | %h4 | 4 | %h4 |
5 | - Stats for #{@project.root_ref}: | 5 | + Stats: |
6 | %p | 6 | %p |
7 | %b Total commits: | 7 | %b Total commits: |
8 | %span= @stats.commits_count | 8 | %span= @stats.commits_count |
9 | %p | 9 | %p |
10 | - %b Total files: | 10 | + %b Total files in #{@project.root_ref}: |
11 | %span= @stats.files_count | 11 | %span= @stats.files_count |
12 | %p | 12 | %p |
13 | %b Authors: | 13 | %b Authors: |
@@ -30,10 +30,12 @@ | @@ -30,10 +30,12 @@ | ||
30 | :javascript | 30 | :javascript |
31 | $(function(){ | 31 | $(function(){ |
32 | var labels = [#{@graph.labels.to_json}]; | 32 | var labels = [#{@graph.labels.to_json}]; |
33 | + var commits = [#{@graph.commits.join(', ')}]; | ||
33 | var r = Raphael('activity-chart'); | 34 | var r = Raphael('activity-chart'); |
34 | r.text(160, 10, "Commit activity for last #{@graph.weeks} weeks").attr({ font: "13px sans-serif" }); | 35 | r.text(160, 10, "Commit activity for last #{@graph.weeks} weeks").attr({ font: "13px sans-serif" }); |
35 | r.barchart( | 36 | r.barchart( |
36 | 10, 10, 400, 160, | 37 | 10, 10, 400, 160, |
37 | - [[#{@graph.commits.join(', ')}]] | 38 | + [commits], |
39 | + {colors:["#456"]} | ||
38 | ).label(labels, true); | 40 | ).label(labels, true); |
39 | }) | 41 | }) |
lib/gitlab/git_stats.rb
@@ -15,7 +15,8 @@ module Gitlab | @@ -15,7 +15,8 @@ module Gitlab | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def files_count | 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 | end | 20 | end |
20 | 21 | ||
21 | def authors_count | 22 | def authors_count |
@@ -52,15 +53,11 @@ module Gitlab | @@ -52,15 +53,11 @@ module Gitlab | ||
52 | 53 | ||
53 | def build_graph n = 4 | 54 | def build_graph n = 4 |
54 | from, to = (Date.today - n.weeks), Date.today | 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 | commits_per_day = from.upto(to).map do |day| | 62 | commits_per_day = from.upto(to).map do |day| |
66 | commits_dates.count(day.to_date.to_s(:date)) | 63 | commits_dates.count(day.to_date.to_s(:date)) |