BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9eb5cdd7
Commit
9eb5cdd7
authored
Jul 18, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate CommitService.GetTreeEntries Gitaly call
parent
7f78a78a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
33 deletions
+108
-33
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
tree.rb
lib/gitlab/git/tree.rb
+35
-24
commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+25
-0
tree_spec.rb
spec/lib/gitlab/git/tree_spec.rb
+22
-1
commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+25
-7
No files found.
GITALY_SERVER_VERSION
View file @
9eb5cdd7
0.2
2
.0
0.2
3
.0
lib/gitlab/git/tree.rb
View file @
9eb5cdd7
...
...
@@ -17,30 +17,13 @@ module Gitlab
def
where
(
repository
,
sha
,
path
=
nil
)
path
=
nil
if
path
==
''
||
path
==
'/'
commit
=
repository
.
lookup
(
sha
)
root_tree
=
commit
.
tree
tree
=
if
path
id
=
find_id_by_path
(
repository
,
root_tree
.
oid
,
path
)
if
id
repository
.
lookup
(
id
)
else
[]
end
else
root_tree
end
tree
.
map
do
|
entry
|
new
(
id:
entry
[
:oid
],
root_id:
root_tree
.
oid
,
name:
entry
[
:name
],
type:
entry
[
:type
],
mode:
entry
[
:filemode
].
to_s
(
8
),
path:
path
?
File
.
join
(
path
,
entry
[:
name
])
:
entry
[
:name
],
commit_id:
sha
)
Gitlab
::
GitalyClient
.
migrate
(
:tree_entries
)
do
|
is_enabled
|
if
is_enabled
client
=
Gitlab
::
GitalyClient
::
CommitService
.
new
(
repository
)
client
.
tree_entries
(
repository
,
sha
,
path
)
else
tree_entries_from_rugged
(
repository
,
sha
,
path
)
end
end
end
...
...
@@ -74,6 +57,34 @@ module Gitlab
entry
[
:oid
]
end
end
def
tree_entries_from_rugged
(
repository
,
sha
,
path
)
commit
=
repository
.
lookup
(
sha
)
root_tree
=
commit
.
tree
tree
=
if
path
id
=
find_id_by_path
(
repository
,
root_tree
.
oid
,
path
)
if
id
repository
.
lookup
(
id
)
else
[]
end
else
root_tree
end
tree
.
map
do
|
entry
|
new
(
id:
entry
[
:oid
],
root_id:
root_tree
.
oid
,
name:
entry
[
:name
],
type:
entry
[
:type
],
mode:
entry
[
:filemode
].
to_s
(
8
),
path:
path
?
File
.
join
(
path
,
entry
[:
name
])
:
entry
[
:name
],
commit_id:
sha
)
end
end
end
def
initialize
(
options
)
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
9eb5cdd7
...
...
@@ -60,6 +60,31 @@ module Gitlab
entry
end
def
tree_entries
(
repository
,
revision
,
path
)
request
=
Gitaly
::
GetTreeEntriesRequest
.
new
(
repository:
@gitaly_repo
,
revision:
revision
,
path:
path
.
presence
||
'.'
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:get_tree_entries
,
request
)
response
.
flat_map
do
|
message
|
message
.
entries
.
map
do
|
gitaly_tree_entry
|
entry_path
=
gitaly_tree_entry
.
path
.
dup
Gitlab
::
Git
::
Tree
.
new
(
id:
gitaly_tree_entry
.
oid
,
root_id:
gitaly_tree_entry
.
root_oid
,
type:
gitaly_tree_entry
.
type
.
downcase
,
mode:
gitaly_tree_entry
.
mode
.
to_s
(
8
),
name:
File
.
basename
(
entry_path
),
path:
entry_path
,
commit_id:
gitaly_tree_entry
.
commit_oid
)
end
end
end
def
commit_count
(
ref
)
request
=
Gitaly
::
CountCommitsRequest
.
new
(
repository:
@gitaly_repo
,
...
...
spec/lib/gitlab/git/tree_spec.rb
View file @
9eb5cdd7
require
"spec_helper"
describe
Gitlab
::
Git
::
Tree
,
seed_helper:
true
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
)
}
context
:repo
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
)
}
let
(
:tree
)
{
Gitlab
::
Git
::
Tree
.
where
(
repository
,
SeedRepo
::
Commit
::
ID
)
}
it
{
expect
(
tree
).
to
be_kind_of
Array
}
...
...
@@ -74,4 +75,24 @@ describe Gitlab::Git::Tree, seed_helper: true do
it
{
expect
(
submodule
.
name
).
to
eq
(
'gitlab-shell'
)
}
end
end
describe
'#where'
do
context
'with gitaly disabled'
do
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
and_return
(
false
)
end
it
'calls #tree_entries_from_rugged'
do
expect
(
described_class
).
to
receive
(
:tree_entries_from_rugged
)
described_class
.
where
(
repository
,
SeedRepo
::
Commit
::
ID
,
'/'
)
end
end
it
'gets the tree entries from GitalyClient'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
CommitService
).
to
receive
(
:tree_entries
)
described_class
.
where
(
repository
,
SeedRepo
::
Commit
::
ID
,
'/'
)
end
end
end
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
9eb5cdd7
...
...
@@ -2,9 +2,13 @@ require 'spec_helper'
describe
Gitlab
::
GitalyClient
::
CommitService
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:storage_name
)
{
project
.
repository_storage
}
let
(
:relative_path
)
{
project
.
path_with_namespace
+
'.git'
}
let
(
:repository
)
{
project
.
repository
}
let
(
:repository_message
)
{
repository
.
gitaly_repository
}
let
(
:commit
)
{
project
.
commit
(
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
)
}
let
(
:revision
)
{
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
}
let
(
:commit
)
{
project
.
commit
(
revision
)
}
let
(
:client
)
{
described_class
.
new
(
repository
)
}
describe
'#diff_from_parent'
do
context
'when a commit has a parent'
do
...
...
@@ -20,7 +24,7 @@ describe Gitlab::GitalyClient::CommitService do
expect_any_instance_of
(
Gitaly
::
DiffService
::
Stub
).
to
receive
(
:commit_diff
).
with
(
request
,
kind_of
(
Hash
))
described_class
.
new
(
repository
)
.
diff_from_parent
(
commit
)
client
.
diff_from_parent
(
commit
)
end
end
...
...
@@ -38,12 +42,12 @@ describe Gitlab::GitalyClient::CommitService do
expect_any_instance_of
(
Gitaly
::
DiffService
::
Stub
).
to
receive
(
:commit_diff
).
with
(
request
,
kind_of
(
Hash
))
described_class
.
new
(
repository
)
.
diff_from_parent
(
initial_commit
)
client
.
diff_from_parent
(
initial_commit
)
end
end
it
'returns a Gitlab::Git::DiffCollection'
do
ret
=
described_class
.
new
(
repository
)
.
diff_from_parent
(
commit
)
ret
=
client
.
diff_from_parent
(
commit
)
expect
(
ret
).
to
be_kind_of
(
Gitlab
::
Git
::
DiffCollection
)
end
...
...
@@ -53,7 +57,7 @@ describe Gitlab::GitalyClient::CommitService do
expect
(
Gitlab
::
Git
::
DiffCollection
).
to
receive
(
:new
).
with
(
kind_of
(
Enumerable
),
options
)
described_class
.
new
(
repository
)
.
diff_from_parent
(
commit
,
options
)
client
.
diff_from_parent
(
commit
,
options
)
end
end
...
...
@@ -68,7 +72,7 @@ describe Gitlab::GitalyClient::CommitService do
expect_any_instance_of
(
Gitaly
::
DiffService
::
Stub
).
to
receive
(
:commit_delta
).
with
(
request
,
kind_of
(
Hash
)).
and_return
([])
described_class
.
new
(
repository
)
.
commit_deltas
(
commit
)
client
.
commit_deltas
(
commit
)
end
end
...
...
@@ -83,7 +87,7 @@ describe Gitlab::GitalyClient::CommitService do
expect_any_instance_of
(
Gitaly
::
DiffService
::
Stub
).
to
receive
(
:commit_delta
).
with
(
request
,
kind_of
(
Hash
)).
and_return
([])
described_class
.
new
(
repository
)
.
commit_deltas
(
initial_commit
)
client
.
commit_deltas
(
initial_commit
)
end
end
end
...
...
@@ -91,6 +95,7 @@ describe Gitlab::GitalyClient::CommitService do
describe
'#between'
do
let
(
:from
)
{
'master'
}
let
(
:to
)
{
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'
}
it
'sends an RPC request'
do
request
=
Gitaly
::
CommitsBetweenRequest
.
new
(
repository:
repository_message
,
from:
from
,
to:
to
...
...
@@ -102,4 +107,17 @@ describe Gitlab::GitalyClient::CommitService do
described_class
.
new
(
repository
).
between
(
from
,
to
)
end
end
describe
'#tree_entries'
do
let
(
:path
)
{
'/'
}
it
'sends a get_tree_entries message'
do
expect_any_instance_of
(
Gitaly
::
CommitService
::
Stub
)
.
to
receive
(
:get_tree_entries
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
([])
client
.
tree_entries
(
repository
,
revision
,
path
)
end
end
end
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