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

ref service: ListTagNamesContainingCommit

Same as sibling method for branches, we'll have to cope with
ordering, but that can probably wait.
parent b1dc70f8
No related branches found
No related tags found
No related merge requests found
Pipeline #7208 passed with warnings
......@@ -40,6 +40,8 @@
DeleteRefsResponse,
ListBranchNamesContainingCommitRequest,
ListBranchNamesContainingCommitResponse,
ListTagNamesContainingCommitRequest,
ListTagNamesContainingCommitResponse,
)
from ..stub.ref_pb2_grpc import RefServiceServicer
......@@ -236,6 +238,18 @@
yield ListBranchNamesContainingCommitResponse(
branch_names=chunk)
def ListTagNamesContainingCommit(
self,
request: ListTagNamesContainingCommitRequest,
context) -> ListTagNamesContainingCommitResponse:
# TODO support ordering, see similar method for branches
repo = self.load_repo(request.repository)
revs = repo.revs("%s:: and tag()", request.commit_id)
tag_names = (name for rev in revs for name in repo[rev].tags()
if repo.tagtype(name) not in EXCLUDED_TAG_TYPES)
for chunk in chunked(tag_names, limit=request.limit):
yield ListTagNamesContainingCommitResponse(tag_names=chunk)
def flbr_author(commit: GitCommit):
"""Extract commit intro specific fields of FindLocalBranchCommitAuthor."""
......
......@@ -19,6 +19,7 @@
FindAllBranchesRequest,
DeleteRefsRequest,
ListBranchNamesContainingCommitRequest,
ListTagNamesContainingCommitRequest,
)
from ..stub.ref_pb2_grpc import RefServiceStub
......@@ -237,3 +238,35 @@
assert len(limited) == 3
# until we have the ordering, we can only assert sub set.
assert limited.issubset(all_branches)
def test_list_tag_names_containing_commit(grpc_channel, server_repos_root):
ref_stub = RefServiceStub(grpc_channel)
wrapper, grpc_repo = make_empty_repo(server_repos_root,
relative_path='ltncc')
base = wrapper.write_commit('foo', message='Base')
default = wrapper.write_commit('foo', message='Head of default')
wrapper.command('tag', b'v3.2.1', rev=default.hex())
other = wrapper.write_commit('foo', message='Start other',
branch='other', parent=base)
wrapper.command('tag', b'other-tag', rev=other.hex())
def do_list(ctx, limit=0):
chunks_iter = ref_stub.ListTagNamesContainingCommit(
ListTagNamesContainingCommitRequest(
repository=grpc_repo,
commit_id=pycompat.sysstr(ctx.hex()),
limit=limit,
))
return [pycompat.sysstr(tag_name) for chunk in chunks_iter
for tag_name in chunk.tag_names]
all_tags = {'v3.2.1', 'other-tag'}
assert set(do_list(base)) == all_tags
assert do_list(default) == ['v3.2.1']
assert do_list(other) == ['other-tag']
limited = do_list(base, limit=1)
assert len(limited) == 1
assert limited[0] in all_tags
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