mercurial/upgrade.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 27 Sep 2019 21:14:23 +0200
changeset 43000 164bbf674bb6
parent 42999 bb6902cbbe23
child 43002 373749982924
permissions -rw-r--r--
upgrade: also copy data file Differential Revision: https://phab.mercurial-scm.org/D6903
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31894
9379689b6c10 upgrade: update the header comment
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31893
diff changeset
     1
# upgrade.py - functions for in place upgrade of Mercurial repository
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
31895
783b4c9bd5f5 upgrade: update the copyright statement
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31894
diff changeset
     3
# Copyright (c) 2016-present, Gregory Szorc
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8073
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9150
diff changeset
     6
# GNU General Public License version 2 or any later version.
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
     8
from __future__ import absolute_import
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
     9
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
    10
import stat
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    12
from .i18n import _
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    13
from . import (
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    14
    changelog,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26425
diff changeset
    15
    error,
35344
8f3f8b8dbab7 upgrade: use actual filelog to convert filelog
Boris Feld <boris.feld@octobus.net>
parents: 35343
diff changeset
    16
    filelog,
35343
06987c6971be upgrade: more standard creation of the temporary repository
Boris Feld <boris.feld@octobus.net>
parents: 35342
diff changeset
    17
    hg,
31893
165428b05fca upgrade: import 'localrepo' globally
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31875
diff changeset
    18
    localrepo,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    19
    manifest,
38165
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37444
diff changeset
    20
    pycompat,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    21
    revlog,
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
    22
    scmutil,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    23
    util,
31232
254f98326eef vfs: use 'vfs' module directly in 'mercurial.repair'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30975
diff changeset
    24
    vfs as vfsmod,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    25
)
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    26
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    27
from .utils import (
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    28
    compression,
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    29
)
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    30
42832
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    31
# list of requirements that request a clone of all revlog if added/removed
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    32
RECLONES_REQUIREMENTS = {
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    33
    'generaldelta',
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    34
    localrepo.SPARSEREVLOG_REQUIREMENT,
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    35
}
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
    36
31865
5dcaa0f4455b upgrade: drop the prefix to the 'requiredsourcerequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31864
diff changeset
    37
def requiredsourcerequirements(repo):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    38
    """Obtain requirements required to be present to upgrade a repo.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    39
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    40
    An upgrade will not be allowed if the repository doesn't have the
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    41
    requirements returned by this function.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    42
    """
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
    43
    return {
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    44
        # Introduced in Mercurial 0.9.2.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    45
        'revlogv1',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    46
        # Introduced in Mercurial 0.9.2.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    47
        'store',
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
    48
    }
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    49
31866
1454726b6d7c upgrade: drop the prefix to the 'blocksourcerequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31865
diff changeset
    50
def blocksourcerequirements(repo):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    51
    """Obtain requirements that will prevent an upgrade from occurring.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    52
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    53
    An upgrade cannot be performed if the source repository contains a
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    54
    requirements in the returned set.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    55
    """
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
    56
    return {
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    57
        # The upgrade code does not yet support these experimental features.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    58
        # This is an artificial limitation.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    59
        'treemanifest',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    60
        # This was a precursor to generaldelta and was never enabled by default.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    61
        # It should (hopefully) not exist in the wild.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    62
        'parentdelta',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    63
        # Upgrade should operate on the actual store, not the shared link.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    64
        'shared',
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
    65
    }
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    66
31867
cc60b6c36637 upgrade: drop the prefix to the 'supportremovedrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31866
diff changeset
    67
def supportremovedrequirements(repo):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    68
    """Obtain requirements that can be removed during an upgrade.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    69
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    70
    If an upgrade were to create a repository that dropped a requirement,
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    71
    the dropped requirement must appear in the returned set for the upgrade
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    72
    to be allowed.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    73
    """
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    74
    supported = {
38720
d12415b8f833 upgrade: enable adding or removing sparse-revlog requirement
Paul Morelle <paul.morelle@octobus.net>
parents: 38719
diff changeset
    75
        localrepo.SPARSEREVLOG_REQUIREMENT,
d12415b8f833 upgrade: enable adding or removing sparse-revlog requirement
Paul Morelle <paul.morelle@octobus.net>
parents: 38719
diff changeset
    76
    }
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    77
    for name in compression.compengines:
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    78
        engine = compression.compengines[name]
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    79
        if engine.available() and engine.revlogheader():
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    80
            supported.add(b'exp-compression-%s' % name)
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    81
            if engine.name() == 'zstd':
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    82
                supported.add(b'revlog-compression-zstd')
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    83
    return supported
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    84
31870
49011f1cedd4 upgrade: drop the prefix to the 'supporteddestrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31869
diff changeset
    85
def supporteddestrequirements(repo):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    86
    """Obtain requirements that upgrade supports in the destination.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    87
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    88
    If the result of the upgrade would create requirements not in this set,
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    89
    the upgrade is disallowed.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    90
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    91
    Extensions should monkeypatch this to add their custom requirements.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    92
    """
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
    93
    supported = {
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    94
        'dotencode',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    95
        'fncache',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    96
        'generaldelta',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    97
        'revlogv1',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
    98
        'store',
38720
d12415b8f833 upgrade: enable adding or removing sparse-revlog requirement
Paul Morelle <paul.morelle@octobus.net>
parents: 38719
diff changeset
    99
        localrepo.SPARSEREVLOG_REQUIREMENT,
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
   100
    }
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   101
    for name in compression.compengines:
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   102
        engine = compression.compengines[name]
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   103
        if engine.available() and engine.revlogheader():
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   104
            supported.add(b'exp-compression-%s' % name)
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   105
            if engine.name() == 'zstd':
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   106
                supported.add(b'revlog-compression-zstd')
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   107
    return supported
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   108
31869
fe5e30b58934 upgrade: drop the prefix to the 'allowednewrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31868
diff changeset
   109
def allowednewrequirements(repo):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   110
    """Obtain requirements that can be added to a repository during upgrade.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   111
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   112
    This is used to disallow proposed requirements from being added when
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   113
    they weren't present before.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   114
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   115
    We use a list of allowed requirement additions instead of a list of known
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   116
    bad additions because the whitelist approach is safer and will prevent
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   117
    future, unknown requirements from accidentally being added.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   118
    """
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   119
    supported = {
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   120
        'dotencode',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   121
        'fncache',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   122
        'generaldelta',
38720
d12415b8f833 upgrade: enable adding or removing sparse-revlog requirement
Paul Morelle <paul.morelle@octobus.net>
parents: 38719
diff changeset
   123
        localrepo.SPARSEREVLOG_REQUIREMENT,
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
   124
    }
