summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-11-18 02:13:45 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-11-23 18:26:41 +0800
commit7df1cb528e5d977f5f18b1c82433b3c76220d6db (patch)
tree1a0910dfdf21cf1c90192c8295c41ebc57b58376
parent3e558d8dbdbf39a0241b1e72ee494362624ace38 (diff)
downloadgitlab-ce-7df1cb528e5d977f5f18b1c82433b3c76220d6db.tar.gz
Move identical merged branch check to merged_branch_names
-rw-r--r--app/models/repository.rb10
-rw-r--r--app/views/projects/branches/index.html.haml2
-rw-r--r--lib/api/entities.rb6
-rw-r--r--lib/gitlab/git/repository.rb16
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb7
-rw-r--r--spec/models/repository_spec.rb18
6 files changed, 27 insertions, 32 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 2bf21cbdcc4..d4ffd7bfc07 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -909,19 +909,13 @@ class Repository
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)
if branch
@root_ref_sha ||= commit(root_ref).sha
same_head = branch.target == @root_ref_sha
- merged =
- if pre_loaded_merged_branches
- pre_loaded_merged_branches.include?(branch.name)
- else
- ancestor?(branch.target, @root_ref_sha)
- end
-
+ merged = ancestor?(branch.target, @root_ref_sha)
!same_head && merged
else
nil
diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml
index aade310236e..fb770764364 100644
--- a/app/views/projects/branches/index.html.haml
+++ b/app/views/projects/branches/index.html.haml
@@ -38,7 +38,7 @@
- if @branches.any?
%ul.content-list.all-branches
- @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'
- else
.nothing-here-block
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 16ae99b5c6c..acfd4a1ef4d 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -242,7 +242,11 @@ module API
end
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
expose :protected do |repo_branch, options|
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index dcca20c75ef..ff408c0c4dd 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1243,11 +1243,21 @@ module Gitlab
sort_branches(branches, sort_by)
end
+ # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695
def git_merged_branch_names(branch_names = [])
- lines = run_git(['branch', '--merged', root_ref] + branch_names)
- .first.lines
+ root_sha = find_branch(root_ref).target
- 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
def log_using_shell?(options)
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index f0da77c61bb..725e851aa9d 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1211,12 +1211,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
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
expect(names).to include('merge-test')
expect(names).to include('fix-mode')
expect(names).not_to include('feature')
+ expect(names).not_to include('identical')
end
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index e9e6abb0d5f..27f0a99b2fa 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -299,24 +299,6 @@ describe Repository do
it { is_expected.to be_falsey }
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
describe '#can_be_merged?' do