Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
83101941
Commit
83101941
authored
Dec 28, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate merged_branch_names to Gitaly
Closes gitaly#851
parent
be623ef3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
45 deletions
+85
-45
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+24
-9
lib/gitlab/gitaly_client/ref_service.rb
lib/gitlab/gitaly_client/ref_service.rb
+23
-8
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+38
-28
No files found.
lib/gitlab/git/repository.rb
View file @
83101941
...
...
@@ -571,7 +571,21 @@ module Gitlab
end
def
merged_branch_names
(
branch_names
=
[])
Set
.
new
(
git_merged_branch_names
(
branch_names
))
return
[]
unless
root_ref
root_sha
=
find_branch
(
root_ref
)
&
.
target
return
[]
unless
root_sha
branches
=
gitaly_migrate
(
:merged_branch_names
)
do
|
is_enabled
|
if
is_enabled
gitaly_merged_branch_names
(
branch_names
,
root_sha
)
else
git_merged_branch_names
(
branch_names
,
root_sha
)
end
end
Set
.
new
(
branches
)
end
# Return an array of Diff objects that represent the diff
...
...
@@ -1475,14 +1489,7 @@ 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
=
[])
return
[]
unless
root_ref
root_sha
=
find_branch
(
root_ref
)
&
.
target
return
[]
unless
root_sha
def
git_merged_branch_names
(
branch_names
,
root_sha
)
git_arguments
=
%W[branch --merged
#{
root_sha
}
--format=%(refname:short)
\
%(objectname)]
+
branch_names
...
...
@@ -1496,6 +1503,14 @@ module Gitlab
end
end
def
gitaly_merged_branch_names
(
branch_names
,
root_sha
)
qualified_branch_names
=
branch_names
.
map
{
|
b
|
"refs/heads/
#{
b
}
"
}
gitaly_ref_client
.
merged_branches
(
qualified_branch_names
)
.
reject
{
|
b
|
b
.
target
==
root_sha
}
.
map
(
&
:name
)
end
def
process_count_commits_options
(
options
)
if
options
[
:from
]
||
options
[
:to
]
ref
=
...
...
lib/gitlab/gitaly_client/ref_service.rb
View file @
83101941
...
...
@@ -14,12 +14,18 @@ module Gitlab
request
=
Gitaly
::
FindAllBranchesRequest
.
new
(
repository:
@gitaly_repo
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:find_all_branches
,
request
)
response
.
flat_map
do
|
message
|
message
.
branches
.
map
do
|
branch
|
target_commit
=
Gitlab
::
Git
::
Commit
.
decorate
(
@repository
,
branch
.
target
)
Gitlab
::
Git
::
Branch
.
new
(
@repository
,
branch
.
name
,
branch
.
target
.
id
,
target_commit
)
end
end
consume_find_all_branches_response
(
response
)
end
def
merged_branches
(
branch_names
=
[])
request
=
Gitaly
::
FindAllBranchesRequest
.
new
(
repository:
@gitaly_repo
,
merged_only:
true
,
merged_branches:
branch_names
.
map
{
|
s
|
encode_binary
(
s
)
}
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:find_all_branches
,
request
)
consume_find_all_branches_response
(
response
)
end
def
default_branch_name
...
...
@@ -62,7 +68,7 @@ module Gitlab
request
=
Gitaly
::
FindLocalBranchesRequest
.
new
(
repository:
@gitaly_repo
)
request
.
sort_by
=
sort_by_param
(
sort_by
)
if
sort_by
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:find_local_branches
,
request
)
consume_branches_response
(
response
)
consume_
find_local_
branches_response
(
response
)
end
def
tags
...
...
@@ -151,7 +157,7 @@ module Gitlab
enum_value
end
def
consume_branches_response
(
response
)
def
consume_
find_local_
branches_response
(
response
)
response
.
flat_map
do
|
message
|
message
.
branches
.
map
do
|
gitaly_branch
|
Gitlab
::
Git
::
Branch
.
new
(
...
...
@@ -164,6 +170,15 @@ module Gitlab
end
end
def
consume_find_all_branches_response
(
response
)
response
.
flat_map
do
|
message
|
message
.
branches
.
map
do
|
branch
|
target_commit
=
Gitlab
::
Git
::
Commit
.
decorate
(
@repository
,
branch
.
target
)
Gitlab
::
Git
::
Branch
.
new
(
@repository
,
branch
.
name
,
branch
.
target
.
id
,
target_commit
)
end
end
end
def
consume_tags_response
(
response
)
response
.
flat_map
do
|
message
|
message
.
tags
.
map
{
|
gitaly_tag
|
Util
.
gitlab_tag_from_gitaly_tag
(
@repository
,
gitaly_tag
)
}
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
83101941
...
...
@@ -1283,48 +1283,58 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe
'#merged_branch_names'
do
context
'when branch names are passed'
do
it
'only returns the names we are asking'
do
names
=
repository
.
merged_branch_names
(
%w[merge-test]
)
shared_examples
'finding merged branch names'
do
context
'when branch names are passed'
do
it
'only returns the names we are asking'
do
names
=
repository
.
merged_branch_names
(
%w[merge-test]
)
expect
(
names
).
to
contain_exactly
(
'merge-test'
)
end
expect
(
names
).
to
contain_exactly
(
'merge-test'
)
end
it
'does not return unmerged branch names'
do
names
=
repository
.
merged_branch_names
(
%w[feature]
)
it
'does not return unmerged branch names'
do
names
=
repository
.
merged_branch_names
(
%w[feature]
)
expect
(
names
).
to
be_empty
expect
(
names
).
to
be_empty
end
end
end
context
'when no root ref is available'
do
it
'returns empty list'
do
project
=
create
(
:project
,
:empty_repo
)
context
'when no root ref is available'
do
it
'returns empty list'
do
project
=
create
(
:project
,
:empty_repo
)
names
=
project
.
repository
.
merged_branch_names
(
%w[feature]
)
names
=
project
.
repository
.
merged_branch_names
(
%w[feature]
)
expect
(
names
).
to
be_empty
expect
(
names
).
to
be_empty
end
end
end
context
'when no branch names are specified'
do
before
do
repository
.
create_branch
(
'identical'
,
'master'
)
end
context
'when no branch names are specified'
do
before
do
repository
.
create_branch
(
'identical'
,
'master'
)
end
after
do
ensure_seeds
end
after
do
ensure_seeds
end
it
'returns all merged branch names except for identical one'
do
names
=
repository
.
merged_branch_names
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'
)
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
context
'when Gitaly merged_branch_names feature is enabled'
do
it_behaves_like
'finding merged branch names'
end
context
'when Gitaly merged_branch_names feature is disabled'
,
:disable_gitaly
do
it_behaves_like
'finding merged branch names'
end
end
describe
"#ls_files"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment