summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/commits_controller.rb2
-rw-r--r--app/models/repository.rb21
-rw-r--r--app/views/projects/commits/show.html.haml2
3 files changed, 14 insertions, 11 deletions
diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb
index 66e27524a23..bf5b54c8cb7 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).compact
+ @repository.find_commits_by_message(search, @ref, @path, @limit, @offset).compact
else
@repository.commits(@ref, @path, @limit, @offset)
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 9deb08d93b8..d9ff71c01ed 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -92,9 +92,12 @@ class Repository
commits
end
- def find_commits_by_message(query)
+ def find_commits_by_message(query, ref = nil, path = nil, limit = 1000, offset = 0)
+ ref ||= root_ref
+
# Limited to 1000 commits for now, could be parameterized?
- args = %W(#{Gitlab.config.git.bin_path} log --pretty=%H --max-count 1000 --grep=#{query})
+ args = %W(#{Gitlab.config.git.bin_path} log #{ref} --pretty=%H --skip #{offset} --max-count #{limit} --grep=#{query})
+ 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) }
@@ -175,7 +178,7 @@ class Repository
def size
cache.fetch(:size) { raw_repository.size }
end
-
+
def diverging_commit_counts(branch)
root_ref_hash = raw_repository.rev_parse_target(root_ref).oid
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
@@ -183,7 +186,7 @@ class Repository
# than SHA-1 hashes
number_commits_behind = commits_between(branch.target, root_ref_hash).size
number_commits_ahead = commits_between(root_ref_hash, branch.target).size
-
+
{ behind: number_commits_behind, ahead: number_commits_ahead }
end
end
@@ -192,7 +195,7 @@ class Repository
%i(size branch_names tag_names commit_count
readme version contribution_guide changelog license)
end
-
+
def branch_cache_keys
branches.map do |branch|
:"diverging_commit_counts_#{branch.name}"
@@ -205,7 +208,7 @@ class Repository
send(key)
end
end
-
+
branches.each do |branch|
unless cache.exist?(:"diverging_commit_counts_#{branch.name}")
send(:diverging_commit_counts, branch)
@@ -227,10 +230,10 @@ class Repository
cache_keys.each do |key|
cache.expire(key)
end
-
+
expire_branch_cache
end
-
+
def expire_branch_cache
branches.each do |branch|
cache.expire(:"diverging_commit_counts_#{branch.name}")
@@ -242,7 +245,7 @@ class Repository
cache.expire(key)
send(key)
end
-
+
branches.each do |branch|
cache.expire(:"diverging_commit_counts_#{branch.name}")
diverging_commit_counts(branch)
diff --git a/app/views/projects/commits/show.html.haml b/app/views/projects/commits/show.html.haml
index 5e59afcd783..8f6625fef8a 100644
--- a/app/views/projects/commits/show.html.haml
+++ b/app/views/projects/commits/show.html.haml
@@ -18,7 +18,7 @@
Create Merge Request
.pull-left.prepend-left-10
- = form_tag(namespace_project_commits_path(@project.namespace, @project, @ref), method: :get, class: 'pull-left commits-search-form') do
+ = form_tag(namespace_project_commits_path(@project.namespace, @project, @id), method: :get, class: 'pull-left commits-search-form') do
= search_field_tag :search, params[:search], { placeholder: 'Filter by commit message', id: 'commits-search', class: 'form-control search-text-input', spellcheck: false }
- if current_user && current_user.private_token