summaryrefslogtreecommitdiff
path: root/app/models/commit_collection.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-04 15:08:40 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-04 15:08:40 +0000
commit6b833f1e0340e00fdee074da9c42c0d4e07a46d2 (patch)
tree6fc3a7a2f8a02fec8d1e7561b453d33eb4048dad /app/models/commit_collection.rb
parent88a0824944720b6edaaef56376713541b9a02118 (diff)
downloadgitlab-ce-6b833f1e0340e00fdee074da9c42c0d4e07a46d2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/commit_collection.rb')
-rw-r--r--app/models/commit_collection.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/models/commit_collection.rb b/app/models/commit_collection.rb
index d4c29aa295b..456d32bf403 100644
--- a/app/models/commit_collection.rb
+++ b/app/models/commit_collection.rb
@@ -1,17 +1,20 @@
# frozen_string_literal: true
-# A collection of Commit instances for a specific project and Git reference.
+# A collection of Commit instances for a specific container and Git reference.
class CommitCollection
include Enumerable
include Gitlab::Utils::StrongMemoize
- attr_reader :project, :ref, :commits
+ attr_reader :container, :ref, :commits
- # project - The project the commits belong to.
+ delegate :repository, to: :container, allow_nil: true
+ delegate :project, to: :repository, allow_nil: true
+
+ # container - The object the commits belong to.
# commits - The Commit instances to store.
# ref - The name of the ref (e.g. "master").
- def initialize(project, commits, ref = nil)
- @project = project
+ def initialize(container, commits, ref = nil)
+ @container = container
@commits = commits
@ref = ref
end
@@ -39,6 +42,8 @@ class CommitCollection
# Setting the pipeline for each commit ahead of time removes the need for running
# a query for every commit we're displaying.
def with_latest_pipeline(ref = nil)
+ return self unless project
+
pipelines = project.ci_pipelines.latest_pipeline_per_commit(map(&:id), ref)
each do |commit|
@@ -59,16 +64,16 @@ class CommitCollection
# Batch load any commits that are not backed by full gitaly data, and
# replace them in the collection.
def enrich!
- # A project is needed in order to fetch data from gitaly. Projects
+ # A container is needed in order to fetch data from gitaly. Containers
# can be absent from commits in certain rare situations (like when
# viewing a MR of a deleted fork). In these cases, assume that the
# enriched data is not needed.
- return self if project.blank? || fully_enriched?
+ return self if container.blank? || fully_enriched?
# Batch load full Commits from the repository
# and map to a Hash of id => Commit
replacements = Hash[unenriched.map do |c|
- [c.id, Commit.lazy(project, c.id)]
+ [c.id, Commit.lazy(container, c.id)]
end.compact]
# Replace the commits, keeping the same order