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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
9f44687a
Commit
9f44687a
authored
Jun 28, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitaly-encodings' into 'master'
Fix gitaly ref encoding bugs Closes #34156 See merge request !12522
parents
d3c3200c
d3bcf8ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
11 deletions
+44
-11
lib/gitlab/git.rb
lib/gitlab/git.rb
+3
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+1
-3
lib/gitlab/gitaly_client/ref.rb
lib/gitlab/gitaly_client/ref.rb
+16
-7
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+24
-0
No files found.
lib/gitlab/git.rb
View file @
9f44687a
...
...
@@ -7,8 +7,10 @@ module Gitlab
CommandError
=
Class
.
new
(
StandardError
)
class
<<
self
include
Gitlab
::
EncodingHelper
def
ref_name
(
ref
)
ref
.
sub
(
/\Arefs\/(tags|heads)\//
,
''
)
encode!
ref
.
sub
(
/\Arefs\/(tags|heads)\//
,
''
)
end
def
branch_name
(
ref
)
...
...
lib/gitlab/git/repository.rb
View file @
9f44687a
...
...
@@ -113,9 +113,7 @@ module Gitlab
def
local_branches
(
sort_by:
nil
)
gitaly_migrate
(
:local_branches
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_client
.
local_branches
(
sort_by:
sort_by
).
map
do
|
gitaly_branch
|
Gitlab
::
Git
::
Branch
.
new
(
self
,
gitaly_branch
.
name
,
gitaly_branch
)
end
gitaly_ref_client
.
local_branches
(
sort_by:
sort_by
)
else
branches
(
filter: :local
,
sort_by:
sort_by
)
end
...
...
lib/gitlab/gitaly_client/ref.rb
View file @
9f44687a
module
Gitlab
module
GitalyClient
class
Ref
include
Gitlab
::
EncodingHelper
# 'repository' is a Gitlab::Git::Repository
def
initialize
(
repository
)
@repository
=
repository
@gitaly_repo
=
repository
.
gitaly_repository
@storage
=
repository
.
storage
end
...
...
@@ -16,13 +19,13 @@ module Gitlab
def
branch_names
request
=
Gitaly
::
FindAllBranchNamesRequest
.
new
(
repository:
@gitaly_repo
)
response
=
GitalyClient
.
call
(
@storage
,
:ref
,
:find_all_branch_names
,
request
)
consume_refs_response
(
response
,
prefix:
'refs/heads/'
)
consume_refs_response
(
response
)
{
|
name
|
Gitlab
::
Git
.
branch_name
(
name
)
}
end
def
tag_names
request
=
Gitaly
::
FindAllTagNamesRequest
.
new
(
repository:
@gitaly_repo
)
response
=
GitalyClient
.
call
(
@storage
,
:ref
,
:find_all_tag_names
,
request
)
consume_refs_response
(
response
,
prefix:
'refs/tags/'
)
consume_refs_response
(
response
)
{
|
name
|
Gitlab
::
Git
.
tag_name
(
name
)
}
end
def
find_ref_name
(
commit_id
,
ref_prefix
)
...
...
@@ -51,10 +54,8 @@ module Gitlab
private
def
consume_refs_response
(
response
,
prefix
:)
response
.
flat_map
do
|
r
|
r
.
names
.
map
{
|
name
|
name
.
sub
(
/\A
#{
Regexp
.
escape
(
prefix
)
}
/
,
''
)
}
end
def
consume_refs_response
(
response
)
response
.
flat_map
{
|
message
|
message
.
names
.
map
{
|
name
|
yield
(
name
)
}
}
end
def
sort_by_param
(
sort_by
)
...
...
@@ -64,7 +65,15 @@ module Gitlab
end
def
consume_branches_response
(
response
)
response
.
flat_map
{
|
r
|
r
.
branches
}
response
.
flat_map
do
|
message
|
message
.
branches
.
map
do
|
gitaly_branch
|
Gitlab
::
Git
::
Branch
.
new
(
@repository
,
encode!
(
gitaly_branch
.
name
.
dup
),
gitaly_branch
.
commit_id
)
end
end
end
end
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
9f44687a
...
...
@@ -26,6 +26,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
it
'returns UTF-8'
do
expect
(
repository
.
root_ref
.
encoding
).
to
eq
(
Encoding
.
find
(
'UTF-8'
))
end
context
'with gitaly enabled'
do
before
do
stub_gitaly
...
...
@@ -123,6 +127,11 @@ describe Gitlab::Git::Repository, seed_helper: true do
it
'has SeedRepo::Repo::BRANCHES.size elements'
do
expect
(
subject
.
size
).
to
eq
(
SeedRepo
::
Repo
::
BRANCHES
.
size
)
end
it
'returns UTF-8'
do
expect
(
subject
.
first
.
encoding
).
to
eq
(
Encoding
.
find
(
'UTF-8'
))
end
it
{
is_expected
.
to
include
(
"master"
)
}
it
{
is_expected
.
not_to
include
(
"branch-from-space"
)
}
...
...
@@ -158,10 +167,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
subject
{
repository
.
tag_names
}
it
{
is_expected
.
to
be_kind_of
Array
}
it
'has SeedRepo::Repo::TAGS.size elements'
do
expect
(
subject
.
size
).
to
eq
(
SeedRepo
::
Repo
::
TAGS
.
size
)
end
it
'returns UTF-8'
do
expect
(
subject
.
first
.
encoding
).
to
eq
(
Encoding
.
find
(
'UTF-8'
))
end
describe
'#last'
do
subject
{
super
().
last
}
it
{
is_expected
.
to
eq
(
"v1.2.1"
)
}
...
...
@@ -1276,6 +1290,16 @@ describe Gitlab::Git::Repository, seed_helper: true do
Gitlab
::
GitalyClient
.
clear_stubs!
end
it
'returns a Branch with UTF-8 fields'
do
branches
=
@repo
.
local_branches
.
to_a
expect
(
branches
.
size
).
to
be
>
0
utf_8
=
Encoding
.
find
(
'utf-8'
)
branches
.
each
do
|
branch
|
expect
(
branch
.
name
.
encoding
).
to
eq
(
utf_8
)
expect
(
branch
.
target
.
encoding
).
to
eq
(
utf_8
)
unless
branch
.
target
.
nil?
end
end
it
'gets the branches from GitalyClient'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Ref
).
to
receive
(
:local_branches
)
.
and_return
([])
...
...
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