Commit 7412e2fa authored by Bob Van Landuyt's avatar Bob Van Landuyt

Get `repository` from noteable in DiffNotes

Getting the `repository` directly from the noteable in DiffNotes
allows us to use a different repository when the DiffNote is not
on a project repository.

It is only the first step in decoupling the DiffNote from a project's
main repository.
parent 4504959a
...@@ -46,7 +46,7 @@ class DiffNote < Note ...@@ -46,7 +46,7 @@ class DiffNote < Note
# Returns the diff file from `position` # Returns the diff file from `position`
def latest_diff_file def latest_diff_file
strong_memoize(:latest_diff_file) do strong_memoize(:latest_diff_file) do
position.diff_file(project.repository) position.diff_file(repository)
end end
end end
...@@ -113,7 +113,7 @@ class DiffNote < Note ...@@ -113,7 +113,7 @@ class DiffNote < Note
if note_diff_file if note_diff_file
diff = Gitlab::Git::Diff.new(note_diff_file.to_hash) diff = Gitlab::Git::Diff.new(note_diff_file.to_hash)
Gitlab::Diff::File.new(diff, Gitlab::Diff::File.new(diff,
repository: project.repository, repository: repository,
diff_refs: original_position.diff_refs) diff_refs: original_position.diff_refs)
elsif created_at_diff?(noteable.diff_refs) elsif created_at_diff?(noteable.diff_refs)
# We're able to use the already persisted diffs (Postgres) if we're # We're able to use the already persisted diffs (Postgres) if we're
...@@ -124,7 +124,7 @@ class DiffNote < Note ...@@ -124,7 +124,7 @@ class DiffNote < Note
# `Diff::FileCollection::MergeRequestDiff`. # `Diff::FileCollection::MergeRequestDiff`.
noteable.diffs(original_position.diff_options).diff_files.first noteable.diffs(original_position.diff_options).diff_files.first
else else
original_position.diff_file(self.project.repository) original_position.diff_file(repository)
end end
# Since persisted diff files already have its content "unfolded" # Since persisted diff files already have its content "unfolded"
...@@ -139,7 +139,7 @@ class DiffNote < Note ...@@ -139,7 +139,7 @@ class DiffNote < Note
end end
def set_line_code def set_line_code
self.line_code = self.position.line_code(self.project.repository) self.line_code = self.position.line_code(repository)
end end
def verify_supported def verify_supported
...@@ -173,6 +173,10 @@ class DiffNote < Note ...@@ -173,6 +173,10 @@ class DiffNote < Note
shas << self.position.head_sha shas << self.position.head_sha
end end
project.repository.keep_around(*shas) repository.keep_around(*shas)
end
def repository
noteable.respond_to?(:repository) ? noteable.repository : project.repository
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment