Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hgitaly
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
heptapod
hgitaly
Commits
00f38176
Commit
00f38176
authored
4 years ago
by
Sushil Khanchi
Browse files
Options
Downloads
Patches
Plain Diff
RepositoryService: implement FindMergeBase RPC
parent
eb8506ce
No related branches found
Branches containing commit
Tags
0.36.0
Tags containing commit
1 merge request
!54
RepositoryService: implement FindMergeBase RPC
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hgitaly/service/repository_service.py
+22
-2
22 additions, 2 deletions
hgitaly/service/repository_service.py
hgitaly/service/tests/test_repository_service.py
+54
-0
54 additions, 0 deletions
hgitaly/service/tests/test_repository_service.py
with
76 additions
and
2 deletions
hgitaly/service/repository_service.py
+
22
−
2
View file @
00f38176
...
...
@@ -76,8 +76,28 @@
def
FindMergeBase
(
self
,
request
:
FindMergeBaseRequest
,
context
)
->
FindMergeBaseResponse
:
return
not_implemented
(
context
,
FindMergeBaseResponse
,
issue
=
26
)
logger
.
debug
(
"
FindMergeBase request=%r
"
,
request
)
repo
=
self
.
load_repo
(
request
.
repository
,
context
)
if
len
(
request
.
revisions
)
<
2
:
# require at least 2 revisions
return
invalid_argument
(
context
,
FindMergeBaseResponse
,
'
FindMergeBase: at least 2 revisions are required
'
)
ctxs
=
[]
for
rev
in
request
.
revisions
:
ctx
=
gitlab_revision_changeset
(
repo
,
rev
)
if
ctx
is
None
:
return
FindMergeBaseResponse
()
ctxs
.
append
(
ctx
)
# As per Gitaly, In future we may support this method for more
# than two revisions, but for now we don't.
ctx_from
,
ctx_to
=
ctxs
[
0
],
ctxs
[
1
]
gca
=
repo
.
revs
(
b
"
ancestor(%d, %d)
"
%
(
ctx_from
.
rev
(),
ctx_to
.
rev
())
).
first
()
base
=
repo
[
gca
].
hex
()
if
gca
is
not
None
else
''
return
FindMergeBaseResponse
(
base
=
base
)
def
RepositoryExists
(
self
,
request
:
RepositoryExistsRequest
,
...
...
This diff is collapsed.
Click to expand it.
hgitaly/service/tests/test_repository_service.py
+
54
−
0
View file @
00f38176
...
...
@@ -21,9 +21,10 @@
from
hgitaly.tests.common
import
make_empty_repo
from
hgitaly.stub.repository_service_pb2
import
(
FindMergeBaseRequest
,
GetArchiveRequest
,
HasLocalBranchesRequest
,
RepositoryExistsRequest
,
WriteRefRequest
,
)
from
hgitaly.stub.repository_service_pb2_grpc
import
RepositoryServiceStub
...
...
@@ -24,9 +25,13 @@
GetArchiveRequest
,
HasLocalBranchesRequest
,
RepositoryExistsRequest
,
WriteRefRequest
,
)
from
hgitaly.stub.repository_service_pb2_grpc
import
RepositoryServiceStub
from
mercurial
import
(
node
as
node_mod
,
pycompat
,
)
def
test_repository_exists
(
grpc_channel
,
server_repos_root
):
...
...
@@ -225,3 +230,52 @@
assert
extract_dir
.
join
(
'
archive-dir
'
,
'
foo
'
).
read
()
==
large_content
del
large_content
def
test_find_merge_base
(
grpc_channel
,
server_repos_root
):
repo_stub
=
RepositoryServiceStub
(
grpc_channel
)
wrapper
,
grpc_repo
=
make_empty_repo
(
server_repos_root
)
# repo structure:
#
# o 2 add animal (branch/stable)
# |
# | 1 add bar
# |/
# |
# o 0 add foo
#
ctx0
=
wrapper
.
write_commit
(
'
foo
'
)
sha0
=
ctx0
.
hex
()
sha1
=
wrapper
.
write_commit
(
'
bar
'
).
hex
()
sha2
=
wrapper
.
write_commit
(
'
animal
'
,
branch
=
'
stable
'
,
parent
=
ctx0
).
hex
()
# commting new root, to test no gca case
sha3
=
wrapper
.
commit_file
(
'
tut
'
,
branch
=
'
other
'
,
parent
=
node_mod
.
nullid
).
hex
()
def
do_rpc
(
revisions
):
request
=
FindMergeBaseRequest
(
repository
=
grpc_repo
,
revisions
=
revisions
,
)
response
=
repo_stub
.
FindMergeBase
(
request
)
return
pycompat
.
sysbytes
(
response
.
base
)
# Actual test
assert
do_rpc
([
sha1
,
sha2
])
==
sha0
assert
do_rpc
([
b
'
branch/stable
'
,
sha1
])
==
sha0
# when no merge base (gca) found
assert
do_rpc
([
sha0
,
sha3
])
==
b
''
# test with invalid_argument, as it requires minimum 2 revisions
with
pytest
.
raises
(
grpc
.
RpcError
)
as
exc_info
:
do_rpc
([
sha0
])
assert
exc_info
.
value
.
code
()
==
grpc
.
StatusCode
.
INVALID_ARGUMENT
assert
(
exc_info
.
value
.
details
()
==
'
FindMergeBase: at least 2 revisions are required
'
)
sha_not_exists
=
b
'
deadnode
'
*
5
assert
do_rpc
([
sha0
,
sha_not_exists
])
==
b
''
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment