diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 9dac240f2817c789ef7f8213d62435e316706fb2..b9da1e09d4be13c11dd6252ba3d77c010aa48499 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -175,7 +175,7 @@ def commits # or from cache if already merged @commits = set_commits_for_rendering( - @merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch).with_markdown_cache, + @merge_request.recent_commits(load_from_gitaly: true).with_latest_pipeline(@merge_request.source_branch).with_markdown_cache, commits_count: @merge_request.commits_count ) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index cf1468c5c53c2df4bfce6ce4aa71c985accf81e0..156540d455c6d5b54229a9933cc60500f759dc52 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -615,8 +615,8 @@ def context_commits_count context_commits.count end - def commits(limit: nil) - return merge_request_diff.commits(limit: limit) if merge_request_diff.persisted? + def commits(limit: nil, load_from_gitaly: false) + return merge_request_diff.commits(limit: limit, load_from_gitaly: load_from_gitaly) if merge_request_diff.persisted? commits_arr = if compare_commits reversed_commits = compare_commits.reverse @@ -628,8 +628,8 @@ def commits(limit: nil) CommitCollection.new(source_project, commits_arr, source_branch) end - def recent_commits - commits(limit: MergeRequestDiff::COMMITS_SAFE_SIZE) + def recent_commits(load_from_gitaly: false) + commits(limit: MergeRequestDiff::COMMITS_SAFE_SIZE, load_from_gitaly: load_from_gitaly) end def commits_count diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index bea75927b2cc1b2f14386df48de26fc690321624..d2b3ca753b1d6c1a71b42dbe918b21da5add8299 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -288,9 +288,9 @@ def raw_diffs(options = {}) end end - def commits(limit: nil) - strong_memoize(:"commits_#{limit || 'all'}") do - load_commits(limit: limit) + def commits(limit: nil, load_from_gitaly: false) + strong_memoize(:"commits_#{limit || 'all'}_#{load_from_gitaly}") do + load_commits(limit: limit, load_from_gitaly: load_from_gitaly) end end @@ -700,9 +700,14 @@ def load_diffs(options) end end - def load_commits(limit: nil) - commits = merge_request_diff_commits.with_users.limit(limit) - .map { |commit| Commit.from_hash(commit.to_hash, project) } + def load_commits(limit: nil, load_from_gitaly: false) + if load_from_gitaly + commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.limit(limit).map(&:sha)) + commits = Commit.decorate(commits, project) + else + commits = merge_request_diff_commits.with_users.limit(limit) + .map { |commit| Commit.from_hash(commit.to_hash, project) } + end CommitCollection .new(merge_request.source_project, commits, merge_request.source_branch) diff --git a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb index fd77c4eb37220e40a8ca0897c75a501a3f16688e..f0273c1716f661c94508dd778fbd3d5da8db972e 100644 --- a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb +++ b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb @@ -21,7 +21,7 @@ controller.prepend_view_path('app/views/projects') assign(:merge_request, merge_request) - assign(:commits, merge_request.commits) + assign(:commits, merge_request.commits(load_from_gitaly: true)) assign(:hidden_commit_count, 0) end @@ -34,6 +34,12 @@ expect(rendered).to have_link(href: href) end + it 'shows signature verification badge' do + render + + expect(rendered).to have_css('.gpg-status-box') + end + context 'when there are hidden commits' do before do assign(:hidden_commit_count, 1)