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
f32f04a5
Commit
f32f04a5
authored
Jan 15, 2018
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Commit#uri_type to Gitaly
Closes gitaly#915
parent
74f2f9b3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
18 deletions
+55
-18
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
app/models/commit.rb
app/models/commit.rb
+4
-4
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+32
-5
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+1
-1
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+17
-7
No files found.
GITALY_SERVER_VERSION
View file @
f32f04a5
0.6
7
.0
0.6
9
.0
app/models/commit.rb
View file @
f32f04a5
...
@@ -372,19 +372,19 @@ class Commit
...
@@ -372,19 +372,19 @@ class Commit
# uri_type('doc/README.md') # => :blob
# uri_type('doc/README.md') # => :blob
# uri_type('doc/logo.png') # => :raw
# uri_type('doc/logo.png') # => :raw
# uri_type('doc/api') # => :tree
# uri_type('doc/api') # => :tree
# uri_type('not/found') # =>
:
nil
# uri_type('not/found') # => nil
#
#
# Returns a symbol
# Returns a symbol
def
uri_type
(
path
)
def
uri_type
(
path
)
entry
=
@raw
.
rugged_tree_entry
(
path
)
entry
=
@raw
.
tree_entry
(
path
)
return
unless
entry
if
entry
[
:type
]
==
:blob
if
entry
[
:type
]
==
:blob
blob
=
::
Blob
.
decorate
(
Gitlab
::
Git
::
Blob
.
new
(
name:
entry
[
:name
]),
@project
)
blob
=
::
Blob
.
decorate
(
Gitlab
::
Git
::
Blob
.
new
(
name:
entry
[
:name
]),
@project
)
blob
.
image?
||
blob
.
video?
?
:raw
:
:blob
blob
.
image?
||
blob
.
video?
?
:raw
:
:blob
else
else
entry
[
:type
]
entry
[
:type
]
end
end
rescue
Rugged
::
TreeError
nil
end
end
def
raw_diffs
(
*
args
)
def
raw_diffs
(
*
args
)
...
...
lib/gitlab/git/commit.rb
View file @
f32f04a5
...
@@ -436,6 +436,16 @@ module Gitlab
...
@@ -436,6 +436,16 @@ module Gitlab
parent_ids
.
size
>
1
parent_ids
.
size
>
1
end
end
def
tree_entry
(
path
)
@repository
.
gitaly_migrate
(
:commit_tree_entry
)
do
|
is_migrated
|
if
is_migrated
gitaly_tree_entry
(
path
)
else
rugged_tree_entry
(
path
)
end
end
end
def
to_gitaly_commit
def
to_gitaly_commit
return
raw_commit
if
raw_commit
.
is_a?
(
Gitaly
::
GitCommit
)
return
raw_commit
if
raw_commit
.
is_a?
(
Gitaly
::
GitCommit
)
...
@@ -450,11 +460,6 @@ module Gitlab
...
@@ -450,11 +460,6 @@ module Gitlab
)
)
end
end
# Is this the same as Blob.find_entry_by_path ?
def
rugged_tree_entry
(
path
)
rugged_commit
.
tree
.
path
(
path
)
end
private
private
def
init_from_hash
(
hash
)
def
init_from_hash
(
hash
)
...
@@ -501,6 +506,28 @@ module Gitlab
...
@@ -501,6 +506,28 @@ module Gitlab
SERIALIZE_KEYS
SERIALIZE_KEYS
end
end
def
gitaly_tree_entry
(
path
)
# We're only interested in metadata, so limit actual data to 1 byte
# since Gitaly doesn't support "send no data" option.
entry
=
@repository
.
gitaly_commit_client
.
tree_entry
(
id
,
path
,
1
)
return
unless
entry
# To be compatible with the rugged format
entry
=
entry
.
to_h
entry
.
delete
(
:data
)
entry
[
:name
]
=
File
.
basename
(
path
)
entry
[
:type
]
=
entry
[
:type
].
downcase
entry
end
# Is this the same as Blob.find_entry_by_path ?
def
rugged_tree_entry
(
path
)
rugged_commit
.
tree
.
path
(
path
)
rescue
Rugged
::
TreeError
nil
end
def
gitaly_commit_author_from_rugged
(
author_or_committer
)
def
gitaly_commit_author_from_rugged
(
author_or_committer
)
Gitaly
::
CommitAuthor
.
new
(
Gitaly
::
CommitAuthor
.
new
(
name:
author_or_committer
[
:name
].
b
,
name:
author_or_committer
[
:name
].
b
,
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
f32f04a5
...
@@ -177,7 +177,7 @@ module Gitlab
...
@@ -177,7 +177,7 @@ module Gitlab
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:list_commits_by_oid
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:list_commits_by_oid
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
consume_commits_response
(
response
)
consume_commits_response
(
response
)
rescue
GRPC
::
Unknown
# If no repository is found, happens mainly during testing
rescue
GRPC
::
NotFound
# If no repository is found, happens mainly during testing
[]
[]
end
end
...
...
spec/models/commit_spec.rb
View file @
f32f04a5
...
@@ -439,6 +439,7 @@ eos
...
@@ -439,6 +439,7 @@ eos
end
end
describe
'#uri_type'
do
describe
'#uri_type'
do
shared_examples
'URI type'
do
it
'returns the URI type at the given path'
do
it
'returns the URI type at the given path'
do
expect
(
commit
.
uri_type
(
'files/html'
)).
to
be
(
:tree
)
expect
(
commit
.
uri_type
(
'files/html'
)).
to
be
(
:tree
)
expect
(
commit
.
uri_type
(
'files/images/logo-black.png'
)).
to
be
(
:raw
)
expect
(
commit
.
uri_type
(
'files/images/logo-black.png'
)).
to
be
(
:raw
)
...
@@ -451,6 +452,15 @@ eos
...
@@ -451,6 +452,15 @@ eos
end
end
end
end
context
'when Gitaly commit_tree_entry feature is enabled'
do
it_behaves_like
'URI type'
end
context
'when Gitaly commit_tree_entry feature is disabled'
,
:disable_gitaly
do
it_behaves_like
'URI type'
end
end
describe
'.from_hash'
do
describe
'.from_hash'
do
let
(
:new_commit
)
{
described_class
.
from_hash
(
commit
.
to_hash
,
project
)
}
let
(
:new_commit
)
{
described_class
.
from_hash
(
commit
.
to_hash
,
project
)
}
...
...
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