summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/mailers/emails/projects.rb6
-rw-r--r--app/models/commit.rb11
-rw-r--r--app/models/merge_request_diff.rb4
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/project_wiki.rb2
-rw-r--r--app/models/repository.rb11
-rw-r--r--app/services/merge_requests/build_service.rb2
-rw-r--r--app/views/projects/blame/show.html.haml2
-rw-r--r--app/views/projects/commits/_commit_list.html.haml4
-rw-r--r--app/workers/irker_worker.rb3
-rw-r--r--lib/api/entities.rb4
-rw-r--r--spec/mailers/notify_spec.rb6
12 files changed, 34 insertions, 27 deletions
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb
index 0dbb2939bb3..9cb7077e59d 100644
--- a/app/mailers/emails/projects.rb
+++ b/app/mailers/emails/projects.rb
@@ -79,7 +79,7 @@ module Emails
@disable_diffs = disable_diffs
if @compare
- @commits = Commit.decorate(compare.commits)
+ @commits = Commit.decorate(compare.commits, @project)
@diffs = compare.diffs
end
@@ -101,8 +101,8 @@ module Emails
if @commits.length > 1
@target_url = namespace_project_compare_url(@project.namespace,
@project,
- from: Commit.new(@compare.base),
- to: Commit.new(@compare.head))
+ from: Commit.new(@compare.base, @project),
+ to: Commit.new(@compare.head, @project))
@subject << "Deleted " if @reverse_compare
@subject << "#{@commits.length} commits: #{@commits.first.title}"
else
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 1cabc060c2a..d4e9ebacac6 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -6,6 +6,8 @@ class Commit
attr_mentionable :safe_message
+ attr_accessor :project
+
# Safe amount of changes (files and lines) in one commit to render
# Used to prevent 500 error on huge commits by suppressing diff
#
@@ -18,12 +20,12 @@ class Commit
DIFF_HARD_LIMIT_LINES = 50000 unless defined?(DIFF_HARD_LIMIT_LINES)
class << self
- def decorate(commits)
+ def decorate(commits, project)
commits.map do |commit|
if commit.kind_of?(Commit)
commit
else
- self.new(commit)
+ self.new(commit, project)
end
end
end
@@ -41,10 +43,11 @@ class Commit
attr_accessor :raw
- def initialize(raw_commit)
+ def initialize(raw_commit, project)
raise "Nil as raw commit passed" unless raw_commit
@raw = raw_commit
+ @project = project
end
def id
@@ -169,6 +172,6 @@ class Commit
end
def parents
- @parents ||= Commit.decorate(super)
+ @parents ||= Commit.decorate(super, project)
end
end
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index acac1ca4cf7..df1c2b78758 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -67,7 +67,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
def load_commits(array)
- array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) }
+ array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash), merge_request.source_project) }
end
def dump_diffs(diffs)
@@ -88,7 +88,7 @@ class MergeRequestDiff < ActiveRecord::Base
commits = compare_result.commits
if commits.present?
- commits = Commit.decorate(commits).
+ commits = Commit.decorate(commits, merge_request.source_project).
sort_by(&:created_at).
reverse
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 64ee2c2212b..4c1404ee9f8 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -254,7 +254,11 @@ class Project < ActiveRecord::Base
end
def repository
- @repository ||= Repository.new(path_with_namespace)
+ @repository ||= Repository.new(path_with_namespace, nil, self)
+ end
+
+ def commit(id)
+ repository.commit(id)
end
def saved?
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 772c868d9cd..0706a1ca0d1 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -112,7 +112,7 @@ class ProjectWiki
end
def repository
- Repository.new(path_with_namespace, default_branch)
+ Repository.new(path_with_namespace, default_branch, @project)
end
def default_branch
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 263a436d521..1b8c74028d9 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -1,11 +1,12 @@
class Repository
include Gitlab::ShellAdapter
- attr_accessor :raw_repository, :path_with_namespace
+ attr_accessor :raw_repository, :path_with_namespace, :project
- def initialize(path_with_namespace, default_branch = nil)
+ def initialize(path_with_namespace, default_branch = nil, project = nil)
@path_with_namespace = path_with_namespace
@raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace
+ @project = project
rescue Gitlab::Git::Repository::NoRepository
nil
end
@@ -28,7 +29,7 @@ class Repository
def commit(id = 'HEAD')
return nil unless raw_repository
commit = Gitlab::Git::Commit.find(raw_repository, id)
- commit = Commit.new(commit) if commit
+ commit = Commit.new(commit, @project) if commit
commit
rescue Rugged::OdbError
nil
@@ -42,13 +43,13 @@ class Repository
limit: limit,
offset: offset,
)
- commits = Commit.decorate(commits) if commits.present?
+ commits = Commit.decorate(commits, @project) if commits.present?
commits
end
def commits_between(from, to)
commits = Gitlab::Git::Commit.between(raw_repository, from, to)
- commits = Commit.decorate(commits) if commits.present?
+ commits = Commit.decorate(commits, @project) if commits.present?
commits
end
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb
index a44b91166e8..956480938c3 100644
--- a/app/services/merge_requests/build_service.rb
+++ b/app/services/merge_requests/build_service.rb
@@ -29,7 +29,7 @@ module MergeRequests
# At this point we decide if merge request can be created
# If we have at least one commit to merge -> creation allowed
if commits.present?
- merge_request.compare_commits = Commit.decorate(commits)
+ merge_request.compare_commits = Commit.decorate(commits, merge_request.source_project)
merge_request.can_be_created = true
merge_request.compare_failed = false
diff --git a/app/views/projects/blame/show.html.haml b/app/views/projects/blame/show.html.haml
index e6a859fea8f..89dd68d6471 100644
--- a/app/views/projects/blame/show.html.haml
+++ b/app/views/projects/blame/show.html.haml
@@ -12,7 +12,7 @@
.file-content.blame.highlight
%table
- @blame.each do |commit, lines, since|
- - commit = Commit.new(commit)
+ - commit = Commit.new(commit, @project)
%tr
%td.blame-commit
%span.commit
diff --git a/app/views/projects/commits/_commit_list.html.haml b/app/views/projects/commits/_commit_list.html.haml
index 2ee7d73bd20..ce60fbdf032 100644
--- a/app/views/projects/commits/_commit_list.html.haml
+++ b/app/views/projects/commits/_commit_list.html.haml
@@ -3,9 +3,9 @@
Commits (#{@commits.count})
- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
%ul.well-list
- - Commit.decorate(@commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE)).each do |commit|
+ - Commit.decorate(@commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE), @project).each do |commit|
= render "projects/commits/inline_commit", commit: commit, project: @project
%li.warning-row.unstyled
other #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} commits hidden to prevent performance issues.
- else
- %ul.well-list= render Commit.decorate(@commits), project: @project
+ %ul.well-list= render Commit.decorate(@commits, @project), project: @project
diff --git a/app/workers/irker_worker.rb b/app/workers/irker_worker.rb
index 8b50f423984..84a54656df2 100644
--- a/app/workers/irker_worker.rb
+++ b/app/workers/irker_worker.rb
@@ -137,8 +137,7 @@ class IrkerWorker
end
def commit_from_id(project, id)
- commit = Gitlab::Git::Commit.find(project.repository, id)
- Commit.new(commit)
+ project.commit(id)
end
def files_count(commit)
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 36332bc6514..79b4afa40ba 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -251,11 +251,11 @@ module API
class Compare < Grape::Entity
expose :commit, using: Entities::RepoCommit do |compare, options|
- Commit.decorate(compare.commits).last
+ Commit.decorate(compare.commits, nil).last
end
expose :commits, using: Entities::RepoCommit do |compare, options|
- Commit.decorate(compare.commits)
+ Commit.decorate(compare.commits, nil)
end
expose :diffs, using: Entities::RepoDiff do |compare, options|
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index b297fbd5119..6f7f5835b94 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -670,8 +670,8 @@ describe Notify do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, sample_image_commit.id, sample_commit.id) }
- let(:commits) { Commit.decorate(compare.commits) }
- let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: Commit.new(compare.base), to: Commit.new(compare.head)) }
+ let(:commits) { Commit.decorate(compare.commits, nil) }
+ let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: Commit.new(compare.base, project), to: Commit.new(compare.head, project)) }
let(:send_from_committer_email) { false }
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare, reverse_compare: false, send_from_committer_email: send_from_committer_email) }
@@ -774,7 +774,7 @@ describe Notify do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, sample_commit.parent_id, sample_commit.id) }
- let(:commits) { Commit.decorate(compare.commits) }
+ let(:commits) { Commit.decorate(compare.commits, nil) }
let(:diff_path) { namespace_project_commit_path(project.namespace, project, commits.first) }
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare) }