Skip to content
Snippets Groups Projects
Commit bf7abe24 authored by Georges Racinet's avatar Georges Racinet
Browse files

ref service: FindLocalBranches

It looks as if the `commit` field was added last, and that
would explain why the redundancy.
parent 5cca85c5
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,8 @@
from hgext3rd.heptapod.branch import get_default_gitlab_branch
from ..stub.shared_pb2 import (
Branch
Branch,
GitCommit,
)
from ..stub.ref_pb2 import (
FindDefaultBranchNameRequest,
......@@ -23,6 +24,10 @@
FindAllTagNamesResponse,
FindRefNameRequest,
FindRefNameResponse,
FindLocalBranchesRequest,
FindLocalBranchCommitAuthor,
FindLocalBranchResponse,
FindLocalBranchesResponse,
FindAllBranchesRequest,
FindAllBranchesResponse,
FindBranchRequest,
......@@ -135,6 +140,16 @@
return FindBranchResponse(
branch=Branch(name=name, target_commit=git_commit(head)))
def FindLocalBranches(self,
request: FindLocalBranchesRequest,
context) -> FindLocalBranchesResponse:
repo = self.load_repo(request.repository)
for chunk in chunked(iter_gitlab_branches(repo)):
yield FindLocalBranchesResponse(
branches=(find_local_branch_response(name, head)
for name, head in chunk),
)
def FindAllBranches(self,
request: FindAllBranchesRequest,
context) -> FindAllBranchesResponse:
......@@ -144,3 +159,25 @@
yield FindAllBranchesResponse(
branches=(Branch(name=name, target=git_commit(head))
for name, head in chunk))
def flbr_author(commit: GitCommit):
"""Extract commit intro specific fields of FindLocalBranchCommitAuthor."""
return FindLocalBranchCommitAuthor(
name=commit.name,
email=commit.email,
date=commit.date,
timezone=commit.timezone,
)
def find_local_branch_response(name, head):
commit = git_commit(head)
return FindLocalBranchResponse(
name=name,
commit_id=commit.id,
commit_subject=commit.subject,
commit_author=flbr_author(commit.author),
commit_committer=flbr_author(commit.committer),
commit=commit,
)
......@@ -10,6 +10,7 @@
FindAllBranchNamesRequest,
FindAllTagNamesRequest,
FindBranchRequest,
FindLocalBranchesRequest,
FindAllBranchesRequest,
)
from ..stub.ref_pb2_grpc import RefServiceStub
......@@ -68,7 +69,7 @@
ref_stub = RefServiceStub(grpc_channel)
wrapper, grpc_repo = make_empty_repo(server_repos_root,
relative_path='find_branch')
ctx = wrapper.write_commit('foo')
ctx = wrapper.write_commit('foo', message="Ze subject")
resp = ref_stub.FindBranch(
FindBranchRequest(repository=grpc_repo,
name=b'branch/default'))
......@@ -91,6 +92,14 @@
# to represent the absence of results.
assert not resp.branch.name
resp = ref_stub.FindLocalBranches(
FindLocalBranchesRequest(repository=grpc_repo))
branches = [br for chunk in resp for br in chunk.branches]
assert len(branches) == 1
assert branches[0].name == b'branch/default'
assert branches[0].commit == branch.target_commit
assert branches[0].commit_subject == b"Ze subject"
resp = ref_stub.FindAllBranches(
FindAllBranchesRequest(repository=grpc_repo))
branches = [br for chunk in resp for br in chunk.branches]
......
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