summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-21 15:09:15 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-24 12:29:36 +0200
commit84a1590252c63c710bceaa7a394799cdc5109505 (patch)
tree12d9b499acad48dc9420d095803705093d2b135d /app/models
parentb0ed2ff1a69df384a1cb9a184c0528bec1986827 (diff)
downloadgitlab-ce-84a1590252c63c710bceaa7a394799cdc5109505.tar.gz
Let commit model know about its project.
Diffstat (limited to 'app/models')
-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
5 files changed, 21 insertions, 13 deletions
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