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
@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
......
......@@ -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)
......
......@@ -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
......
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