Commit 6f875903 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'refactoring_find_commits_method' into 'master'

Refactoring find_commits method

It's possible that `find_commits_by_message` return nil in array which is not OK. We have different checks outside of this method. This MR places all checks inside the method.

See merge request !7000
parents ba28a64e fd2c3a3d
...@@ -13,7 +13,7 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -13,7 +13,7 @@ class Projects::CommitsController < Projects::ApplicationController
@commits = @commits =
if search.present? if search.present?
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset).compact @repository.find_commits_by_message(search, @ref, @path, @limit, @offset)
else else
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset) @repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end end
......
...@@ -109,6 +109,10 @@ class Repository ...@@ -109,6 +109,10 @@ class Repository
end end
def find_commits_by_message(query, ref = nil, path = nil, limit = 1000, offset = 0) def find_commits_by_message(query, ref = nil, path = nil, limit = 1000, offset = 0)
unless exists? && has_visible_content? && query.present?
return []
end
ref ||= root_ref ref ||= root_ref
args = %W( args = %W(
...@@ -117,9 +121,8 @@ class Repository ...@@ -117,9 +121,8 @@ class Repository
) )
args = args.concat(%W(-- #{path})) if path.present? args = args.concat(%W(-- #{path})) if path.present?
git_log_results = Gitlab::Popen.popen(args, path_to_repo).first.lines.map(&:chomp) git_log_results = Gitlab::Popen.popen(args, path_to_repo).first.lines
commits = git_log_results.map { |c| commit(c) } git_log_results.map { |c| commit(c.chomp) }.compact
commits
end end
def find_branch(name, fresh_repo: true) def find_branch(name, fresh_repo: true)
......
...@@ -73,11 +73,7 @@ module Gitlab ...@@ -73,11 +73,7 @@ module Gitlab
end end
def commits def commits
if project.empty_repo? || query.blank? project.repository.find_commits_by_message(query)
[]
else
project.repository.find_commits_by_message(query).compact
end
end end
def project_ids_relation def project_ids_relation
......
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