Commit f4bda4e0 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

RefService.DeleteRefs: separated actual removing look

This will make forthcoming code for `except_prefix` easier
to integrate.

--HG--
branch : stable
parent 0d2b8a4e1def
......@@ -349,19 +349,15 @@ class RefServicer(RefServiceServicer, HGitalyServicer):
srefs = special_refs(repo)
if srefs is GITLAB_TYPED_REFS_MISSING:
srefs = ensure_special_refs(repo)
# Using copy() to avoid doing anything (natural rollback) if
# one of the ref is bogus.
# It's not really important right now because we have
# no cache of loaded repos, but that will change sooner or later.
srefs = srefs.copy()
for ref in request.refs:
name = parse_special_ref(ref)
if name is None:
return DeleteRefsResponse(
git_error="Only special refs, such as merge-requests (but "
"not keep-arounds) can be directly deleted in Mercurial, "
"got %r" % ref)
srefs.pop(name, None)
if refs:
# Using copy() to avoid doing anything (natural rollback) if
# one of the ref is bogus.
# It's not really important right now because we have
# no cache of loaded repos, but that will change sooner or later.
srefs = srefs.copy()
err = remove_special_refs(srefs, refs)
if err is not None:
return DeleteRefsResponse(git_error=err)
write_special_refs(repo, srefs)
return DeleteRefsResponse()
......@@ -515,3 +511,24 @@ TAG_REF_PREFIX = b'refs/tags/'
def gitlab_tag_from_ref(ref):
if ref.startswith(TAG_REF_PREFIX):
return ref[len(TAG_REF_PREFIX):]
def remove_special_refs(special_refs, to_remove):
"""Remove given elements of the ``special_refs`` mapping.
:param dict special_refs: the special refs to remove from, whose keys
are the shortened special ref name.
:param to_remove: iterable of full ref names to remove.
:returns: ``None`` if ok, else an error message.
It is not an error to remove an absent ref, but it is one to request
removal of a ref that is not a special ref.
"""
for ref in to_remove:
name = parse_special_ref(ref)
if name is None:
return (
"Only special refs, such as merge-requests (but "
"not keep-arounds) can be directly deleted in Mercurial, "
"got %r" % ref)
special_refs.pop(name, None)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment