Commit 3a6967ae authored by Lin Jen-Shin's avatar Lin Jen-Shin

Move identical merged branch check to merged_branch_names

parent 1f774de6
...@@ -916,19 +916,13 @@ class Repository ...@@ -916,19 +916,13 @@ class Repository
end end
end end
def merged_to_root_ref?(branch_or_name, pre_loaded_merged_branches = nil) def merged_to_root_ref?(branch_or_name)
branch = Gitlab::Git::Branch.find(self, branch_or_name) branch = Gitlab::Git::Branch.find(self, branch_or_name)
if branch if branch
@root_ref_sha ||= commit(root_ref).sha @root_ref_sha ||= commit(root_ref).sha
same_head = branch.target == @root_ref_sha same_head = branch.target == @root_ref_sha
merged = merged = ancestor?(branch.target, @root_ref_sha)
if pre_loaded_merged_branches
pre_loaded_merged_branches.include?(branch.name)
else
ancestor?(branch.target, @root_ref_sha)
end
!same_head && merged !same_head && merged
else else
nil nil
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
- if @branches.any? - if @branches.any?
%ul.content-list.all-branches %ul.content-list.all-branches
- @branches.each do |branch| - @branches.each do |branch|
= render "projects/branches/branch", branch: branch, merged: @repository.merged_to_root_ref?(branch, @merged_branch_names) = render "projects/branches/branch", branch: branch, merged: @merged_branch_names.include?(branch.name)
= paginate @branches, theme: 'gitlab' = paginate @branches, theme: 'gitlab'
- else - else
.nothing-here-block .nothing-here-block
......
...@@ -271,7 +271,11 @@ module API ...@@ -271,7 +271,11 @@ module API
end end
expose :merged do |repo_branch, options| expose :merged do |repo_branch, options|
options[:project].repository.merged_to_root_ref?(repo_branch, options[:merged_branch_names]) if options[:merged_branch_names]
options[:merged_branch_names].include?(repo_branch.name)
else
options[:project].repository.merged_to_root_ref?(repo_branch)
end
end end
expose :protected do |repo_branch, options| expose :protected do |repo_branch, options|
......
...@@ -1222,11 +1222,21 @@ module Gitlab ...@@ -1222,11 +1222,21 @@ module Gitlab
sort_branches(branches, sort_by) sort_branches(branches, sort_by)
end end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695
def git_merged_branch_names(branch_names = []) def git_merged_branch_names(branch_names = [])
lines = run_git(['branch', '--merged', root_ref] + branch_names) root_sha = find_branch(root_ref).target
.first.lines
lines.map(&:strip) git_arguments =
%W[branch --merged #{root_sha}
--format=%(refname:short)\ %(objectname)] + branch_names
lines = run_git(git_arguments).first.lines
lines.each_with_object([]) do |line, branches|
name, sha = line.strip.split(' ', 2)
branches << name if sha != root_sha
end
end end
def log_using_shell?(options) def log_using_shell?(options)
......
...@@ -1211,12 +1211,17 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1211,12 +1211,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
context 'when no branch names are specified' do context 'when no branch names are specified' do
it 'returns all merged branch names' do before do
repository.create_branch('identical', 'master')
end
it 'returns all merged branch names except for identical one' do
names = repository.merged_branch_names names = repository.merged_branch_names
expect(names).to include('merge-test') expect(names).to include('merge-test')
expect(names).to include('fix-mode') expect(names).to include('fix-mode')
expect(names).not_to include('feature') expect(names).not_to include('feature')
expect(names).not_to include('identical')
end end
end end
end end
......
...@@ -299,24 +299,6 @@ describe Repository do ...@@ -299,24 +299,6 @@ describe Repository do
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when pre-loaded merged branches are provided' do
using RSpec::Parameterized::TableSyntax
where(:branch, :pre_loaded, :expected) do
'not-merged-branch' | ['branch-merged'] | false
'branch-merged' | ['not-merged-branch'] | false
'branch-merged' | ['branch-merged'] | true
'not-merged-branch' | ['not-merged-branch'] | false
'master' | ['master'] | false
end
with_them do
subject { repository.merged_to_root_ref?(branch, pre_loaded) }
it { is_expected.to eq(expected) }
end
end
end end
describe '#can_be_merged?' do describe '#can_be_merged?' do
......
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