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

GitLabStateMaintainer: adopted validate_obsolescence()

parent 798e60fa
No related branches found
No related tags found
1 merge request!50Separation of hg-git and generic parts in "mirroring" code
......@@ -13,9 +13,6 @@
from dulwich.repo import check_ref_format
from hggit.git_handler import GitHandler
from heptapod import (
util,
)
from heptapod.gitlab.branch import (
gitlab_branch_ref as git_branch_ref,
gitlab_branch_from_ref as git_branch_from_ref,
......@@ -41,7 +38,6 @@
WildHeadResolved,
)
from hgext3rd.evolve import headchecking
from mercurial.i18n import _
from mercurial.node import hex
from mercurial import (
error,
......@@ -108,49 +104,6 @@
hg_sha_from_gitlab_sha = GitHandler.map_hg_get
gitlab_sha_from_hg_sha = GitHandler.map_git_get
def validate_obsolescence(self, txn):
"""Abort if the given transaction creates unwanted obsolescence.
Most GitLab refs must not be to obsolete changesets, but we don't
want to create blocking situations for repos with long history
where this may already be the case.
See heptapod#393
We are at the end of the transaction, hence we can assume that
consequences of new obsmarkers have already been applied (e.g, moving
a bookmark if possible)
"""
unfi = self.repo.unfiltered()
for new_obsmarker in txn.changes[b'obsmarkers']:
try:
obsolete_ctx = unfi[new_obsmarker[0]]
except error.RepoLookupError:
continue
bookmarks = obsolete_ctx.bookmarks()
if bookmarks:
hint = _(b"If this isn't a mistake, you may need to also "
b"update the bookmark(s).")
msg = _(b"Refusing these changes, as they would make "
b"bookmark(s) %s point to the "
b"obsolete changeset %s") % (
util.format_bytes_list(bookmarks),
obsolete_ctx.hex())
raise error.Abort(msg, hint=hint)
tags = [t for t in obsolete_ctx.tags()
if unfi.tagtype(t) == b'global']
if tags:
hint = _(b"If this isn't a mistake, you may need to also "
b"update the tag(s).")
msg = _(b"Refusing these changes, as they would make "
b"tag(s) %s point to the "
b"obsolete changeset %s") % (
util.format_bytes_list(tags),
obsolete_ctx.hex())
raise error.Abort(msg, hint=hint)
def get_exportable(self):
"""Heptapod version, including named branches and topics.
......
......@@ -160,7 +160,7 @@
After all other rules have been applied, this handles the cases
where there are 0, 1 or several heads for the given branch.
storing at most one head in ``git_refs`` for the
storing at most one head in ``gitlab_refs`` for the
given ``branch`` either enforcing the rejection of multiple heads or
stoging extra heads in the ``wild`` namespace, according to
configuration.
......@@ -247,3 +247,46 @@
except error.RepoLookupError:
return None
return repo[rev].hex()
def validate_obsolescence(self, txn):
"""Abort if the given transaction creates unwanted obsolescence.
Most GitLab refs must not be to obsolete changesets, but we don't
want to create blocking situations for repos with long history
where this may already be the case.
See heptapod#393
We are at the end of the transaction, hence we can assume that
consequences of new obsmarkers have already been applied (e.g, moving
a bookmark if possible)
"""
unfi = self.repo.unfiltered()
for new_obsmarker in txn.changes[b'obsmarkers']:
try:
obsolete_ctx = unfi[new_obsmarker[0]]
except error.RepoLookupError:
continue
bookmarks = obsolete_ctx.bookmarks()
if bookmarks:
hint = _(b"If this isn't a mistake, you may need to also "
b"update the bookmark(s).")
msg = _(b"Refusing these changes, as they would make "
b"bookmark(s) %s point to the "
b"obsolete changeset %s") % (
util.format_bytes_list(bookmarks),
obsolete_ctx.hex())
raise error.Abort(msg, hint=hint)
tags = [t for t in obsolete_ctx.tags()
if unfi.tagtype(t) == b'global']
if tags:
hint = _(b"If this isn't a mistake, you may need to also "
b"update the tag(s).")
msg = _(b"Refusing these changes, as they would make "
b"tag(s) %s point to the "
b"obsolete changeset %s") % (
util.format_bytes_list(tags),
obsolete_ctx.hex())
raise error.Abort(msg, hint=hint)
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