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
713c7fa9
Commit
713c7fa9
authored
May 02, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client implementation GetRawChanges
Part of
https://gitlab.com/gitlab-org/gitaly/issues/1138
parent
40655a48
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
34 deletions
+80
-34
lib/gitlab/git/raw_diff_change.rb
lib/gitlab/git/raw_diff_change.rb
+9
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+19
-8
lib/gitlab/gitaly_client/repository_service.rb
lib/gitlab/gitaly_client/repository_service.rb
+6
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+35
-25
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+11
-0
No files found.
lib/gitlab/git/raw_diff_change.rb
View file @
713c7fa9
...
@@ -6,7 +6,15 @@ module Gitlab
...
@@ -6,7 +6,15 @@ module Gitlab
attr_reader
:blob_id
,
:blob_size
,
:old_path
,
:new_path
,
:operation
attr_reader
:blob_id
,
:blob_size
,
:old_path
,
:new_path
,
:operation
def
initialize
(
raw_change
)
def
initialize
(
raw_change
)
parse
(
raw_change
)
if
raw_change
.
is_a?
(
Gitaly
::
GetRawChangesResponse
::
RawChange
)
@blob_id
=
raw_change
.
blob_id
@blob_size
=
raw_change
.
size
@old_path
=
raw_change
.
old_path
.
presence
@new_path
=
raw_change
.
new_path
.
presence
@operation
=
raw_change
.
operation
&
.
downcase
||
:unknown
else
parse
(
raw_change
)
end
end
end
private
private
...
...
lib/gitlab/git/repository.rb
View file @
713c7fa9
...
@@ -581,19 +581,30 @@ module Gitlab
...
@@ -581,19 +581,30 @@ module Gitlab
# old_rev and new_rev are commit ID's
# old_rev and new_rev are commit ID's
# the result of this method is an array of Gitlab::Git::RawDiffChange
# the result of this method is an array of Gitlab::Git::RawDiffChange
def
raw_changes_between
(
old_rev
,
new_rev
)
def
raw_changes_between
(
old_rev
,
new_rev
)
result
=
[]
gitaly_migrate
(
:raw_changes_between
)
do
|
is_enabled
|
if
is_enabled
gitaly_repository_client
.
raw_changes_between
(
old_rev
,
new_rev
)
.
each_with_object
([])
do
|
msg
,
arr
|
msg
.
raw_changes
.
each
{
|
change
|
arr
<<
::
Gitlab
::
Git
::
RawDiffChange
.
new
(
change
)
}
end
else
result
=
[]
circuit_breaker
.
perform
do
circuit_breaker
.
perform
do
Open3
.
pipeline_r
(
git_diff_cmd
(
old_rev
,
new_rev
),
format_git_cat_file_script
,
git_cat_file_cmd
)
do
|
last_stdout
,
wait_threads
|
Open3
.
pipeline_r
(
git_diff_cmd
(
old_rev
,
new_rev
),
format_git_cat_file_script
,
git_cat_file_cmd
)
do
|
last_stdout
,
wait_threads
|
last_stdout
.
each_line
{
|
line
|
result
<<
::
Gitlab
::
Git
::
RawDiffChange
.
new
(
line
.
chomp!
)
}
last_stdout
.
each_line
{
|
line
|
result
<<
::
Gitlab
::
Git
::
RawDiffChange
.
new
(
line
.
chomp!
)
}
if
wait_threads
.
any?
{
|
waiter
|
!
waiter
.
value
&
.
success?
}
if
wait_threads
.
any?
{
|
waiter
|
!
waiter
.
value
&
.
success?
}
raise
::
Gitlab
::
Git
::
Repository
::
GitError
,
"Unabled to obtain changes between
#{
old_rev
}
and
#{
new_rev
}
"
raise
::
Gitlab
::
Git
::
Repository
::
GitError
,
"Unabled to obtain changes between
#{
old_rev
}
and
#{
new_rev
}
"
end
end
end
end
result
end
end
end
end
rescue
ArgumentError
=>
e
r
esult
r
aise
Gitlab
::
Git
::
Repository
::
GitError
.
new
(
e
)
end
end
# Returns the SHA of the most recent common ancestor of +from+ and +to+
# Returns the SHA of the most recent common ancestor of +from+ and +to+
...
...
lib/gitlab/gitaly_client/repository_service.rb
View file @
713c7fa9
...
@@ -293,6 +293,12 @@ module Gitlab
...
@@ -293,6 +293,12 @@ module Gitlab
response
=
GitalyClient
.
call
(
@storage
,
:repository_service
,
:calculate_checksum
,
request
)
response
=
GitalyClient
.
call
(
@storage
,
:repository_service
,
:calculate_checksum
,
request
)
response
.
checksum
.
presence
response
.
checksum
.
presence
end
end
def
raw_changes_between
(
from
,
to
)
request
=
Gitaly
::
GetRawChangesRequest
.
new
(
repository:
@gitaly_repo
,
from_revision:
from
,
to_revision:
to
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:get_raw_changes
,
request
)
end
end
end
end
end
end
end
spec/lib/gitlab/git/repository_spec.rb
View file @
713c7fa9
...
@@ -1068,41 +1068,51 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1068,41 +1068,51 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#raw_changes_between'
do
describe
'#raw_changes_between'
do
let
(
:old_rev
)
{
}
shared_examples
'raw changes'
do
let
(
:new_rev
)
{
}
let
(
:old_rev
)
{
}
let
(
:changes
)
{
repository
.
raw_changes_between
(
old_rev
,
new_rev
)
}
let
(
:new_rev
)
{
}
let
(
:changes
)
{
repository
.
raw_changes_between
(
old_rev
,
new_rev
)
}
context
'initial commit'
do
context
'initial commit'
do
let
(
:old_rev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
let
(
:old_rev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
let
(
:new_rev
)
{
'1a0b36b3cdad1d2ee32457c102a8c0b7056fa863'
}
let
(
:new_rev
)
{
'1a0b36b3cdad1d2ee32457c102a8c0b7056fa863'
}
it
'returns the changes'
do
it
'returns the changes'
do
expect
(
changes
).
to
be_present
expect
(
changes
).
to
be_present
expect
(
changes
.
size
).
to
eq
(
3
)
expect
(
changes
.
size
).
to
eq
(
3
)
end
end
end
end
context
'with an invalid rev'
do
context
'with an invalid rev'
do
let
(
:old_rev
)
{
'foo'
}
let
(
:old_rev
)
{
'foo'
}
let
(
:new_rev
)
{
'bar'
}
let
(
:new_rev
)
{
'bar'
}
it
'returns an error'
do
it
'returns an error'
do
expect
{
changes
}.
to
raise_error
(
Gitlab
::
Git
::
Repository
::
GitError
)
expect
{
changes
}.
to
raise_error
(
Gitlab
::
Git
::
Repository
::
GitError
)
end
end
end
end
context
'with valid revs'
do
context
'with valid revs'
do
let
(
:old_rev
)
{
'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6'
}
let
(
:old_rev
)
{
'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6'
}
let
(
:new_rev
)
{
'4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6'
}
let
(
:new_rev
)
{
'4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6'
}
it
'returns the changes'
do
it
'returns the changes'
do
expect
(
changes
.
size
).
to
eq
(
9
)
expect
(
changes
.
size
).
to
eq
(
9
)
expect
(
changes
.
first
.
operation
).
to
eq
(
:modified
)
expect
(
changes
.
first
.
operation
).
to
eq
(
:modified
)
expect
(
changes
.
first
.
new_path
).
to
eq
(
'.gitmodules'
)
expect
(
changes
.
first
.
new_path
).
to
eq
(
'.gitmodules'
)
expect
(
changes
.
last
.
operation
).
to
eq
(
:added
)
expect
(
changes
.
last
.
operation
).
to
eq
(
:added
)
expect
(
changes
.
last
.
new_path
).
to
eq
(
'files/lfs/picture-invalid.png'
)
expect
(
changes
.
last
.
new_path
).
to
eq
(
'files/lfs/picture-invalid.png'
)
end
end
end
end
end
context
'when gitaly is enabled'
do
it_behaves_like
'raw changes'
end
context
'when gitaly is disabled'
,
:disable_gitaly
do
it_behaves_like
'raw changes'
end
end
end
describe
'#merge_base'
do
describe
'#merge_base'
do
...
...
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
View file @
713c7fa9
...
@@ -167,4 +167,15 @@ describe Gitlab::GitalyClient::RepositoryService do
...
@@ -167,4 +167,15 @@ describe Gitlab::GitalyClient::RepositoryService do
client
.
create_from_snapshot
(
'http://example.com?wiki=1'
,
'Custom xyz'
)
client
.
create_from_snapshot
(
'http://example.com?wiki=1'
,
'Custom xyz'
)
end
end
end
end
describe
'#raw_changes_between'
do
it
'sends a create_repository_from_snapshot message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:get_raw_changes
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
)
client
.
raw_changes_between
(
'deadbeef'
,
'deadpork'
)
end
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