Last active
September 13, 2022 15:57
-
-
Save jaraco/5d3edde1e1424a56ba873916ec898d77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""internal-phase migration support.""" | |
# This software may be used and distributed according to the terms of the | |
# GNU General Public License version 2 or any later version. | |
from google_hgext import util | |
from mercurial import exthelper | |
from mercurial import localrepo | |
from mercurial import scmutil | |
eh = exthelper.exthelper() | |
old_name = b'internal-phase' | |
# disabled; TODO: enable in a subsequent release | |
# from mercurial import phases | |
# from mercurial import requirements | |
# @eh.reposetup | |
# def enable_internal_phase(ui, repo): | |
# """Enable the internal-phase.""" | |
# del ui # unused | |
# if not is_fig(repo): | |
# return | |
# if phases.supportinternal(repo): | |
# return | |
# repo.requirements.add(requirements.INTERNAL_PHASE_REQUIREMENT) | |
# scmutil.writereporequirements(repo) | |
# assert phases.supportinternal(repo) | |
@eh.wrapfunction(localrepo, 'ensurerequirementsrecognized') | |
def check_reqs(orig, requirements_, supported): | |
"""Override localrepo.ensurerequirementsrecognized for compatibility. | |
Make it appear as if 'internal-phase' is supported | |
on later versions of Mercurial where it's been removed. | |
Avoids a crash when starting up on a repo with the | |
deprecated 'internal-phase' so that | |
``remove_internal_phase_requirement`` can effect | |
its change. | |
Args: | |
orig: original function | |
requirements_: same as orig | |
supported: same as orig | |
Returns: | |
same as orig | |
""" | |
return orig(requirements_, supported | {old_name}) | |
@eh.reposetup | |
def remove_internal_phase_requirement(ui, repo): | |
"""Remove any internal-phase requirement. | |
In 74fb1842f8b9, Mercurial renamed the requirement for enabling the internal | |
phase. This change happened during Google's adoption of the feature, | |
so the current codebase also expects to support the original name. | |
Remove the old requirement. | |
Remove this code after the internal phase work has stabilized. | |
Args: | |
ui: the ui | |
repo: the repo | |
Returns: | |
nothing | |
""" | |
if not util.is_fig(repo): | |
return | |
try: | |
repo.requirements.remove(old_name) | |
except KeyError: | |
return | |
try: | |
scmutil.writereporequirements(repo) | |
except PermissionError: | |
ui.log(b'shelve', b'no permission to update repository requirements\n') | |
except Exception as exc: # pylint: disable=broad-except | |
msg = f'phase migration failed to remove internal-phase ({exc!r})\n' | |
bmsg = msg.encode() | |
ui.warn(bmsg) | |
ui.log(b'shelve', bmsg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The latest revision reflects the implementation we've adopted.