42137
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   125
    for name in compression.compengines:
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   126
        engine = compression.compengines[name]
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   127
        if engine.available() and engine.revlogheader():
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   128
            supported.add(b'exp-compression-%s' % name)
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   129
            if engine.name() == 'zstd':
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   130
                supported.add(b'revlog-compression-zstd')
d086ba387ae8 upgrade: support upgrade to/from zstd storage (issue6088)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42136
diff changeset
   131
    return supported
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   132
35302
ad2b35ebf670 upgraderepo: allow extension to register preserved requirements
Boris Feld <boris.feld@octobus.net>
parents: 33438
diff changeset
   133
def preservedrequirements(repo):
ad2b35ebf670 upgraderepo: allow extension to register preserved requirements
Boris Feld <boris.feld@octobus.net>
parents: 33438
diff changeset
   134
    return set()
ad2b35ebf670 upgraderepo: allow extension to register preserved requirements
Boris Feld <boris.feld@octobus.net>
parents: 33438
diff changeset
   135
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   136
deficiency = 'deficiency'
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   137
optimisation = 'optimization'
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   138
31868
9f84ccb1b282 upgrade: drop the prefix to the 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31867
diff changeset
   139
class improvement(object):
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   140
    """Represents an improvement that can be made as part of an upgrade.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   141
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   142
    The following attributes are defined on each instance:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   143
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   144
    name
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   145
       Machine-readable string uniquely identifying this improvement. It
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   146
       will be mapped to an action later in the upgrade process.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   147
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   148
    type
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   149
       Either ``deficiency`` or ``optimisation``. A deficiency is an obvious
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   150
       problem. An optimization is an action (sometimes optional) that
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   151
       can be taken to further improve the state of the repository.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   152
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   153
    description
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   154
       Message intended for humans explaining the improvement in more detail,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   155
       including the implications of it. For ``deficiency`` types, should be
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   156
       worded in the present tense. For ``optimisation`` types, should be
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   157
       worded in the future tense.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   158
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   159
    upgrademessage
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   160
       Message intended for humans explaining what an upgrade addressing this
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   161
       issue will do. Should be worded in the future tense.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   162
    """
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   163
    def __init__(self, name, type, description, upgrademessage):
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   164
        self.name = name
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   165
        self.type = type
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   166
        self.description = description
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   167
        self.upgrademessage = upgrademessage
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   168
31902
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   169
    def __eq__(self, other):
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   170
        if not isinstance(other, improvement):
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   171
            # This is what python tell use to do
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   172
            return NotImplemented
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   173
        return self.name == other.name
6557f0d4ab8e upgrade: implement equality for 'improvement' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31901
diff changeset
   174
32028
99f63f476a72 upgrade: implement '__ne__' on 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31904
diff changeset
   175
    def __ne__(self, other):
40997
038108a9811c upgrade: correct implementation of improvement.__ne__
Benjamin Peterson <benjamin@python.org>
parents: 40918
diff changeset
   176
        return not (self == other)
32028
99f63f476a72 upgrade: implement '__ne__' on 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31904
diff changeset
   177
32029
9e35848fa007 upgrade: implement '__hash__' on 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32028
diff changeset
   178
    def __hash__(self):
9e35848fa007 upgrade: implement '__hash__' on 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32028
diff changeset
   179
        return hash(self.name)
