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
8e3f2ecf
Commit
8e3f2ecf
authored
Jul 22, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate RefsService.FindAllBranches Gitaly RPC
parent
8065adcc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
7 deletions
+40
-7
lib/gitlab/git.rb
lib/gitlab/git.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+8
-4
lib/gitlab/gitaly_client/ref_service.rb
lib/gitlab/gitaly_client/ref_service.rb
+13
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+7
-2
spec/lib/gitlab/gitaly_client/ref_service_spec.rb
spec/lib/gitlab/gitaly_client/ref_service_spec.rb
+11
-0
No files found.
lib/gitlab/git.rb
View file @
8e3f2ecf
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
include
Gitlab
::
EncodingHelper
include
Gitlab
::
EncodingHelper
def
ref_name
(
ref
)
def
ref_name
(
ref
)
encode!
ref
.
sub
(
/\Arefs\/(tags|heads)\//
,
''
)
encode!
ref
.
sub
(
/\Arefs\/(tags|heads
|remotes
)\//
,
''
)
end
end
def
branch_name
(
ref
)
def
branch_name
(
ref
)
...
...
lib/gitlab/git/repository.rb
View file @
8e3f2ecf
...
@@ -82,10 +82,14 @@ module Gitlab
...
@@ -82,10 +82,14 @@ module Gitlab
end
end
# Returns an Array of Branches
# Returns an Array of Branches
#
def
branches
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/389
gitaly_migrate
(
:branches
)
do
|
is_enabled
|
def
branches
(
sort_by:
nil
)
if
is_enabled
branches_filter
(
sort_by:
sort_by
)
gitaly_ref_client
.
branches
else
branches_filter
end
end
end
end
def
reload_rugged
def
reload_rugged
...
...
lib/gitlab/gitaly_client/ref_service.rb
View file @
8e3f2ecf
...
@@ -10,6 +10,19 @@ module Gitlab
...
@@ -10,6 +10,19 @@ module Gitlab
@storage
=
repository
.
storage
@storage
=
repository
.
storage
end
end
def
branches
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
|
gitaly_commit
=
GitalyClient
::
Commit
.
new
(
@repository
,
branch
.
target
)
target_commit
=
Gitlab
::
Git
::
Commit
.
decorate
(
gitaly_commit
)
Gitlab
::
Git
::
Branch
.
new
(
@repository
,
branch
.
name
,
branch
.
target
.
id
,
target_commit
)
end
end
end
def
default_branch_name
def
default_branch_name
request
=
Gitaly
::
FindDefaultBranchNameRequest
.
new
(
repository:
@gitaly_repo
)
request
=
Gitaly
::
FindDefaultBranchNameRequest
.
new
(
repository:
@gitaly_repo
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:find_default_branch_name
,
request
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:find_default_branch_name
,
request
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
8e3f2ecf
...
@@ -939,16 +939,21 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -939,16 +939,21 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
'with deleted branch with Gitaly disabled'
do
context
'with deleted branch with Gitaly disabled'
do
before
do
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
and_return
(
false
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
and_return
(
false
)
end
it
'returns no results'
do
ref
=
double
()
ref
=
double
()
allow
(
ref
).
to
receive
(
:name
)
{
'bad-branch'
}
allow
(
ref
).
to
receive
(
:name
)
{
'bad-branch'
}
allow
(
ref
).
to
receive
(
:target
)
{
raise
Rugged
::
ReferenceError
}
allow
(
ref
).
to
receive
(
:target
)
{
raise
Rugged
::
ReferenceError
}
branches
=
double
()
branches
=
double
()
allow
(
branches
).
to
receive
(
:each
)
{
[
ref
].
each
}
allow
(
branches
).
to
receive
(
:each
)
{
[
ref
].
each
}
allow
(
repository
.
rugged
).
to
receive
(
:branches
)
{
branches
}
allow
(
repository
.
rugged
).
to
receive
(
:branches
)
{
branches
}
end
it
{
is_expected
.
to
eq
([])
}
expect
(
subject
).
to
be_empty
end
end
end
it_behaves_like
'wrapping gRPC errors'
,
Gitlab
::
GitalyClient
::
RefService
,
:branches
end
end
describe
'#branch_count'
do
describe
'#branch_count'
do
...
...
spec/lib/gitlab/gitaly_client/ref_service_spec.rb
View file @
8e3f2ecf
...
@@ -6,6 +6,17 @@ describe Gitlab::GitalyClient::RefService do
...
@@ -6,6 +6,17 @@ describe Gitlab::GitalyClient::RefService do
let
(
:relative_path
)
{
project
.
path_with_namespace
+
'.git'
}
let
(
:relative_path
)
{
project
.
path_with_namespace
+
'.git'
}
let
(
:client
)
{
described_class
.
new
(
project
.
repository
)
}
let
(
:client
)
{
described_class
.
new
(
project
.
repository
)
}
describe
'#branches'
do
it
'sends a find_all_branches message'
do
expect_any_instance_of
(
Gitaly
::
RefService
::
Stub
)
.
to
receive
(
:find_all_branches
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
([])
client
.
branches
end
end
describe
'#branch_names'
do
describe
'#branch_names'
do
it
'sends a find_all_branch_names message'
do
it
'sends a find_all_branch_names message'
do
expect_any_instance_of
(
Gitaly
::
RefService
::
Stub
)
expect_any_instance_of
(
Gitaly
::
RefService
::
Stub
)
...
...
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