mercurial/upgrade_utils/auto_upgrade.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 18 May 2022 16:50:55 +0100
changeset 49220 3376b5d9a697
parent 49200 71774d799de7
child 49339 9e203cda3238
permissions -rw-r--r--
debugdeltachain: glob variance of "test-generaldelta" We mostly care about generaldelta happening, the exact details of storage size variation is not really important so we can glob it instead of having multiple lines for each variances. This will make updating the output of the command simpler.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# upgrade.py - functions for automatic upgrade of Mercurial repository
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright (c) 2022-present, Pierre-Yves David
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
#
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
from ..i18n import _
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
from .. import (
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
    error,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
    requirements as requirementsmod,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
    scmutil,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    15
from . import (
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    16
    actions,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    17
    engine,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    18
)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    19
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    20
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    21
class AutoUpgradeOperation(actions.BaseOperation):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    22
    """A limited Upgrade Operation used to run simple auto upgrade task
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    23
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    24
    (Expand it as needed in the future)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    25
    """
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    26
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    27
    def __init__(self, req):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    28
        super().__init__(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    29
            new_requirements=req,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    30
            backup_store=False,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    31
        )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    32
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
def get_share_safe_action(repo):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
    """return an automatic-upgrade action for `share-safe` if applicable
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    36
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
    If no action is needed, return None, otherwise return a callback to upgrade
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
    or downgrade the repository according the configuration and repository
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    39
    format.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    40
    """
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
    ui = repo.ui
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
    requirements = repo.requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
    auto_upgrade_share_source = ui.configbool(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
        b'format',
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
        b'use-share-safe.automatic-upgrade-of-mismatching-repositories',
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
    )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
    action = None
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
    if (
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
        auto_upgrade_share_source
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
        and requirementsmod.SHARED_REQUIREMENT not in requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
    ):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
        sf_config = ui.configbool(b'format', b'use-share-safe')
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
        sf_local = requirementsmod.SHARESAFE_REQUIREMENT in requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    56
        if sf_config and not sf_local:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    57
            msg = _(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
                b"automatically upgrading repository to the `share-safe`"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    59
                b" feature\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
            )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
            hint = b"(see `hg help config.format.use-share-safe` for details)\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
            def action():
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    64
                if not ui.quiet:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
                    ui.write_err(msg)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
                    ui.write_err(hint)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    67
                requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
                scmutil.writereporequirements(repo, requirements)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    69
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    70
        elif sf_local and not sf_config:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
            msg = _(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
                b"automatically downgrading repository from the `share-safe`"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    73
                b" feature\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
            )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    75
            hint = b"(see `hg help config.format.use-share-safe` for details)\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    76
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    77
            def action():
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
                if not ui.quiet:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    79
                    ui.write_err(msg)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
                    ui.write_err(hint)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
                requirements.discard(requirementsmod.SHARESAFE_REQUIREMENT)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
                scmutil.writereporequirements(repo, requirements)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
    return action
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    87
def get_tracked_hint_action(repo):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    88
    """return an automatic-upgrade action for `tracked-hint` if applicable
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    89
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    90
    If no action is needed, return None, otherwise return a callback to upgrade
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    91
    or downgrade the repository according the configuration and repository
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    92
    format.
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    93
    """
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    94
    ui = repo.ui
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    95
    requirements = set(repo.requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    96
    auto_upgrade_tracked_hint = ui.configbool(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    97
        b'format',
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    98
        b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
    99
    )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   100
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   101
    action = None
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   102
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   103
    if auto_upgrade_tracked_hint:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   104
        th_config = ui.configbool(b'format', b'use-dirstate-tracked-hint')
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   105
        th_local = requirementsmod.DIRSTATE_TRACKED_HINT_V1 in requirements
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   106
        if th_config and not th_local:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   107
            msg = _(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   108
                b"automatically upgrading repository to the `tracked-hint`"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   109
                b" feature\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   110
            )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   111
            hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   112
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   113
            def action():
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   114
                if not ui.quiet:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   115
                    ui.write_err(msg)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   116
                    ui.write_err(hint)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   117
                requirements.add(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   118
                op = AutoUpgradeOperation(requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   119
                engine.upgrade_tracked_hint(ui, repo, op, add=True)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   120
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   121
        elif th_local and not th_config:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   122
            msg = _(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   123
                b"automatically downgrading repository from the `tracked-hint`"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   124
                b" feature\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   125
            )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   126
            hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   127
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   128
            def action():
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   129
                if not ui.quiet:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   130
                    ui.write_err(msg)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   131
                    ui.write_err(hint)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   132
                requirements.discard(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   133
                op = AutoUpgradeOperation(requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   134
                engine.upgrade_tracked_hint(ui, repo, op, add=False)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   135
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   136
    return action
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   137
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   138
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   139
def get_dirstate_v2_action(repo):
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   140
    """return an automatic-upgrade action for `dirstate-v2` if applicable
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   141
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   142
    If no action is needed, return None, otherwise return a callback to upgrade
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   143
    or downgrade the repository according the configuration and repository
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   144
    format.
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   145
    """
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   146
    ui = repo.ui
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   147
    requirements = set(repo.requirements)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   148
    auto_upgrade_tracked_hint = ui.configbool(
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   149
        b'format',
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   150
        b'use-dirstate-v2.automatic-upgrade-of-mismatching-repositories',
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   151
    )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   152
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   153
    action = None
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   154
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   155
    if auto_upgrade_tracked_hint:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   156
        d2_config = ui.configbool(b'format', b'use-dirstate-v2')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   157
        d2_local = requirementsmod.DIRSTATE_V2_REQUIREMENT in requirements
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   158
        if d2_config and not d2_local:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   159
            msg = _(
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   160
                b"automatically upgrading repository to the `dirstate-v2`"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   161
                b" feature\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   162
            )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   163
            hint = (
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   164
                b"(see `hg help config.format.use-dirstate-v2` for details)\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   165
            )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   166
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   167
            def action():
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   168
                if not ui.quiet:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   169
                    ui.write_err(msg)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   170
                    ui.write_err(hint)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   171
                requirements.add(requirementsmod.DIRSTATE_V2_REQUIREMENT)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   172
                fake_op = AutoUpgradeOperation(requirements)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   173
                engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v1', b'v2')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   174
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   175
        elif d2_local and not d2_config:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   176
            msg = _(
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   177
                b"automatically downgrading repository from the `dirstate-v2`"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   178
                b" feature\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   179
            )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   180
            hint = (
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   181
                b"(see `hg help config.format.use-dirstate-v2` for details)\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   182
            )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   183
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   184
            def action():
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   185
                if not ui.quiet:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   186
                    ui.write_err(msg)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   187
                    ui.write_err(hint)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   188
                requirements.discard(requirementsmod.DIRSTATE_V2_REQUIREMENT)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   189
                fake_op = AutoUpgradeOperation(requirements)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   190
                engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v2', b'v1')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   191
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   192
    return action
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   193
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   194
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
AUTO_UPGRADE_ACTIONS = [
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
   196
    get_dirstate_v2_action,
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   197
    get_share_safe_action,
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
   198
    get_tracked_hint_action,
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
]
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   200
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   201
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
def may_auto_upgrade(repo, maker_func):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
    """potentially perform auto-upgrade and return the final repository to use
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
    Auto-upgrade are "quick" repository upgrade that might automatically be run
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   206
    by "any" repository access. See `hg help config.format` for automatic
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
    upgrade documentation.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   208
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   209
    note: each relevant upgrades are done one after the other for simplicity.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   210
    This avoid having repository is partially inconsistent state while
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   211
    upgrading.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   212
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   213
    repo: the current repository instance
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   214
    maker_func: a factory function that can recreate a repository after an upgrade
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   215
    """
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   216
    clear = False
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   217
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   218
    loop = 0
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   219
49200
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   220
    try:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   221
        while not clear:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   222
            loop += 1
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   223
            if loop > 100:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   224
                # XXX basic protection against infinite loop, make it better.
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   225
                raise error.ProgrammingError("Too many auto upgrade loops")
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   226
            clear = True
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   227
            for get_action in AUTO_UPGRADE_ACTIONS:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   228
                action = get_action(repo)
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   229
                if action is not None:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   230
                    clear = False
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   231
                    with repo.wlock(wait=False), repo.lock(wait=False):
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   232
                        action = get_action(repo)
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   233
                        if action is not None:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   234
                            action()
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   235
                        repo = maker_func()
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   236
    except error.LockError:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   237
        # if we cannot get the lock, ignore the auto-upgrade attemps and
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   238
        # proceed. We might want to make this behavior configurable in the
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   239
        # future.
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   240
        pass
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
   241
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   242
    return repo