Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
hgitaly
Commits
cebd3b97b285
Commit
cebd3b97
authored
Jul 19, 2021
by
Georges Racinet
🦑
Browse files
RefService.DeleteRefs: separated actual removing look
This will make forthcoming code for `except_prefix` easier to integrate.
parent
0d2b8a4e1def
Changes
1
Hide whitespace changes
Inline
Side-by-side
hgitaly/service/ref.py
View file @
cebd3b97
...
...
@@ -349,19 +349,15 @@
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 @@
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment