summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-10-19 19:43:04 +0300
committerValery Sizov <valery@gitlab.com>2016-10-20 12:45:34 +0300
commitfd2c3a3da0302a474d7c1adbd409aedea2a41053 (patch)
tree5e10605f62a9a51fded5ef7874e6da8c8154c081 /app
parentf0c7e6713f2778a2b52ab8091c398a96982380de (diff)
downloadgitlab-ce-fd2c3a3da0302a474d7c1adbd409aedea2a41053.tar.gz
Refactoring find_commits functionality
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/commits_controller.rb2
-rw-r--r--app/models/repository.rb9
2 files changed, 7 insertions, 4 deletions
diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb
index a52c614b259..c2e7bf1ffec 100644
--- a/app/controllers/projects/commits_controller.rb
+++ b/app/controllers/projects/commits_controller.rb
@@ -13,7 +13,7 @@ class Projects::CommitsController < Projects::ApplicationController
@commits =
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
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 72e473871fa..1b7f20a2134 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -109,6 +109,10 @@ class Repository
end
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
args = %W(
@@ -117,9 +121,8 @@ class Repository
)
args = args.concat(%W(-- #{path})) if path.present?
- git_log_results = Gitlab::Popen.popen(args, path_to_repo).first.lines.map(&:chomp)
- commits = git_log_results.map { |c| commit(c) }
- commits
+ git_log_results = Gitlab::Popen.popen(args, path_to_repo).first.lines
+ git_log_results.map { |c| commit(c.chomp) }.compact
end
def find_branch(name, fresh_repo: true)