Commit a031813887a203b80006e7fdc3204355fd8d02b7
1 parent
1b2fba08
Exists in
master
and in
4 other branches
Commit, network graph refactoring
Showing
14 changed files
with
125 additions
and
97 deletions
Show diff stats
app/assets/stylesheets/highlight.black.css.scss
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | .cm { color: #888888 } /* Comment.Multiline */ | 11 | .cm { color: #888888 } /* Comment.Multiline */ |
12 | .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ | 12 | .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ |
13 | .c1 { color: #888888 } /* Comment.Single */ | 13 | .c1 { color: #888888 } /* Comment.Single */ |
14 | - .cs { color: #cc0000; font-weight: bold; background-color: auto } /* Comment.Special */ | 14 | + .cs { color: #cc0000; font-weight: bold; background-color: transparent } /* Comment.Special */ |
15 | .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ | 15 | .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ |
16 | .ge { font-style: italic } /* Generic.Emph */ | 16 | .ge { font-style: italic } /* Generic.Emph */ |
17 | .gr { color: #aa0000 } /* Generic.Error */ | 17 | .gr { color: #aa0000 } /* Generic.Error */ |
@@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
30 | .highlight .kt{color:#458;font-weight:bold;} /* Keyword.Type */ | 30 | .highlight .kt{color:#458;font-weight:bold;} /* Keyword.Type */ |
31 | .m { color: #0000DD; font-weight: bold } /* Literal.Number */ | 31 | .m { color: #0000DD; font-weight: bold } /* Literal.Number */ |
32 | .p { color: #eee; } | 32 | .p { color: #eee; } |
33 | - .s { color: #dd2200; background-color: auto } /* Literal.String */ | 33 | + .s { color: #dd2200; background-color: transparent } /* Literal.String */ |
34 | .highlight .na{color:#008080;} /* Name.Attribute */ | 34 | .highlight .na{color:#008080;} /* Name.Attribute */ |
35 | .highlight .nb{color:#0086B3;} /* Name.Builtin */ | 35 | .highlight .nb{color:#0086B3;} /* Name.Builtin */ |
36 | .highlight .nc{color:#4d3;font-weight:bold;} /* Name.Class */ | 36 | .highlight .nc{color:#4d3;font-weight:bold;} /* Name.Class */ |
@@ -48,9 +48,9 @@ | @@ -48,9 +48,9 @@ | ||
48 | .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ | 48 | .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ |
49 | .highlight .mi {color:#099;} /* Literal.Number.Integer */ | 49 | .highlight .mi {color:#099;} /* Literal.Number.Integer */ |
50 | .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ | 50 | .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ |
51 | - .sb { color: #dd2200; background-color: auto } /* Literal.String.Backtick */ | 51 | + .sb { color: #dd2200; background-color: transparent; } /* Literal.String.Backtick */ |
52 | .highlight .sc{color:#d14;} /* Literal.String.Char */ | 52 | .highlight .sc{color:#d14;} /* Literal.String.Char */ |
53 | - .sd { color: #dd2200; background-color: auto } /* Literal.String.Doc */ | 53 | + .sd { color: #dd2200; background-color: transparent; } /* Literal.String.Doc */ |
54 | .highlight .s2{color:orange;} /* Literal.String.Double */ | 54 | .highlight .s2{color:orange;} /* Literal.String.Double */ |
55 | .highlight .se{color:orange;} /* Literal.String.Escape */ | 55 | .highlight .se{color:orange;} /* Literal.String.Escape */ |
56 | .highlight .sh{color:orange;} /* Literal.String.Heredoc */ | 56 | .highlight .sh{color:orange;} /* Literal.String.Heredoc */ |
app/controllers/commits_controller.rb
@@ -13,12 +13,7 @@ class CommitsController < ApplicationController | @@ -13,12 +13,7 @@ class CommitsController < ApplicationController | ||
13 | def index | 13 | def index |
14 | @repo = project.repo | 14 | @repo = project.repo |
15 | @limit, @offset = (params[:limit] || 20), (params[:offset] || 0) | 15 | @limit, @offset = (params[:limit] || 20), (params[:offset] || 0) |
16 | - | ||
17 | - @commits = if params[:path] | ||
18 | - @repo.log(@ref, params[:path], :max_count => @limit, :skip => @offset) | ||
19 | - else | ||
20 | - @repo.commits(@ref, @limit, @offset) | ||
21 | - end | 16 | + @commits = @project.commits(@ref, params[:path], @limit, @offset) |
22 | 17 | ||
23 | respond_to do |format| | 18 | respond_to do |format| |
24 | format.html # index.html.erb | 19 | format.html # index.html.erb |
@@ -28,7 +23,7 @@ class CommitsController < ApplicationController | @@ -28,7 +23,7 @@ class CommitsController < ApplicationController | ||
28 | end | 23 | end |
29 | 24 | ||
30 | def show | 25 | def show |
31 | - @commit = project.repo.commits(params[:id]).first | 26 | + @commit = project.commit(params[:id]) |
32 | @notes = project.commit_notes(@commit).fresh.limit(20) | 27 | @notes = project.commit_notes(@commit).fresh.limit(20) |
33 | @note = @project.build_commit_note(@commit) | 28 | @note = @project.build_commit_note(@commit) |
34 | 29 |
app/controllers/projects_controller.rb
@@ -86,31 +86,7 @@ class ProjectsController < ApplicationController | @@ -86,31 +86,7 @@ class ProjectsController < ApplicationController | ||
86 | end | 86 | end |
87 | 87 | ||
88 | def graph | 88 | def graph |
89 | - @repo = project.repo | ||
90 | - commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650}) | ||
91 | - ref_cache = {} | ||
92 | - commits.collect! do |commit| | ||
93 | - add_refs(commit, ref_cache) | ||
94 | - GraphCommit.new(commit) | ||
95 | - end | ||
96 | - | ||
97 | - days = GraphCommit.index_commits(commits) | ||
98 | - @days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json | ||
99 | - @commits_json = commits.collect do |c| | ||
100 | - h = {} | ||
101 | - h[:parents] = c.parents.collect do |p| | ||
102 | - [p.id,0,0] | ||
103 | - end | ||
104 | - h[:author] = c.author.name.force_encoding("UTF-8") | ||
105 | - h[:time] = c.time | ||
106 | - h[:space] = c.space | ||
107 | - h[:refs] = c.refs.collect{|r|r.name}.join(" ") unless c.refs.nil? | ||
108 | - h[:id] = c.sha | ||
109 | - h[:date] = c.date | ||
110 | - h[:message] = c.message.force_encoding("UTF-8") | ||
111 | - h[:login] = c.author.email | ||
112 | - h | ||
113 | - end.to_json | 89 | + @days_json, @commits_json = GraphCommit.to_graph(project) |
114 | end | 90 | end |
115 | 91 | ||
116 | def destroy | 92 | def destroy |
@@ -123,17 +99,6 @@ class ProjectsController < ApplicationController | @@ -123,17 +99,6 @@ class ProjectsController < ApplicationController | ||
123 | 99 | ||
124 | protected | 100 | protected |
125 | 101 | ||
126 | - def add_refs(commit, ref_cache) | ||
127 | - if ref_cache.empty? | ||
128 | - @repo.refs.each do |ref| | ||
129 | - ref_cache[ref.commit.id] ||= [] | ||
130 | - ref_cache[ref.commit.id] << ref | ||
131 | - end | ||
132 | - end | ||
133 | - commit.refs = ref_cache[commit.id] if ref_cache.include? commit.id | ||
134 | - commit.refs ||= [] | ||
135 | - end | ||
136 | - | ||
137 | def project | 102 | def project |
138 | @project ||= Project.find_by_code(params[:id]) | 103 | @project ||= Project.find_by_code(params[:id]) |
139 | end | 104 | end |
app/helpers/dashboard_helper.rb
@@ -2,7 +2,7 @@ module DashboardHelper | @@ -2,7 +2,7 @@ module DashboardHelper | ||
2 | def dashboard_feed_path(project, object) | 2 | def dashboard_feed_path(project, object) |
3 | case object.class.name.to_s | 3 | case object.class.name.to_s |
4 | when "Issue" then project_issue_path(project, project.issues.find(object.id)) | 4 | when "Issue" then project_issue_path(project, project.issues.find(object.id)) |
5 | - when "Grit::Commit" then project_commit_path(project, project.repo.commits(object.id).first) | 5 | + when "Commit" then project_commit_path(project, project.repo.commits(object.id).first) |
6 | when "Note" | 6 | when "Note" |
7 | then | 7 | then |
8 | note = object | 8 | note = object |
app/models/commit.rb
1 | class Commit | 1 | class Commit |
2 | + attr_accessor :commit | ||
3 | + attr_accessor :head | ||
4 | + | ||
5 | + delegate :message, | ||
6 | + :committed_date, | ||
7 | + :parents, | ||
8 | + :sha, | ||
9 | + :date, | ||
10 | + :author, | ||
11 | + :message, | ||
12 | + :diffs, | ||
13 | + :tree, | ||
14 | + :id, | ||
15 | + :to => :commit | ||
16 | + | ||
17 | + def initialize(raw_commit, head = nil) | ||
18 | + @commit = raw_commit | ||
19 | + @head = head | ||
20 | + end | ||
21 | + | ||
22 | + def safe_message | ||
23 | + message.force_encoding(Encoding::UTF_8) | ||
24 | + end | ||
25 | + | ||
26 | + def created_at | ||
27 | + committed_date | ||
28 | + end | ||
29 | + | ||
30 | + def author_email | ||
31 | + author.email.force_encoding(Encoding::UTF_8) | ||
32 | + end | ||
33 | + | ||
34 | + def author_name | ||
35 | + author.name.force_encoding(Encoding::UTF_8) | ||
36 | + end | ||
2 | end | 37 | end |
app/models/repository.rb
@@ -64,16 +64,17 @@ class Repository | @@ -64,16 +64,17 @@ class Repository | ||
64 | end | 64 | end |
65 | 65 | ||
66 | def commit(commit_id = nil) | 66 | def commit(commit_id = nil) |
67 | - if commit_id | ||
68 | - repo.commits(commit_id).first | ||
69 | - else | ||
70 | - repo.commits.first | ||
71 | - end | 67 | + commit = if commit_id |
68 | + repo.commits(commit_id).first | ||
69 | + else | ||
70 | + repo.commits.first | ||
71 | + end | ||
72 | + Commit.new(commit) if commit | ||
72 | end | 73 | end |
73 | 74 | ||
74 | def fresh_commits(n = 10) | 75 | def fresh_commits(n = 10) |
75 | commits = heads.map do |h| | 76 | commits = heads.map do |h| |
76 | - repo.commits(h.name, n).each { |c| c.head = h } | 77 | + repo.commits(h.name, n).map { |c| Commit.new(c, h) } |
77 | end.flatten.uniq { |c| c.id } | 78 | end.flatten.uniq { |c| c.id } |
78 | 79 | ||
79 | commits.sort! do |x, y| | 80 | commits.sort! do |x, y| |
@@ -85,7 +86,7 @@ class Repository | @@ -85,7 +86,7 @@ class Repository | ||
85 | 86 | ||
86 | def commits_since(date) | 87 | def commits_since(date) |
87 | commits = heads.map do |h| | 88 | commits = heads.map do |h| |
88 | - repo.log(h.name, nil, :since => date).each { |c| c.head = h } | 89 | + repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) } |
89 | end.flatten.uniq { |c| c.id } | 90 | end.flatten.uniq { |c| c.id } |
90 | 91 | ||
91 | commits.sort! do |x, y| | 92 | commits.sort! do |x, y| |
@@ -94,4 +95,14 @@ class Repository | @@ -94,4 +95,14 @@ class Repository | ||
94 | 95 | ||
95 | commits | 96 | commits |
96 | end | 97 | end |
98 | + | ||
99 | + def commits(ref, path = nil, limit = nil, offset = nil) | ||
100 | + if path | ||
101 | + repo.log(ref, path, :max_count => limit, :skip => offset) | ||
102 | + elsif limit && offset | ||
103 | + repo.commits(ref, limit, offset) | ||
104 | + else | ||
105 | + repo.commits(ref) | ||
106 | + end.map{ |c| Commit.new(c) } | ||
107 | + end | ||
97 | end | 108 | end |
app/views/projects/_feed.html.haml
@@ -10,6 +10,6 @@ | @@ -10,6 +10,6 @@ | ||
10 | .right | 10 | .right |
11 | - klass = update.class.to_s.split("::").last.downcase | 11 | - klass = update.class.to_s.split("::").last.downcase |
12 | %span.tag{ :class => klass }= klass | 12 | %span.tag{ :class => klass }= klass |
13 | - - if update.kind_of?(Grit::Commit) | 13 | + - if update.kind_of?(Commit) |
14 | %span.tag.commit= update.head.name | 14 | %span.tag.commit= update.head.name |
15 | 15 |
app/views/refs/_tree_item.html.haml
1 | - file = params[:path] ? File.join(params[:path], content.name) : content.name | 1 | - file = params[:path] ? File.join(params[:path], content.name) : content.name |
2 | -- content_commit = @project.repo.log(@commit.id, file, :max_count => 1).last | 2 | +- content_commit = @project.commits(@commit.id, file, 1).last |
3 | - return unless content_commit | 3 | - return unless content_commit |
4 | %tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) } | 4 | %tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) } |
5 | %td.tree-item-file-name | 5 | %td.tree-item-file-name |
config/initializers/gitlabhq/20_grit_ext.rb
@@ -7,9 +7,5 @@ Grit::Blob.class_eval do | @@ -7,9 +7,5 @@ Grit::Blob.class_eval do | ||
7 | include Utils::Colorize | 7 | include Utils::Colorize |
8 | end | 8 | end |
9 | 9 | ||
10 | -Grit::Commit.class_eval do | ||
11 | - include CommitExt | ||
12 | -end | ||
13 | - | ||
14 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] | 10 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] |
15 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] | 11 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] |
lib/commit_ext.rb
@@ -1,20 +0,0 @@ | @@ -1,20 +0,0 @@ | ||
1 | -module CommitExt | ||
2 | - attr_accessor :head | ||
3 | - attr_accessor :refs | ||
4 | - | ||
5 | - def safe_message | ||
6 | - message.force_encoding(Encoding::UTF_8) | ||
7 | - end | ||
8 | - | ||
9 | - def created_at | ||
10 | - committed_date | ||
11 | - end | ||
12 | - | ||
13 | - def author_email | ||
14 | - author.email.force_encoding(Encoding::UTF_8) | ||
15 | - end | ||
16 | - | ||
17 | - def author_name | ||
18 | - author.name.force_encoding(Encoding::UTF_8) | ||
19 | - end | ||
20 | -end |
lib/graph_commit.rb
@@ -2,14 +2,22 @@ require "grit" | @@ -2,14 +2,22 @@ require "grit" | ||
2 | 2 | ||
3 | class GraphCommit | 3 | class GraphCommit |
4 | attr_accessor :time, :space | 4 | attr_accessor :time, :space |
5 | - def initialize(commit) | ||
6 | - @_commit = commit | ||
7 | - @time = -1 | ||
8 | - @space = 0 | ||
9 | - end | 5 | + attr_accessor :refs |
10 | 6 | ||
11 | - def method_missing(m, *args, &block) | ||
12 | - @_commit.send(m, *args, &block) | 7 | + def self.to_graph(project) |
8 | + @repo = project.repo | ||
9 | + commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650}) | ||
10 | + | ||
11 | + ref_cache = {} | ||
12 | + | ||
13 | + commits.map! {|c| GraphCommit.new(Commit.new(c))} | ||
14 | + commits.each { |commit| commit.add_refs(ref_cache, @repo) } | ||
15 | + | ||
16 | + days = GraphCommit.index_commits(commits) | ||
17 | + @days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json | ||
18 | + @commits_json = commits.map(&:to_graph_hash).to_json | ||
19 | + | ||
20 | + return @days_json, @commits_json | ||
13 | end | 21 | end |
14 | 22 | ||
15 | # Method is adding time and space on the | 23 | # Method is adding time and space on the |
@@ -72,4 +80,41 @@ class GraphCommit | @@ -72,4 +80,41 @@ class GraphCommit | ||
72 | marks.compact.max | 80 | marks.compact.max |
73 | end | 81 | end |
74 | 82 | ||
83 | + | ||
84 | + def initialize(commit) | ||
85 | + @_commit = commit | ||
86 | + @time = -1 | ||
87 | + @space = 0 | ||
88 | + end | ||
89 | + | ||
90 | + def method_missing(m, *args, &block) | ||
91 | + @_commit.send(m, *args, &block) | ||
92 | + end | ||
93 | + | ||
94 | + def to_graph_hash | ||
95 | + h = {} | ||
96 | + h[:parents] = self.parents.collect do |p| | ||
97 | + [p.id,0,0] | ||
98 | + end | ||
99 | + h[:author] = author.name.force_encoding("UTF-8") | ||
100 | + h[:time] = time | ||
101 | + h[:space] = space | ||
102 | + h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? | ||
103 | + h[:id] = sha | ||
104 | + h[:date] = date | ||
105 | + h[:message] = message.force_encoding("UTF-8") | ||
106 | + h[:login] = author.email | ||
107 | + h | ||
108 | + end | ||
109 | + | ||
110 | + def add_refs(ref_cache, repo) | ||
111 | + if ref_cache.empty? | ||
112 | + repo.refs.each do |ref| | ||
113 | + ref_cache[ref.commit.id] ||= [] | ||
114 | + ref_cache[ref.commit.id] << ref | ||
115 | + end | ||
116 | + end | ||
117 | + @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) | ||
118 | + @refs ||= [] | ||
119 | + end | ||
75 | end | 120 | end |
spec/requests/commits_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper' | @@ -2,7 +2,7 @@ require 'spec_helper' | ||
2 | 2 | ||
3 | describe "Commits" do | 3 | describe "Commits" do |
4 | let(:project) { Factory :project } | 4 | let(:project) { Factory :project } |
5 | - let!(:commit) { project.repo.commits.first } | 5 | + let!(:commit) { project.commit } |
6 | before do | 6 | before do |
7 | login_as :user | 7 | login_as :user |
8 | project.add_access(@user, :read) | 8 | project.add_access(@user, :read) |
@@ -48,11 +48,11 @@ describe "Commits" do | @@ -48,11 +48,11 @@ describe "Commits" do | ||
48 | 48 | ||
49 | describe "GET /commits/:id" do | 49 | describe "GET /commits/:id" do |
50 | before do | 50 | before do |
51 | - visit project_commit_path(project, commit) | 51 | + visit project_commit_path(project, commit.id) |
52 | end | 52 | end |
53 | 53 | ||
54 | it "should have valid path" do | 54 | it "should have valid path" do |
55 | - current_path.should == project_commit_path(project, commit) | 55 | + current_path.should == project_commit_path(project, commit.id) |
56 | end | 56 | end |
57 | end | 57 | end |
58 | end | 58 | end |
spec/requests/projects_security_spec.rb
@@ -55,12 +55,12 @@ describe "Projects" do | @@ -55,12 +55,12 @@ describe "Projects" do | ||
55 | end | 55 | end |
56 | 56 | ||
57 | describe "GET /project_code/commit" do | 57 | describe "GET /project_code/commit" do |
58 | - it { project_commit_path(@project, @project.commit).should be_allowed_for @u1 } | ||
59 | - it { project_commit_path(@project, @project.commit).should be_allowed_for @u3 } | ||
60 | - it { project_commit_path(@project, @project.commit).should be_denied_for :admin } | ||
61 | - it { project_commit_path(@project, @project.commit).should be_denied_for @u2 } | ||
62 | - it { project_commit_path(@project, @project.commit).should be_denied_for :user } | ||
63 | - it { project_commit_path(@project, @project.commit).should be_denied_for :visitor } | 58 | + it { project_commit_path(@project, @project.commit.id).should be_allowed_for @u1 } |
59 | + it { project_commit_path(@project, @project.commit.id).should be_allowed_for @u3 } | ||
60 | + it { project_commit_path(@project, @project.commit.id).should be_denied_for :admin } | ||
61 | + it { project_commit_path(@project, @project.commit.id).should be_denied_for @u2 } | ||
62 | + it { project_commit_path(@project, @project.commit.id).should be_denied_for :user } | ||
63 | + it { project_commit_path(@project, @project.commit.id).should be_denied_for :visitor } | ||
64 | end | 64 | end |
65 | 65 | ||
66 | describe "GET /project_code/team" do | 66 | describe "GET /project_code/team" do |
spec/requests/projects_spec.rb
@@ -79,6 +79,7 @@ describe "Projects" do | @@ -79,6 +79,7 @@ describe "Projects" do | ||
79 | end | 79 | end |
80 | 80 | ||
81 | it "should beahave like activities page" do | 81 | it "should beahave like activities page" do |
82 | + save_and_open_page | ||
82 | within ".project-update" do | 83 | within ".project-update" do |
83 | page.should have_content("master") | 84 | page.should have_content("master") |
84 | page.should have_content(@project.commit.author.name) | 85 | page.should have_content(@project.commit.author.name) |