Commit 4443a5f3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add support for ref and path to commits filtering

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent b2b4e9a7
...@@ -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).compact @repository.find_commits_by_message(search, @ref, @path, @limit, @offset).compact
else else
@repository.commits(@ref, @path, @limit, @offset) @repository.commits(@ref, @path, @limit, @offset)
end end
......
...@@ -92,9 +92,12 @@ class Repository ...@@ -92,9 +92,12 @@ class Repository
commits commits
end 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? # 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) 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.map { |c| commit(c) }
...@@ -175,7 +178,7 @@ class Repository ...@@ -175,7 +178,7 @@ class Repository
def size def size
cache.fetch(:size) { raw_repository.size } cache.fetch(:size) { raw_repository.size }
end end
def diverging_commit_counts(branch) def diverging_commit_counts(branch)
root_ref_hash = raw_repository.rev_parse_target(root_ref).oid root_ref_hash = raw_repository.rev_parse_target(root_ref).oid
cache.fetch(:"diverging_commit_counts_#{branch.name}") do cache.fetch(:"diverging_commit_counts_#{branch.name}") do
...@@ -183,7 +186,7 @@ class Repository ...@@ -183,7 +186,7 @@ class Repository
# than SHA-1 hashes # than SHA-1 hashes
number_commits_behind = commits_between(branch.target, root_ref_hash).size number_commits_behind = commits_between(branch.target, root_ref_hash).size
number_commits_ahead = commits_between(root_ref_hash, branch.target).size number_commits_ahead = commits_between(root_ref_hash, branch.target).size
{ behind: number_commits_behind, ahead: number_commits_ahead } { behind: number_commits_behind, ahead: number_commits_ahead }
end end
end end
...@@ -192,7 +195,7 @@ class Repository ...@@ -192,7 +195,7 @@ class Repository
%i(size branch_names tag_names commit_count %i(size branch_names tag_names commit_count
readme version contribution_guide changelog license) readme version contribution_guide changelog license)
end end
def branch_cache_keys def branch_cache_keys
branches.map do |branch| branches.map do |branch|
:"diverging_commit_counts_#{branch.name}" :"diverging_commit_counts_#{branch.name}"
...@@ -205,7 +208,7 @@ class Repository ...@@ -205,7 +208,7 @@ class Repository
send(key) send(key)
end end
end end
branches.each do |branch| branches.each do |branch|
unless cache.exist?(:"diverging_commit_counts_#{branch.name}") unless cache.exist?(:"diverging_commit_counts_#{branch.name}")
send(:diverging_commit_counts, branch) send(:diverging_commit_counts, branch)
...@@ -227,10 +230,10 @@ class Repository ...@@ -227,10 +230,10 @@ class Repository
cache_keys.each do |key| cache_keys.each do |key|
cache.expire(key) cache.expire(key)
end end
expire_branch_cache expire_branch_cache
end end
def expire_branch_cache def expire_branch_cache
branches.each do |branch| branches.each do |branch|
cache.expire(:"diverging_commit_counts_#{branch.name}") cache.expire(:"diverging_commit_counts_#{branch.name}")
...@@ -242,7 +245,7 @@ class Repository ...@@ -242,7 +245,7 @@ class Repository
cache.expire(key) cache.expire(key)
send(key) send(key)
end end
branches.each do |branch| branches.each do |branch|
cache.expire(:"diverging_commit_counts_#{branch.name}") cache.expire(:"diverging_commit_counts_#{branch.name}")
diverging_commit_counts(branch) diverging_commit_counts(branch)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
Create Merge Request Create Merge Request
.pull-left.prepend-left-10 .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 } = 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 - if current_user && current_user.private_token
......
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