9e35848fa007 upgrade: implement '__hash__' on 'improvement' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32028
diff changeset
   180
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   181
allformatvariant = []
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   182
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   183
def registerformatvariant(cls):
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   184
    allformatvariant.append(cls)
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   185
    return cls
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   186
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   187
class formatvariant(improvement):
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   188
    """an improvement subclass dedicated to repository format"""
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   189
    type = deficiency
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   190
    ### The following attributes should be defined for each class:
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   191
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   192
    # machine-readable string uniquely identifying this improvement. it will be
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   193
    # mapped to an action later in the upgrade process.
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   194
    name = None
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   195
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   196
    # message intended for humans explaining the improvement in more detail,
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   197
    # including the implications of it ``deficiency`` types, should be worded
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   198
    # in the present tense.
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   199
    description = None
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   200
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   201
    # message intended for humans explaining what an upgrade addressing this
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   202
    # issue will do. should be worded in the future tense.
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   203
    upgrademessage = None
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   204
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   205
    # value of current Mercurial default for new repository
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   206
    default = None
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   207
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   208
    def __init__(self):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   209
        raise NotImplementedError()
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   210
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   211
    @staticmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   212
    def fromrepo(repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   213
        """current value of the variant in the repository"""
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   214
        raise NotImplementedError()
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   215
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   216
    @staticmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   217
    def fromconfig(repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   218
        """current value of the variant in the configuration"""
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   219
        raise NotImplementedError()
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   220
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   221
class requirementformatvariant(formatvariant):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   222
    """formatvariant based on a 'requirement' name.
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   223
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   224
    Many format variant are controlled by a 'requirement'. We define a small
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   225
    subclass to factor the code.
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   226
    """
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   227
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   228
    # the requirement that control this format variant
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   229
    _requirement = None
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   230
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   231
    @staticmethod
39546
41aa5dced975 localrepo: pass ui to newreporequirements() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39243
diff changeset
   232
    def _newreporequirements(ui):
39996
dbcb466d0065 localrepo: define storage backend in creation options (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39870
diff changeset
   233
        return localrepo.newreporequirements(
dbcb466d0065 localrepo: define storage backend in creation options (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39870
diff changeset
   234
            ui, localrepo.defaultcreateopts(ui))
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   235
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   236
    @classmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   237
    def fromrepo(cls, repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   238
        assert cls._requirement is not None
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   239
        return cls._requirement in repo.requirements
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   240
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   241
    @classmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   242
    def fromconfig(cls, repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   243
        assert cls._requirement is not None
39546
41aa5dced975 localrepo: pass ui to newreporequirements() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39243
diff changeset
   244
        return cls._requirement in cls._newreporequirements(repo.ui)
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   245
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   246
@registerformatvariant
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   247
class fncache(requirementformatvariant):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   248
    name = 'fncache'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   249
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   250
    _requirement = 'fncache'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   251
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   252
    default = True
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   253
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   254
    description = _('long and reserved filenames may not work correctly; '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   255
                    'repository performance is sub-optimal')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   256
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   257
    upgrademessage = _('repository will be more resilient to storing '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   258
                       'certain paths and performance of certain '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   259
                       'operations should be improved')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   260
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   261
@registerformatvariant
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   262
class dotencode(requirementformatvariant):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   263
    name = 'dotencode'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   264
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   265
    _requirement = 'dotencode'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   266
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   267
    default = True
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   268
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   269
    description = _('storage of filenames beginning with a period or '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   270
                    'space may not work correctly')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   271
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   272
    upgrademessage = _('repository will be better able to store files '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   273
                       'beginning with a space or period')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   274
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   275
@registerformatvariant
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   276
class generaldelta(requirementformatvariant):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   277
    name = 'generaldelta'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   278
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   279
    _requirement = 'generaldelta'
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   280
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   281
    default = True
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   282
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   283
    description = _('deltas within internal storage are unable to '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   284
                    'choose optimal revisions; repository is larger and '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   285
                    'slower than it could be; interaction with other '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   286
                    'repositories may require extra network and CPU '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   287
                    'resources, making "hg push" and "hg pull" slower')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   288
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   289
    upgrademessage = _('repository storage will be able to create '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   290
                       'optimal deltas; new repository data will be '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   291
                       'smaller and read times should decrease; '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   292
                       'interacting with other repositories using this '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   293
                       'storage model should require less network and '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   294
                       'CPU resources, making "hg push" and "hg pull" '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   295
                       'faster')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   296
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   297
@registerformatvariant
38719
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   298
class sparserevlog(requirementformatvariant):
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   299
    name = 'sparserevlog'
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   300
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   301
    _requirement = localrepo.SPARSEREVLOG_REQUIREMENT
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   302
40918
3764330f76a6 sparse-revlog: enabled by default
Boris Feld <boris.feld@octobus.net>
parents: 40837
diff changeset
   303
    default = True
38719
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   304
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   305
    description = _('in order to limit disk reading and memory usage on older '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   306
                    'version, the span of a delta chain from its root to its '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   307
                    'end is limited, whatever the relevant data in this span. '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   308
                    'This can severly limit Mercurial ability to build good '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   309
                    'chain of delta resulting is much more storage space being '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   310
                    'taken and limit reusability of on disk delta during '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   311
                    'exchange.'
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   312
                   )
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   313
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   314
    upgrademessage = _('Revlog supports delta chain with more unused data '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   315
                       'between payload. These gaps will be skipped at read '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   316
                       'time. This allows for better delta chains, making a '
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   317
                       'better compression and faster exchange with server.')
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   318
4ad2a1ff0404 upgrade: add information about sparse-revlog
Paul Morelle <paul.morelle@octobus.net>
parents: 38399
diff changeset
   319
@registerformatvariant
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   320
class removecldeltachain(formatvariant):
35335
0181f99819d2 upgrade: rename 'removecldeltachain' to 'plain-cl-delta'
Boris Feld <boris.feld@octobus.net>
parents: 35302
diff changeset
   321
    name = 'plain-cl-delta'
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   322
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   323
    default = True
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   324
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   325
    description = _('changelog storage is using deltas instead of '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   326
                    'raw entries; changelog reading and any '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   327
                    'operation relying on changelog data are slower '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   328
                    'than they could be')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   329
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   330
    upgrademessage = _('changelog storage will be reformated to '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   331
                       'store raw entries; changelog reading will be '
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   332
                       'faster; changelog size may be reduced')
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   333
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   334
    @staticmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   335
    def fromrepo(repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   336
        # Mercurial 4.0 changed changelogs to not use delta chains. Search for
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   337
        # changelogs with deltas.
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   338
        cl = repo.changelog
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   339
        chainbase = cl.chainbase
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   340
        return all(rev == chainbase(rev) for rev in cl)
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   341
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   342
    @staticmethod
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   343
    def fromconfig(repo):
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   344
        return True
32030
e47223576b8d upgrade: introduce a 'formatvariant' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32029
diff changeset
   345
35340
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   346
@registerformatvariant
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   347
class compressionengine(formatvariant):
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   348
    name = 'compression'
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   349
    default = 'zlib'
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   350
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   351
    description = _('Compresion algorithm used to compress data. '
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   352
                    'Some engine are faster than other')
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   353
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   354
    upgrademessage = _('revlog content will be recompressed with the new '
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   355
                       'algorithm.')
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   356
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   357
    @classmethod
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   358
    def fromrepo(cls, repo):
42136
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   359
        # we allow multiple compression engine requirement to co-exist because
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   360
        # strickly speaking, revlog seems to support mixed compression style.
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   361
        #
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   362
        # The compression used for new entries will be "the last one"
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   363
        compression = 'zlib'
35340
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   364
        for req in repo.requirements:
42136
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   365
            prefix = req.startswith
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   366
            if prefix('revlog-compression-') or prefix('exp-compression-'):
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   367
                compression = req.split('-', 2)[2]
10a6725dca6e compression: introduce an official `zstd-revlog` requirement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42046
diff changeset
   368
        return compression
35340
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   369
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   370
    @classmethod
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   371
    def fromconfig(cls, repo):
42046
4ee906aa7b60 compression: introduce an official `format.revlog-compression` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42045
diff changeset
   372
        return repo.ui.config('format', 'revlog-compression')
35340
ead01b74be04 upgrade: register compression as a format variants
Boris Feld <boris.feld@octobus.net>
parents: 35335
diff changeset
   373
42045
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   374
@registerformatvariant
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   375
class compressionlevel(formatvariant):
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   376
    name = 'compression-level'
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   377
    default = 'default'
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   378
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   379
    description = _('compression level')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   380
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   381
    upgrademessage = _('revlog content will be recompressed')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   382
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   383
    @classmethod
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   384
    def fromrepo(cls, repo):
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   385
        comp = compressionengine.fromrepo(repo)
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   386
        level = None
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   387
        if comp == 'zlib':
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   388
            level = repo.ui.configint('storage', 'revlog.zlib.level')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   389
        elif comp == 'zstd':
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   390
            level = repo.ui.configint('storage', 'revlog.zstd.level')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   391
        if level is None:
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   392
            return 'default'
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   393
        return bytes(level)
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   394
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   395
    @classmethod
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   396
    def fromconfig(cls, repo):
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   397
        comp = compressionengine.fromconfig(repo)
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   398
        level = None
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   399
        if comp == 'zlib':
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   400
            level = repo.ui.configint('storage', 'revlog.zlib.level')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   401
        elif comp == 'zstd':
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   402
            level = repo.ui.configint('storage', 'revlog.zstd.level')
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   403
        if level is None:
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   404
            return 'default'
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   405
        return bytes(level)
d7e751ec679e compression: display compression level in debugformat
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41089
diff changeset
   406
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   407
def finddeficiencies(repo):
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   408
    """returns a list of deficiencies that the repo suffer from"""
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   409
    deficiencies = []
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   410
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   411
    # We could detect lack of revlogv1 and store here, but they were added
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   412
    # in 0.9.2 and we don't support upgrading repos without these
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   413
    # requirements, so let's not bother.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   414
32032
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   415
    for fv in allformatvariant:
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   416
        if not fv.fromrepo(repo):
189778a06743 upgrade: register all format variants in a list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32031
diff changeset
   417
            deficiencies.append(fv)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   418
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   419
    return deficiencies
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   420
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   421
# search without '-' to support older form on newer client.
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   422
#
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   423
# We don't enforce backward compatibility for debug command so this
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   424
# might eventually be dropped. However, having to use two different
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   425
# forms in script when comparing result is anoying enough to add
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   426
# backward compatibility for a while.
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   427
legacy_opts_map = {
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   428
    'redeltaparent': 're-delta-parent',
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   429
    'redeltamultibase': 're-delta-multibase',
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   430
    'redeltaall': 're-delta-all',
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   431
    'redeltafulladd': 're-delta-fulladd',
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   432
}
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   433
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   434
def findoptimizations(repo):
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   435
    """Determine optimisation that could be used during upgrade"""
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   436
    # These are unconditionally added. There is logic later that figures out
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   437
    # which ones to apply.
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   438
    optimizations = []
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   439
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   440
    optimizations.append(improvement(
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   441
        name='re-delta-parent',
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   442
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   443
        description=_('deltas within internal storage will be recalculated to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   444
                      'choose an optimal base revision where this was not '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   445
                      'already done; the size of the repository may shrink and '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   446
                      'various operations may become faster; the first time '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   447
                      'this optimization is performed could slow down upgrade '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   448
                      'execution considerably; subsequent invocations should '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   449
                      'not run noticeably slower'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   450
        upgrademessage=_('deltas within internal storage will choose a new '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   451
                         'base revision if needed')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   452
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   453
    optimizations.append(improvement(
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   454
        name='re-delta-multibase',
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   455
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   456
        description=_('deltas within internal storage will be recalculated '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   457
                      'against multiple base revision and the smallest '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   458
                      'difference will be used; the size of the repository may '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   459
                      'shrink significantly when there are many merges; this '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   460
                      'optimization will slow down execution in proportion to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   461
                      'the number of merges in the repository and the amount '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   462
                      'of files in the repository; this slow down should not '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   463
                      'be significant unless there are tens of thousands of '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   464
                      'files and thousands of merges'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   465
        upgrademessage=_('deltas within internal storage will choose an '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   466
                         'optimal delta by computing deltas against multiple '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   467
                         'parents; may slow down execution time '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   468
                         'significantly')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   469
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   470
    optimizations.append(improvement(
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   471
        name='re-delta-all',
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   472
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   473
        description=_('deltas within internal storage will always be '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   474
                      'recalculated without reusing prior deltas; this will '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   475
                      'likely make execution run several times slower; this '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   476
                      'optimization is typically not needed'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   477
        upgrademessage=_('deltas within internal storage will be fully '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   478
                         'recomputed; this will likely drastically slow down '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   479
                         'execution time')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   480
35345
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   481
    optimizations.append(improvement(
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   482
        name='re-delta-fulladd',
35345
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   483
        type=optimisation,
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   484
        description=_('every revision will be re-added as if it was new '
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   485
                      'content. It will go through the full storage '
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   486
                      'mechanism giving extensions a chance to process it '
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   487
                      '(eg. lfs). This is similar to "re-delta-all" but even '
35345
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   488
                      'slower since more logic is involved.'),
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   489
        upgrademessage=_('each revision will be added as new content to the '
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   490
                         'internal storage; this will likely drastically slow '
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   491
                         'down execution time, but some extensions might need '
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   492
                         'it')))
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   493
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   494
    return optimizations
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   495
31900
0f0d7005b9ad upgrade: simplify 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31899
diff changeset
   496
def determineactions(repo, deficiencies, sourcereqs, destreqs):
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   497
    """Determine upgrade actions that will be performed.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   498
31896
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   499
    Given a list of improvements as returned by ``finddeficiencies`` and
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   500
    ``findoptimizations``, determine the list of upgrade actions that
127b41e975fd upgrade: split finding deficiencies from finding optimisations
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31895
diff changeset
   501
    will be performed.
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   502
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   503
    The role of this function is to filter improvements if needed, apply
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   504
    recommended optimizations from the improvements list that make sense,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   505
    etc.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   506
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   507
    Returns a list of action names.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   508
    """
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   509
    newactions = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   510
31870
49011f1cedd4 upgrade: drop the prefix to the 'supporteddestrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31869
diff changeset
   511
    knownreqs = supporteddestrequirements(repo)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   512
31900
0f0d7005b9ad upgrade: simplify 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31899
diff changeset
   513
    for d in deficiencies:
0f0d7005b9ad upgrade: simplify 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31899
diff changeset
   514
        name = d.name
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   515
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   516
        # If the action is a requirement that doesn't show up in the
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   517
        # destination requirements, prune the action.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   518
        if name in knownreqs and name not in destreqs:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   519
            continue
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   520
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
   521
        newactions.append(d)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   522
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   523
    # FUTURE consider adding some optimizations here for certain transitions.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   524
    # e.g. adding generaldelta could schedule parent redeltas.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   525
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   526
    return newactions
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   527
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   528
def _revlogfrompath(repo, path):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   529
    """Obtain a revlog from a repo path.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   530
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   531
    An instance of the appropriate class is returned.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   532
    """
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   533
    if path == '00changelog.i':
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   534
        return changelog.changelog(repo.svfs)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   535
    elif path.endswith('00manifest.i'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   536
        mandir = path[:-len('00manifest.i')]
39243
0d97530eb535 manifest: rename dir argument and attribute to tree
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38736
diff changeset
   537
        return manifest.manifestrevlog(repo.svfs, tree=mandir)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   538
    else:
35344
8f3f8b8dbab7 upgrade: use actual filelog to convert filelog
Boris Feld <boris.feld@octobus.net>
parents: 35343
diff changeset
   539
        #reverse of "/".join(("data", path + ".i"))
8f3f8b8dbab7 upgrade: use actual filelog to convert filelog
Boris Feld <boris.feld@octobus.net>
parents: 35343
diff changeset
   540
        return filelog.filelog(repo.svfs, path[5:-2])
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   541
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   542
def _copyrevlog(tr, destrepo, oldrl, unencodedname):
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   543
    """copy all relevant files for `oldrl` into `destrepo` store
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   544
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   545
    Files are copied "as is" without any transformation. The copy is performed
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   546
    without extra checks. Callers are responsible for making sure the copied
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   547
    content is compatible with format of the destination repository.
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   548
    """
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   549
    oldrl = getattr(oldrl, '_revlog', oldrl)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   550
    newrl = _revlogfrompath(destrepo, unencodedname)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   551
    newrl = getattr(newrl, '_revlog', newrl)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   552
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   553
    oldvfs = oldrl.opener
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   554
    newvfs = newrl.opener
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   555
    oldindex = oldvfs.join(oldrl.indexfile)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   556
    newindex = newvfs.join(newrl.indexfile)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   557
    olddata = oldvfs.join(oldrl.datafile)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   558
    newdata = newvfs.join(newrl.datafile)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   559
42999
bb6902cbbe23 upgrade: create the correct destination directory for copies revlogs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42832
diff changeset
   560
    with newvfs(newrl.indexfile, 'w'):
bb6902cbbe23 upgrade: create the correct destination directory for copies revlogs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42832
diff changeset
   561
        pass # create all the directories
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   562
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   563
    util.copyfile(oldindex, newindex)
43000
164bbf674bb6 upgrade: also copy data file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42999
diff changeset
   564
    if oldrl.opener.exists(oldrl.datafile):
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   565
        util.copyfile(olddata, newdata)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   566
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   567
    if not (unencodedname.endswith('00changelog.i')
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   568
            or unencodedname.endswith('00manifest.i')):
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   569
        destrepo.svfs.fncache.add(unencodedname)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   570
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   571
UPGRADE_CHANGELOG = object()
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   572
UPGRADE_MANIFEST = object()
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   573
UPGRADE_FILELOG = object()
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   574
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   575
UPGRADE_ALL_REVLOGS = frozenset([UPGRADE_CHANGELOG,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   576
                                 UPGRADE_MANIFEST,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   577
                                 UPGRADE_FILELOG])
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   578
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   579
def matchrevlog(revlogfilter, entry):
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   580
    """check is a revlog is selected for cloning
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   581
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   582
    The store entry is checked against the passed filter"""
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   583
    if entry.endswith('00changelog.i'):
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   584
        return UPGRADE_CHANGELOG in revlogfilter
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   585
    elif entry.endswith('00manifest.i'):
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   586
        return UPGRADE_MANIFEST in revlogfilter
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   587
    return UPGRADE_FILELOG in revlogfilter
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   588
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   589
def _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   590
                  revlogs=UPGRADE_ALL_REVLOGS):
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   591
    """Copy revlogs between 2 repos."""
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   592
    revcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   593
    srcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   594
    srcrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   595
    dstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   596
    fcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   597
    frevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   598
    fsrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   599
    frawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   600
    fdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   601
    mcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   602
    mrevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   603
    msrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   604
    mrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   605
    mdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   606
    crevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   607
    csrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   608
    crawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   609
    cdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   610
42689
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   611
    alldatafiles = list(srcrepo.store.walk())
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   612
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   613
    # Perform a pass to collect metadata. This validates we can open all
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   614
    # source files and allows a unified progress bar to be displayed.
42689
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   615
    for unencoded, encoded, size in alldatafiles:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   616
        if unencoded.endswith('.d'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   617
            continue
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   618
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   619
        rl = _revlogfrompath(srcrepo, unencoded)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   620
39870
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   621
        info = rl.storageinfo(exclusivefiles=True, revisionscount=True,
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   622
                              trackedsize=True, storedsize=True)
39857
8dab7c8a93eb upgrade: report size of backing files, not internal storage size
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39546
diff changeset
   623
39870
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   624
        revcount += info['revisionscount'] or 0
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   625
        datasize = info['storedsize'] or 0
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   626
        rawsize = info['trackedsize'] or 0
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   627
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   628
        srcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   629
        srcrawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   630
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   631
        # This is for the separate progress bars.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   632
        if isinstance(rl, changelog.changelog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   633
            crevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   634
            csrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   635
            crawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   636
        elif isinstance(rl, manifest.manifestrevlog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   637
            mcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   638
            mrevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   639
            msrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   640
            mrawsize += rawsize
37444
c8666a9e9e11 upgrade: sniff for filelog type
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36373
diff changeset
   641
        elif isinstance(rl, filelog.filelog):
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   642
            fcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   643
            frevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   644
            fsrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   645
            frawsize += rawsize
37444
c8666a9e9e11 upgrade: sniff for filelog type
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36373
diff changeset
   646
        else:
c8666a9e9e11 upgrade: sniff for filelog type
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36373
diff changeset
   647
            error.ProgrammingError('unknown revlog type')
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   648
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   649
    if not revcount:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   650
        return
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   651
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   652
    ui.write(_('migrating %d total revisions (%d in filelogs, %d in manifests, '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   653
               '%d in changelog)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   654
             (revcount, frevcount, mrevcount, crevcount))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   655
    ui.write(_('migrating %s in store; %s tracked data\n') % (
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   656
             (util.bytecount(srcsize), util.bytecount(srcrawsize))))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   657
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   658
    # Used to keep track of progress.
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   659
    progress = None
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   660
    def oncopiedrevision(rl, rev, node):
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   661
        progress.increment()
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   662
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   663
    # Do the actual copying.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   664
    # FUTURE this operation can be farmed off to worker processes.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   665
    seen = set()
42689
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   666
    for unencoded, encoded, size in alldatafiles:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   667
        if unencoded.endswith('.d'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   668
            continue
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   669
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   670
        oldrl = _revlogfrompath(srcrepo, unencoded)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   671
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   672
        if isinstance(oldrl, changelog.changelog) and 'c' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   673
            ui.write(_('finished migrating %d manifest revisions across %d '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   674
                       'manifests; change in size: %s\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   675
                     (mrevcount, mcount, util.bytecount(mdstsize - msrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   676
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   677
            ui.write(_('migrating changelog containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   678
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   679
                     (crevcount, util.bytecount(csrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   680
                      util.bytecount(crawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   681
            seen.add('c')
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   682
            progress = srcrepo.ui.makeprogress(_('changelog revisions'),
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   683
                                               total=crevcount)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   684
        elif isinstance(oldrl, manifest.manifestrevlog) and 'm' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   685
            ui.write(_('finished migrating %d filelog revisions across %d '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   686
                       'filelogs; change in size: %s\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   687
                     (frevcount, fcount, util.bytecount(fdstsize - fsrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   688
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   689
            ui.write(_('migrating %d manifests containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   690
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   691
                     (mcount, mrevcount, util.bytecount(msrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   692
                      util.bytecount(mrawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   693
            seen.add('m')
38398
f273b768b60f upgrade: close progress after each revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38165
diff changeset
   694
            if progress:
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   695
                progress.complete()
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   696
            progress = srcrepo.ui.makeprogress(_('manifest revisions'),
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   697
                                               total=mrevcount)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   698
        elif 'f' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   699
            ui.write(_('migrating %d filelogs containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   700
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   701
                     (fcount, frevcount, util.bytecount(fsrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   702
                      util.bytecount(frawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   703
            seen.add('f')
38398
f273b768b60f upgrade: close progress after each revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38165
diff changeset
   704
            if progress:
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   705
                progress.complete()
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   706
            progress = srcrepo.ui.makeprogress(_('file revisions'),
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   707
                                               total=frevcount)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   708
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   709
        if matchrevlog(revlogs, unencoded):
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   710
            ui.note(_('cloning %d revisions from %s\n')
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   711
                    % (len(oldrl), unencoded))
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   712
            newrl = _revlogfrompath(dstrepo, unencoded)
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   713
            oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   714
                        deltareuse=deltareuse,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   715
                        forcedeltabothparents=forcedeltabothparents)
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   716
        else:
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   717
            msg = _('blindly copying %s containing %i revisions\n')
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   718
            ui.note(msg % (unencoded, len(oldrl)))
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   719
            _copyrevlog(tr, dstrepo, oldrl, unencoded)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   720
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   721
            newrl = _revlogfrompath(dstrepo, unencoded)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   722
39870
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   723
        info = newrl.storageinfo(storedsize=True)
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   724
        datasize = info['storedsize'] or 0
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   725
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   726
        dstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   727
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   728
        if isinstance(newrl, changelog.changelog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   729
            cdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   730
        elif isinstance(newrl, manifest.manifestrevlog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   731
            mdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   732
        else:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   733
            fdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   734
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   735
    progress.complete()
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   736
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   737
    ui.write(_('finished migrating %d changelog revisions; change in size: '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   738
               '%s\n') % (crevcount, util.bytecount(cdstsize - csrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   739
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   740
    ui.write(_('finished migrating %d total revisions; total change in store '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   741
               'size: %s\n') % (revcount, util.bytecount(dstsize - srcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   742
31873
d6c2005484b6 upgrade: drop the prefix to the '_filterstorefile' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31872
diff changeset
   743
def _filterstorefile(srcrepo, dstrepo, requirements, path, mode, st):
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   744
    """Determine whether to copy a store file during upgrade.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   745
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   746
    This function is called when migrating store files from ``srcrepo`` to
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   747
    ``dstrepo`` as part of upgrading a repository.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   748
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   749
    Args:
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   750
      srcrepo: repo we are copying from
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   751
      dstrepo: repo we are copying to
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   752
      requirements: set of requirements for ``dstrepo``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   753
      path: store file being examined
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   754
      mode: the ``ST_MODE`` file type of ``path``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   755
      st: ``stat`` data structure for ``path``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   756
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   757
    Function should return ``True`` if the file is to be copied.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   758
    """
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   759
    # Skip revlogs.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   760
    if path.endswith(('.i', '.d')):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   761
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   762
    # Skip transaction related files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   763
    if path.startswith('undo'):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   764
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   765
    # Only copy regular files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   766
    if mode != stat.S_IFREG:
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   767
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   768
    # Skip other skipped files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   769
    if path in ('lock', 'fncache'):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   770
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   771
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   772
    return True
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   773
31874
27ec6517e40e upgrade: drop the prefix to the '_finishdatamigration' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31873
diff changeset
   774
def _finishdatamigration(ui, srcrepo, dstrepo, requirements):
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   775
    """Hook point for extensions to perform additional actions during upgrade.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   776
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   777
    This function is called after revlogs and store files have been copied but
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   778
    before the new store is swapped into the original location.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   779
    """
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   780
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   781
def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions,
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   782
                 revlogs=UPGRADE_ALL_REVLOGS):
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   783
    """Do the low-level work of upgrading a repository.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   784
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   785
    The upgrade is effectively performed as a copy between a source
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   786
    repository and a temporary destination repository.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   787
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   788
    The source repository is unmodified for as long as possible so the
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   789
    upgrade can abort at any time without causing loss of service for
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   790
    readers and without corrupting the source repository.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   791
    """
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   792
    assert srcrepo.currentwlock()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   793
    assert dstrepo.currentwlock()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   794
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   795
    ui.write(_('(it is safe to interrupt this process any time before '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   796
               'data migration completes)\n'))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   797
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   798
    if 're-delta-all' in actions:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   799
        deltareuse = revlog.revlog.DELTAREUSENEVER
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   800
    elif 're-delta-parent' in actions:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   801
        deltareuse = revlog.revlog.DELTAREUSESAMEREVS
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   802
    elif 're-delta-multibase' in actions:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   803
        deltareuse = revlog.revlog.DELTAREUSESAMEREVS
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   804
    elif 're-delta-fulladd' in actions:
35345
6226668a7169 upgrade: add a 'redeltafullall' mode
Boris Feld <boris.feld@octobus.net>
parents: 35344
diff changeset
   805
        deltareuse = revlog.revlog.DELTAREUSEFULLADD
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   806
    else:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   807
        deltareuse = revlog.revlog.DELTAREUSEALWAYS
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   808
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   809
    with dstrepo.transaction('upgrade') as tr:
42690
095dcdd0d55c upgrade: rename `_copyrevlogs` to `_clonerevlogs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42689
diff changeset
   810
        _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse,
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   811
                      're-delta-multibase' in actions, revlogs=revlogs)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   812
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   813
    # Now copy other files in the store directory.
31797
0b913e1e725b repair: iterate store files deterministically
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30781
diff changeset
   814
    # The sorted() makes execution deterministic.
0b913e1e725b repair: iterate store files deterministically
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30781
diff changeset
   815
    for p, kind, st in sorted(srcrepo.store.vfs.readdir('', stat=True)):
31873
d6c2005484b6 upgrade: drop the prefix to the '_filterstorefile' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31872
diff changeset
   816
        if not _filterstorefile(srcrepo, dstrepo, requirements,
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   817
                                       p, kind, st):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   818
            continue
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   819
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   820
        srcrepo.ui.write(_('copying %s\n') % p)
31799
8110d49e0558 repair: use rawvfs when copying extra store files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31797
diff changeset
   821
        src = srcrepo.store.rawvfs.join(p)
8110d49e0558 repair: use rawvfs when copying extra store files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31797
diff changeset
   822
        dst = dstrepo.store.rawvfs.join(p)
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   823
        util.copyfile(src, dst, copystat=True)
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   824
31874
27ec6517e40e upgrade: drop the prefix to the '_finishdatamigration' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31873
diff changeset
   825
    _finishdatamigration(ui, srcrepo, dstrepo, requirements)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   826
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   827
    ui.write(_('data fully migrated to temporary repository\n'))
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   828
38165
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37444
diff changeset
   829
    backuppath = pycompat.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
31232
254f98326eef vfs: use 'vfs' module directly in 'mercurial.repair'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30975
diff changeset
   830
    backupvfs = vfsmod.vfs(backuppath)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   831
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   832
    # Make a backup of requires file first, as it is the first to be modified.
31324
e712a9c35fd8 repair: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31232
diff changeset
   833
    util.copyfile(srcrepo.vfs.join('requires'), backupvfs.join('requires'))
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   834
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   835
    # We install an arbitrary requirement that clients must not support
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   836
    # as a mechanism to lock out new clients during the data swap. This is
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   837
    # better than allowing a client to continue while the repository is in
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   838
    # an inconsistent state.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   839
    ui.write(_('marking source repository as being upgraded; clients will be '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   840
               'unable to read from repository\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   841
    scmutil.writerequires(srcrepo.vfs,
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32032
diff changeset
   842
                          srcrepo.requirements | {'upgradeinprogress'})
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   843
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   844
    ui.write(_('starting in-place swap of repository data\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   845
    ui.write(_('replaced files will be backed up at %s\n') %
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   846
             backuppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   847
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   848
    # Now swap in the new store directory. Doing it as a rename should make
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   849
    # the operation nearly instantaneous and atomic (at least in well-behaved
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   850
    # environments).
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   851
    ui.write(_('replacing store...\n'))
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30781
diff changeset
   852
    tstart = util.timer()
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   853
    util.rename(srcrepo.spath, backupvfs.join('store'))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   854
    util.rename(dstrepo.spath, srcrepo.spath)
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30781
diff changeset
   855
    elapsed = util.timer() - tstart
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   856
    ui.write(_('store replacement complete; repository was inconsistent for '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   857
               '%0.1fs\n') % elapsed)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   858
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   859
    # We first write the requirements file. Any new requirements will lock
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   860
    # out legacy clients.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   861
    ui.write(_('finalizing requirements file and making repository readable '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   862
               'again\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   863
    scmutil.writerequires(srcrepo.vfs, requirements)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   864
30781
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   865
    # The lock file from the old store won't be removed because nothing has a
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   866
    # reference to its new location. So clean it up manually. Alternatively, we
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   867
    # could update srcrepo.svfs and other variables to point to the new
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   868
    # location. This is simpler.
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   869
    backupvfs.unlink('store/lock')
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   870
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   871
    return backuppath
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   872
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   873
def upgraderepo(ui, repo, run=False, optimize=None, backup=True,
42831
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   874
                manifest=None, changelog=None):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   875
    """Upgrade a repository in place."""
41088
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   876
    if optimize is None:
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   877
        optimize = []
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 40997
diff changeset
   878
    optimize = set(legacy_opts_map.get(o, o) for o in optimize)
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   879
    repo = repo.unfiltered()
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   880
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   881
    revlogs = set(UPGRADE_ALL_REVLOGS)
42831
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   882
    specentries = (('c', changelog), ('m', manifest))
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   883
    specified = [(y, x) for (y, x) in specentries if x is not None]
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   884
    if specified:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   885
        # we have some limitation on revlogs to be recloned
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   886
        if any(x for y, x in specified):
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   887
            revlogs = set()
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   888
            for r, enabled in specified:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   889
                if enabled:
42831
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   890
                    if r == 'c':
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   891
                        revlogs.add(UPGRADE_CHANGELOG)
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   892
                    elif r == 'm':
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   893
                        revlogs.add(UPGRADE_MANIFEST)
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   894
        else:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   895
            # none are enabled
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   896
            for r, __ in specified:
42831
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   897
                if r == 'c':
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   898
                    revlogs.discard(UPGRADE_CHANGELOG)
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
   899
                elif r == 'm':
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   900
                    revlogs.discard(UPGRADE_MANIFEST)
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
   901
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   902
    # Ensure the repository can be upgraded.
31865
5dcaa0f4455b upgrade: drop the prefix to the 'requiredsourcerequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31864
diff changeset
   903
    missingreqs = requiredsourcerequirements(repo) - repo.requirements
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   904
    if missingreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   905
        raise error.Abort(_('cannot upgrade repository; requirement '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   906
                            'missing: %s') % _(', ').join(sorted(missingreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   907
31866
1454726b6d7c upgrade: drop the prefix to the 'blocksourcerequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31865
diff changeset
   908
    blockedreqs = blocksourcerequirements(repo) & repo.requirements
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   909
    if blockedreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   910
        raise error.Abort(_('cannot upgrade repository; unsupported source '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   911
                            'requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   912
                          _(', ').join(sorted(blockedreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   913
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   914
    # FUTURE there is potentially a need to control the wanted requirements via
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   915
    # command arguments or via an extension hook point.
39996
dbcb466d0065 localrepo: define storage backend in creation options (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39870
diff changeset
   916
    newreqs = localrepo.newreporequirements(
dbcb466d0065 localrepo: define storage backend in creation options (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39870
diff changeset
   917
        repo.ui, localrepo.defaultcreateopts(repo.ui))
35302
ad2b35ebf670 upgraderepo: allow extension to register preserved requirements
Boris Feld <boris.feld@octobus.net>
parents: 33438
diff changeset
   918
    newreqs.update(preservedrequirements(repo))
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   919
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   920
    noremovereqs = (repo.requirements - newreqs -
31867
cc60b6c36637 upgrade: drop the prefix to the 'supportremovedrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31866
diff changeset
   921
                   supportremovedrequirements(repo))
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   922
    if noremovereqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   923
        raise error.Abort(_('cannot upgrade repository; requirement would be '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   924
                            'removed: %s') % _(', ').join(sorted(noremovereqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   925
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   926
    noaddreqs = (newreqs - repo.requirements -
31869
fe5e30b58934 upgrade: drop the prefix to the 'allowednewrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31868
diff changeset
   927
                 allowednewrequirements(repo))
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   928
    if noaddreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   929
        raise error.Abort(_('cannot upgrade repository; do not support adding '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   930
                            'requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   931
                          _(', ').join(sorted(noaddreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   932
31870
49011f1cedd4 upgrade: drop the prefix to the 'supporteddestrequirements' function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31869
diff changeset
   933
    unsupportedreqs = newreqs - supporteddestrequirements(repo)
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   934
    if unsupportedreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   935
        raise error.Abort(_('cannot upgrade repository; do not support '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   936
                            'destination requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   937
                          _(', ').join(sorted(unsupportedreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   938
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   939
    # Find and validate all improvements that can be made.
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   940
    alloptimizations = findoptimizations(repo)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   941
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   942
    # Apply and Validate arguments.
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   943
    optimizations = []
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   944
    for o in alloptimizations:
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   945
        if o.name in optimize:
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   946
            optimizations.append(o)
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   947
            optimize.discard(o.name)
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   948
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   949
    if optimize: # anything left is unknown
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   950
        raise error.Abort(_('unknown optimization action requested: %s') %
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   951
                          ', '.join(sorted(optimize)),
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   952
                          hint=_('run without arguments to see valid '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   953
                                 'optimizations'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   954
31897
d0067250542d upgrade: simplify optimisations validation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31896
diff changeset
   955
    deficiencies = finddeficiencies(repo)
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   956
    actions = determineactions(repo, deficiencies, repo.requirements, newreqs)
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
   957
    actions.extend(o for o in sorted(optimizations)
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
   958
                   # determineactions could have added optimisation
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
   959
                   if o not in actions)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   960
42832
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   961
    removedreqs = repo.requirements - newreqs
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   962
    addedreqs = newreqs - repo.requirements
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   963
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   964
    if revlogs != UPGRADE_ALL_REVLOGS:
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   965
        incompatible = RECLONES_REQUIREMENTS & (removedreqs | addedreqs)
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   966
        if incompatible:
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   967
            msg = _('ignoring revlogs selection flags, format requirements '
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   968
                    'change: %s\n')
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   969
            ui.warn(msg % ', '.join(sorted(incompatible)))
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   970
            revlogs = UPGRADE_ALL_REVLOGS
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42831
diff changeset
   971
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   972
    def printrequirements():
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   973
        ui.write(_('requirements\n'))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   974
        ui.write(_('   preserved: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   975
                 _(', ').join(sorted(newreqs & repo.requirements)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   976
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   977
        if repo.requirements - newreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   978
            ui.write(_('   removed: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   979
                     _(', ').join(sorted(repo.requirements - newreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   980
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   981
        if newreqs - repo.requirements:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   982
            ui.write(_('   added: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   983
                     _(', ').join(sorted(newreqs - repo.requirements)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   984
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   985
        ui.write('\n')
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   986
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   987
    def printupgradeactions():
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
   988
        for a in actions:
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
   989
            ui.write('%s\n   %s\n\n' % (a.name, a.upgrademessage))
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   990
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   991
    if not run:
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   992
        fromconfig = []
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
   993
        onlydefault = []
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   994
31901
9bdedb050d8d upgrade: simplify some of the initial dispatch for dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31900
diff changeset
   995
        for d in deficiencies:
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   996
            if d.fromconfig(repo):
31901
9bdedb050d8d upgrade: simplify some of the initial dispatch for dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31900
diff changeset
   997
                fromconfig.append(d)
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
   998
            elif d.default:
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
   999
                onlydefault.append(d)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1000
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
  1001
        if fromconfig or onlydefault:
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1002
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1003
            if fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1004
                ui.write(_('repository lacks features recommended by '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1005
                           'current config options:\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1006
                for i in fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1007
                    ui.write('%s\n   %s\n\n' % (i.name, i.description))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1008
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1009
            if onlydefault:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1010
                ui.write(_('repository lacks features used by the default '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1011
                           'config options:\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1012
                for i in onlydefault:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1013
                    ui.write('%s\n   %s\n\n' % (i.name, i.description))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1014
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1015
            ui.write('\n')
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1016
        else:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1017
            ui.write(_('(no feature deficiencies found in existing '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1018
                       'repository)\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1019
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1020
        ui.write(_('performing an upgrade with "--run" will make the following '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1021
                   'changes:\n\n'))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1022
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1023
        printrequirements()
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1024
        printupgradeactions()
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1025
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
  1026
        unusedoptimize = [i for i in alloptimizations if i not in actions]
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
  1027
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1028
        if unusedoptimize:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1029
            ui.write(_('additional optimizations are available by specifying '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1030
                     '"--optimize <name>":\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1031
            for i in unusedoptimize:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1032
                ui.write(_('%s\n   %s\n\n') % (i.name, i.description))
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1033
        return
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1034
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1035
    # Else we're in the run=true case.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1036
    ui.write(_('upgrade will perform the following actions:\n\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1037
    printrequirements()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1038
    printupgradeactions()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1039
31903
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
  1040
    upgradeactions = [a.name for a in actions]
fa1088de2119 upgrade: use 'improvement' object for action too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31902
diff changeset
  1041
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1042
    ui.write(_('beginning upgrade...\n'))
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1043
    with repo.wlock(), repo.lock():
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1044
        ui.write(_('repository locked and read-only\n'))
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1045
        # Our strategy for upgrading the repository is to create a new,
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1046
        # temporary repository, write data to it, then do a swap of the
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1047
        # data. There are less heavyweight ways to do this, but it is easier
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1048
        # to create a new repo object than to instantiate all the components
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1049
        # (like the store) separately.
38165
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37444
diff changeset
  1050
        tmppath = pycompat.mkdtemp(prefix='upgrade.', dir=repo.path)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1051
        backuppath = None
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1052
        try:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1053
            ui.write(_('creating temporary repository to stage migrated '
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1054
                       'data: %s\n') % tmppath)
35342
75520786ad2f upgrade: use the repository 'ui' as the base for the new repository
Boris Feld <boris.feld@octobus.net>
parents: 35340
diff changeset
  1055
35379
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35345
diff changeset
  1056
            # clone ui without using ui.copy because repo.ui is protected
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35345
diff changeset
  1057
            repoui = repo.ui.__class__(repo.ui)
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35345
diff changeset
  1058
            dstrepo = hg.repository(repoui, path=tmppath, create=True)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1059
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1060
            with dstrepo.wlock(), dstrepo.lock():
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1061
                backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42693
diff changeset
  1062
                                          upgradeactions, revlogs=revlogs)
41089
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41088
diff changeset
  1063
            if not (backup or backuppath is None):
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41088
diff changeset
  1064
                ui.write(_('removing old repository content%s\n') % backuppath)
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41088
diff changeset
  1065
                repo.vfs.rmtree(backuppath, forcibly=True)
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41088
diff changeset
  1066
                backuppath = None
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1067
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1068
        finally:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1069
            ui.write(_('removing temporary repository %s\n') % tmppath)
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1070
            repo.vfs.rmtree(tmppath, forcibly=True)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1071
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1072
            if backuppath:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1073
                ui.warn(_('copy of old repository backed up at %s\n') %
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1074
                        backuppath)
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1075
                ui.warn(_('the old repository will not be deleted; remove '
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1076
                          'it to free up disk space once the upgraded '
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32291
diff changeset
  1077
                          'repository is verified\n'))