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
Léo-Paul Géneau
gitlab-ce
Commits
37cc50f8
Commit
37cc50f8
authored
Oct 25, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate Gitaly's OperationService.UserFFBranch RPC
parent
74a0e855
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
30 deletions
+115
-30
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+24
-8
lib/gitlab/gitaly_client/operation_service.rb
lib/gitlab/gitaly_client/operation_service.rb
+17
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+39
-21
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
+34
-0
No files found.
lib/gitlab/git/commit.rb
View file @
37cc50f8
...
@@ -73,7 +73,7 @@ module Gitlab
...
@@ -73,7 +73,7 @@ module Gitlab
decorate
(
repo
,
commit
)
if
commit
decorate
(
repo
,
commit
)
if
commit
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
Gitlab
::
Git
::
CommandError
,
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Git
::
CommandError
,
Gitlab
::
Git
::
Repository
::
NoRepository
,
Rugged
::
OdbError
,
Rugged
::
TreeError
Rugged
::
OdbError
,
Rugged
::
TreeError
,
ArgumentError
nil
nil
end
end
...
...
lib/gitlab/git/repository.rb
View file @
37cc50f8
...
@@ -750,13 +750,13 @@ module Gitlab
...
@@ -750,13 +750,13 @@ module Gitlab
end
end
def
ff_merge
(
user
,
source_sha
,
target_branch
)
def
ff_merge
(
user
,
source_sha
,
target_branch
)
OperationService
.
new
(
user
,
self
).
with_branch
(
target_branch
)
do
|
our_commit
|
gitaly_migrate
(
:operation_user_ff_branch
)
do
|
is_enabled
|
raise
ArgumentError
,
'Invalid merge target'
unless
our_commit
if
is_enabled
gitaly_ff_merge
(
user
,
source_sha
,
target_branch
)
source_sha
else
rugged_ff_merge
(
user
,
source_sha
,
target_branch
)
end
end
end
rescue
Rugged
::
ReferenceError
raise
ArgumentError
,
'Invalid merge source'
end
end
def
revert
(
user
:,
commit
:,
branch_name
:,
message
:,
start_branch_name
:,
start_repository
:)
def
revert
(
user
:,
commit
:,
branch_name
:,
message
:,
start_branch_name
:,
start_repository
:)
...
@@ -1169,10 +1169,10 @@ module Gitlab
...
@@ -1169,10 +1169,10 @@ module Gitlab
Gitlab
::
GitalyClient
.
migrate
(
method
,
status:
status
,
&
block
)
Gitlab
::
GitalyClient
.
migrate
(
method
,
status:
status
,
&
block
)
rescue
GRPC
::
NotFound
=>
e
rescue
GRPC
::
NotFound
=>
e
raise
NoRepository
.
new
(
e
)
raise
NoRepository
.
new
(
e
)
rescue
GRPC
::
BadStatus
=>
e
raise
CommandError
.
new
(
e
)
rescue
GRPC
::
InvalidArgument
=>
e
rescue
GRPC
::
InvalidArgument
=>
e
raise
ArgumentError
.
new
(
e
)
raise
ArgumentError
.
new
(
e
)
rescue
GRPC
::
BadStatus
=>
e
raise
CommandError
.
new
(
e
)
end
end
private
private
...
@@ -1614,6 +1614,22 @@ module Gitlab
...
@@ -1614,6 +1614,22 @@ module Gitlab
run_git
(
args
,
env:
env
)
run_git
(
args
,
env:
env
)
end
end
def
gitaly_ff_merge
(
user
,
source_sha
,
target_branch
)
gitaly_operations_client
.
user_ff_branch
(
user
,
source_sha
,
target_branch
)
rescue
GRPC
::
FailedPrecondition
=>
e
raise
CommitError
,
e
end
def
rugged_ff_merge
(
user
,
source_sha
,
target_branch
)
OperationService
.
new
(
user
,
self
).
with_branch
(
target_branch
)
do
|
our_commit
|
raise
ArgumentError
,
'Invalid merge target'
unless
our_commit
source_sha
end
rescue
Rugged
::
ReferenceError
raise
ArgumentError
,
'Invalid merge source'
end
end
end
end
end
end
end
lib/gitlab/gitaly_client/operation_service.rb
View file @
37cc50f8
...
@@ -105,6 +105,23 @@ module Gitlab
...
@@ -105,6 +105,23 @@ module Gitlab
ensure
ensure
request_enum
.
close
request_enum
.
close
end
end
def
user_ff_branch
(
user
,
source_sha
,
target_branch
)
request
=
Gitaly
::
UserFFBranchRequest
.
new
(
repository:
@gitaly_repo
,
user:
Gitlab
::
Git
::
User
.
from_gitlab
(
user
).
to_gitaly
,
commit_id:
source_sha
,
branch:
GitalyClient
.
encode
(
target_branch
)
)
branch_update
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_ff_branch
,
request
).
branch_update
Gitlab
::
Git
::
OperationService
::
BranchUpdate
.
from_gitaly
(
branch_update
)
end
end
end
end
end
end
end
spec/lib/gitlab/git/repository_spec.rb
View file @
37cc50f8
...
@@ -1609,6 +1609,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1609,6 +1609,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
subject
{
repository
.
ff_merge
(
user
,
source_sha
,
target_branch
)
}
subject
{
repository
.
ff_merge
(
user
,
source_sha
,
target_branch
)
}
shared_examples
'#ff_merge'
do
it
'performs a ff_merge'
do
it
'performs a ff_merge'
do
expect
(
subject
.
newrev
).
to
eq
(
source_sha
)
expect
(
subject
.
newrev
).
to
eq
(
source_sha
)
expect
(
subject
.
repo_created
).
to
be
(
false
)
expect
(
subject
.
repo_created
).
to
be
(
false
)
...
@@ -1644,6 +1645,23 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1644,6 +1645,23 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
context
'with gitaly'
do
it
"calls Gitaly's OperationService"
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
OperationService
)
.
to
receive
(
:user_ff_branch
).
with
(
user
,
source_sha
,
target_branch
)
.
and_return
(
nil
)
subject
end
it_behaves_like
'#ff_merge'
end
context
'without gitaly'
,
:skip_gitaly_mock
do
it_behaves_like
'#ff_merge'
end
end
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
rugged
=
repository
.
rugged
rugged
=
repository
.
rugged
...
...
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
View file @
37cc50f8
...
@@ -89,4 +89,38 @@ describe Gitlab::GitalyClient::OperationService do
...
@@ -89,4 +89,38 @@ describe Gitlab::GitalyClient::OperationService do
end
end
end
end
end
end
describe
'#user_ff_branch'
do
let
(
:target_branch
)
{
'my-branch'
}
let
(
:source_sha
)
{
'cfe32cf61b73a0d5e9f13e774abde7ff789b1660'
}
let
(
:request
)
do
Gitaly
::
UserFFBranchRequest
.
new
(
repository:
repository
.
gitaly_repository
,
branch:
target_branch
,
commit_id:
source_sha
,
user:
gitaly_user
)
end
let
(
:branch_update
)
do
Gitaly
::
OperationBranchUpdate
.
new
(
commit_id:
source_sha
,
repo_created:
false
,
branch_created:
false
)
end
let
(
:response
)
{
Gitaly
::
UserFFBranchResponse
.
new
(
branch_update:
branch_update
)
}
subject
{
client
.
user_ff_branch
(
user
,
source_sha
,
target_branch
)
}
it
'sends a user_ff_branch message and returns a BranchUpdate object'
do
expect_any_instance_of
(
Gitaly
::
OperationService
::
Stub
)
.
to
receive
(
:user_ff_branch
).
with
(
request
,
kind_of
(
Hash
))
.
and_return
(
response
)
expect
(
subject
).
to
be_a
(
Gitlab
::
Git
::
OperationService
::
BranchUpdate
)
expect
(
subject
.
newrev
).
to
eq
(
source_sha
)
expect
(
subject
.
repo_created
).
to
be
(
false
)
expect
(
subject
.
branch_created
).
to
be
(
false
)
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