Skip to content
Snippets Groups Projects
Commit d44671a2 authored by Sushil Khanchi's avatar Sushil Khanchi :koala:
Browse files

CommitService: implement FindCommits (partially for now)

For now, this doesn't support all lookups, but we plan to
complete it by HGitaly1 milestone.
parent d40d133c
No related branches found
No related tags found
1 merge request!7CommitService: implement FindCommits (partially for now)
Pipeline #12550 passed
......@@ -15,6 +15,8 @@
CountCommitsResponse,
FindCommitRequest,
FindCommitResponse,
FindCommitsRequest,
FindCommitsResponse,
)
from ..stub.commit_pb2_grpc import CommitServiceServicer
......@@ -104,3 +106,24 @@
commit = None if ctx is None else message.commit(ctx)
return FindCommitResponse(commit=commit)
def FindCommits(self, request: FindCommitsRequest,
context) -> FindCommitsResponse:
# TODO: yet to finish this method to support all lookups
repo = self.load_repo(request.repository, context)
revision = request.revision
if revision:
ctx = gitlab_revision_changeset(repo, revision)
revs = repo.revs('::%s', ctx)
else:
# Note: if revision is not passed, we return all revs for now.
# `revision` and `all` are mutually exclusive
revs = repo.revs('all()')
# order revision from top to bottom i.e (tip:0)
revs.reverse()
limit = request.limit
if limit and len(revs) > limit:
revs = revs.slice(0, limit)
for chunk in chunked(revs):
yield FindCommitsResponse(
commits=(message.commit(repo[rev]) for rev in chunk))
......@@ -19,6 +19,7 @@
CommitIsAncestorRequest,
CommitsBetweenRequest,
FindCommitRequest,
FindCommitsRequest,
CountCommitsRequest,
)
from hgitaly.stub.commit_pb2_grpc import CommitServiceStub
......@@ -137,6 +138,45 @@
changesets['other_base'].hex(), changesets['wild2'].hex()]
def test_find_commits(grpc_channel, server_repos_root):
grpc_stub = CommitServiceStub(grpc_channel)
wrapper, grpc_repo = make_empty_repo(server_repos_root)
# prepare repo as:
#
# 2 (branch/default)
# |
# 1
# | 3 (topic/default/feature)
# | /
# 0
#
def do_rpc(revision=None, limit=None):
request = FindCommitsRequest(repository=grpc_repo,
revision=revision,
limit=limit)
resp = grpc_stub.FindCommits(request)
return [pycompat.sysbytes(commit.id)
for chunk in resp for commit in chunk.commits]
ctx0 = wrapper.write_commit('foo')
ctx1 = wrapper.write_commit('bar', parent=ctx0)
ctx2 = wrapper.write_commit('baz', parent=ctx1)
ctx3 = wrapper.write_commit('animals',
topic='feature',
parent=ctx0)
# find commits on branch/default
assert do_rpc(revision=b'branch/default') == [
ctx2.hex(), ctx1.hex(), ctx0.hex()]
# find commits on topic/default/feature
assert do_rpc(revision=b'topic/default/feature') == [
ctx3.hex(), ctx0.hex()]
# when no revision passed; return all for now
assert do_rpc() == [ctx3.hex(), ctx2.hex(), ctx1.hex(), ctx0.hex()]
# when limit passed
assert do_rpc(limit=2) == [ctx3.hex(), ctx2.hex()]
def test_count_commits(grpc_channel, server_repos_root):
grpc_stub = CommitServiceStub(grpc_channel)
wrapper, grpc_repo = make_empty_repo(server_repos_root)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment