mercurial/upgrade_utils/engine.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 17 Feb 2022 06:32:03 +0100
changeset 48790 5ba24e886cec
parent 48437 6e4999cb085e
child 48793 6e559391f96e
permissions -rw-r--r--
tracked-key: make it possible to upgrade to and downgrade from the feature This seems rather important if we want people to start using it. Differential Revision: https://phab.mercurial-scm.org/D12198
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
48437
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
    10
import errno
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
    11
import stat
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
46046
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46035
diff changeset
    13
from ..i18n import _
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46035
diff changeset
    14
from ..pycompat import getattr
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46035
diff changeset
    15
from .. import (
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    16
    changelog,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26425
diff changeset
    17
    error,
35344
8f3f8b8dbab7 upgrade: use actual filelog to convert filelog
Boris Feld <boris.feld@octobus.net>
parents: 35343
diff changeset
    18
    filelog,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    19
    manifest,
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44841
diff changeset
    20
    metadata,
38165
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37444
diff changeset
    21
    pycompat,
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45371
diff changeset
    22
    requirements,
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
    23
    scmutil,
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    24
    store,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    25
    util,
31232
254f98326eef vfs: use 'vfs' module directly in 'mercurial.repair'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30975
diff changeset
    26
    vfs as vfsmod,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    27
)
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    28
from ..revlogutils import (
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    29
    constants as revlogconst,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    30
    flagutil,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    31
    nodemap,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    32
    sidedata as sidedatamod,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    33
)
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
    34
from . import actions as upgrade_actions
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    35
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    36
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    37
def get_sidedata_helpers(srcrepo, dstrepo):
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    38
    use_w = srcrepo.ui.configbool(b'experimental', b'worker.repository-upgrade')
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    39
    sequential = pycompat.iswindows or not use_w
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    40
    if not sequential:
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    41
        srcrepo.register_sidedata_computer(
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    42
            revlogconst.KIND_CHANGELOG,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    43
            sidedatamod.SD_FILES,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    44
            (sidedatamod.SD_FILES,),
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    45
            metadata._get_worker_sidedata_adder(srcrepo, dstrepo),
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    46
            flagutil.REVIDX_HASCOPIESINFO,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    47
            replace=True,
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
    48
        )
47085
3aab2330b7d3 sidedata: move sidedata-related utils to the dedicated module
Raphaël Gomès <rgomes@octobus.net>
parents: 47084
diff changeset
    49
    return sidedatamod.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    50
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
    51
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    52
def _revlogfrompath(repo, rl_type, path):
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    53
    """Obtain a revlog from a repo path.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    54
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    55
    An instance of the appropriate class is returned.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    56
    """
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    57
    if rl_type & store.FILEFLAGS_CHANGELOG:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    58
        return changelog.changelog(repo.svfs)
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    59
    elif rl_type & store.FILEFLAGS_MANIFESTLOG:
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    60
        mandir = b''
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    61
        if b'/' in path:
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    62
            mandir = path.rsplit(b'/', 1)[0]
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46526
diff changeset
    63
        return manifest.manifestrevlog(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46526
diff changeset
    64
            repo.nodeconstants, repo.svfs, tree=mandir
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46526
diff changeset
    65
        )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    66
    else:
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    67
        # drop the extension and the `data/` prefix
47660
aa2296893168 upgrade: avoid a traceback in case of unrecognized revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47659
diff changeset
    68
        path_part = path.rsplit(b'.', 1)[0].split(b'/', 1)
aa2296893168 upgrade: avoid a traceback in case of unrecognized revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47659
diff changeset
    69
        if len(path_part) < 2:
47764
6b9ad3a0c348 upgrade: byteify an i18n message
Matt Harbison <matt_harbison@yahoo.com>
parents: 47674
diff changeset
    70
            msg = _(b'cannot recognize revlog from filename: %s')
47660
aa2296893168 upgrade: avoid a traceback in case of unrecognized revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47659
diff changeset
    71
            msg %= path
aa2296893168 upgrade: avoid a traceback in case of unrecognized revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47659
diff changeset
    72
            raise error.Abort(msg)
aa2296893168 upgrade: avoid a traceback in case of unrecognized revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47659
diff changeset
    73
        path = path_part[1]
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    74
        return filelog.filelog(repo.svfs, path)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    75
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
    76
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    77
def _copyrevlog(tr, destrepo, oldrl, rl_type, unencodedname):
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    78
    """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
    79
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    80
    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
    81
    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
    82
    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
    83
    """
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    84
    oldrl = getattr(oldrl, '_revlog', oldrl)
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
    85
    newrl = _revlogfrompath(destrepo, rl_type, unencodedname)
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    86
    newrl = getattr(newrl, '_revlog', newrl)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    87
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    88
    oldvfs = oldrl.opener
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    89
    newvfs = newrl.opener
47148
a07d5cb03a85 revlog: rename `indexfile` to `_indexfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47128
diff changeset
    90
    oldindex = oldvfs.join(oldrl._indexfile)
a07d5cb03a85 revlog: rename `indexfile` to `_indexfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47128
diff changeset
    91
    newindex = newvfs.join(newrl._indexfile)
47149
396442cd7e6a revlog: rename `datafile` to `datafile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
    92
    olddata = oldvfs.join(oldrl._datafile)
396442cd7e6a revlog: rename `datafile` to `datafile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
    93
    newdata = newvfs.join(newrl._datafile)
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    94
47148
a07d5cb03a85 revlog: rename `indexfile` to `_indexfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47128
diff changeset
    95
    with newvfs(newrl._indexfile, b'w'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
    96
        pass  # create all the directories
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    97
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
    98
    util.copyfile(oldindex, newindex)
47149
396442cd7e6a revlog: rename `datafile` to `datafile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
    99
    copydata = oldrl.opener.exists(oldrl._datafile)
43002
373749982924 upgrade: also register copied `.d` files to fncache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43000
diff changeset
   100
    if copydata:
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   101
        util.copyfile(olddata, newdata)
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   102
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   103
    if rl_type & store.FILEFLAGS_FILELOG:
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   104
        destrepo.svfs.fncache.add(unencodedname)
43002
373749982924 upgrade: also register copied `.d` files to fncache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43000
diff changeset
   105
        if copydata:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   106
            destrepo.svfs.fncache.add(unencodedname[:-2] + b'.d')
42691
5535a2201ff1 upgrade: introduce a _copyrevlog method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42690
diff changeset
   107
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   108
46035
6c960b708ac4 upgrade: display the list of processed revlog before proceeding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46003
diff changeset
   109
UPGRADE_CHANGELOG = b"changelog"
6c960b708ac4 upgrade: display the list of processed revlog before proceeding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46003
diff changeset
   110
UPGRADE_MANIFEST = b"manifest"
6c960b708ac4 upgrade: display the list of processed revlog before proceeding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46003
diff changeset
   111
UPGRADE_FILELOGS = b"all-filelogs"
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   112
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   113
UPGRADE_ALL_REVLOGS = frozenset(
45980
fe7d7917ceb5 upgrade: rename UPGRADE_FILELOG to UPGRADE_FILELOGS
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45735
diff changeset
   114
    [UPGRADE_CHANGELOG, UPGRADE_MANIFEST, UPGRADE_FILELOGS]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   115
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   116
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   117
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   118
def matchrevlog(revlogfilter, rl_type):
45694
d1c10d33a85c upgrade: improve documentation of matchrevlog()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45487
diff changeset
   119
    """check if a revlog is selected for cloning.
d1c10d33a85c upgrade: improve documentation of matchrevlog()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45487
diff changeset
   120
d1c10d33a85c upgrade: improve documentation of matchrevlog()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45487
diff changeset
   121
    In other words, are there any updates which need to be done on revlog
d1c10d33a85c upgrade: improve documentation of matchrevlog()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45487
diff changeset
   122
    or it can be blindly copied.
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   123
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   124
    The store entry is checked against the passed filter"""
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   125
    if rl_type & store.FILEFLAGS_CHANGELOG:
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   126
        return UPGRADE_CHANGELOG in revlogfilter
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   127
    elif rl_type & store.FILEFLAGS_MANIFESTLOG:
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   128
        return UPGRADE_MANIFEST in revlogfilter
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   129
    assert rl_type & store.FILEFLAGS_FILELOG
45980
fe7d7917ceb5 upgrade: rename UPGRADE_FILELOG to UPGRADE_FILELOGS
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45735
diff changeset
   130
    return UPGRADE_FILELOGS in revlogfilter
42693
0812d9fb63fe upgrade: introduce the internal code for revlog cloning selection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42691
diff changeset
   131
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   132
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   133
def _perform_clone(
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   134
    ui,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   135
    dstrepo,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   136
    tr,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   137
    old_revlog,
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   138
    rl_type,
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   139
    unencoded,
46217
02df91e895bd engine: pass upgrade operation inside `_perform_clone()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46216
diff changeset
   140
    upgrade_op,
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   141
    sidedata_helpers,
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   142
    oncopiedrevision,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   143
):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 46897
diff changeset
   144
    """returns the new revlog object created"""
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   145
    newrl = None
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   146
    if matchrevlog(upgrade_op.revlogs_to_process, rl_type):
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   147
        ui.note(
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   148
            _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   149
        )
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   150
        newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   151
        old_revlog.clone(
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   152
            tr,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   153
            newrl,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   154
            addrevisioncb=oncopiedrevision,
46217
02df91e895bd engine: pass upgrade operation inside `_perform_clone()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46216
diff changeset
   155
            deltareuse=upgrade_op.delta_reuse_mode,
46218
3f92a9bb80f0 engine: prevent multiple checking of re-delta-multibase
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46217
diff changeset
   156
            forcedeltabothparents=upgrade_op.force_re_delta_both_parents,
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   157
            sidedata_helpers=sidedata_helpers,
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   158
        )
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   159
    else:
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   160
        msg = _(b'blindly copying %s containing %i revisions\n')
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   161
        ui.note(msg % (unencoded, len(old_revlog)))
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   162
        _copyrevlog(tr, dstrepo, old_revlog, rl_type, unencoded)
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   163
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   164
        newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   165
    return newrl
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   166
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   167
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   168
def _clonerevlogs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   169
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   170
    srcrepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   171
    dstrepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   172
    tr,
46216
34efa84a43a1 engine: pass upgrade operation inside _clonerevlogs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46215
diff changeset
   173
    upgrade_op,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   174
):
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   175
    """Copy revlogs between 2 repos."""
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   176
    revcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   177
    srcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   178
    srcrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   179
    dstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   180
    fcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   181
    frevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   182
    fsrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   183
    frawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   184
    fdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   185
    mcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   186
    mrevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   187
    msrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   188
    mrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   189
    mdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   190
    crevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   191
    csrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   192
    crawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   193
    cdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   194
42689
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   195
    alldatafiles = list(srcrepo.store.walk())
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   196
    # mapping of data files which needs to be cloned
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   197
    # key is unencoded filename
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   198
    # value is revlog_object_from_srcrepo
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   199
    manifests = {}
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   200
    changelogs = {}
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   201
    filelogs = {}
42689
896fb9deeaf8 upgrade: walk the source store file only once
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42137
diff changeset
   202
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   203
    # 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
   204
    # source files and allows a unified progress bar to be displayed.
47877
2174f54aab18 store: return just one filename in walk functions
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47764
diff changeset
   205
    for rl_type, unencoded, size in alldatafiles:
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   206
        if not rl_type & store.FILEFLAGS_REVLOG_MAIN:
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   207
            continue
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   208
47659
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   209
        # the store.walk function will wrongly pickup transaction backup and
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   210
        # get confused. As a quick fix for 5.9 release, we ignore those.
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   211
        # (this is not a module constants because it seems better to keep the
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   212
        # hack together)
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   213
        skip_undo = (
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   214
            b'undo.backup.00changelog.i',
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   215
            b'undo.backup.00manifest.i',
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   216
        )
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   217
        if unencoded in skip_undo:
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   218
            continue
f030c7d22032 walk: no longer ignore revlogs of files starting with `undo.` (issue6542)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47320
diff changeset
   219
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   220
        rl = _revlogfrompath(srcrepo, rl_type, unencoded)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   221
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   222
        info = rl.storageinfo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   223
            exclusivefiles=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   224
            revisionscount=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   225
            trackedsize=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   226
            storedsize=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   227
        )
39857
8dab7c8a93eb upgrade: report size of backing files, not internal storage size
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39546
diff changeset
   228
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   229
        revcount += info[b'revisionscount'] or 0
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   230
        datasize = info[b'storedsize'] or 0
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   231
        rawsize = info[b'trackedsize'] or 0
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   232
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   233
        srcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   234
        srcrawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   235
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   236
        # This is for the separate progress bars.
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   237
        if rl_type & store.FILEFLAGS_CHANGELOG:
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   238
            changelogs[unencoded] = (rl_type, rl)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   239
            crevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   240
            csrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   241
            crawsize += rawsize
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   242
        elif rl_type & store.FILEFLAGS_MANIFESTLOG:
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   243
            manifests[unencoded] = (rl_type, rl)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   244
            mcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   245
            mrevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   246
            msrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   247
            mrawsize += rawsize
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   248
        elif rl_type & store.FILEFLAGS_FILELOG:
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   249
            filelogs[unencoded] = (rl_type, rl)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   250
            fcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   251
            frevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   252
            fsrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   253
            frawsize += rawsize
37444
c8666a9e9e11 upgrade: sniff for filelog type
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36373
diff changeset
   254
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   255
            error.ProgrammingError(b'unknown revlog type')
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   256
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   257
    if not revcount:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   258
        return
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   259
44798
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44797
diff changeset
   260
    ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   261
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   262
            b'migrating %d total revisions (%d in filelogs, %d in manifests, '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   263
            b'%d in changelog)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   264
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   265
        % (revcount, frevcount, mrevcount, crevcount)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   266
    )
44798
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44797
diff changeset
   267
    ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   268
        _(b'migrating %s in store; %s tracked data\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   269
        % ((util.bytecount(srcsize), util.bytecount(srcrawsize)))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   270
    )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   271
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   272
    # Used to keep track of progress.
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   273
    progress = None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   274
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   275
    def oncopiedrevision(rl, rev, node):
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   276
        progress.increment()
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   277
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   278
    sidedata_helpers = get_sidedata_helpers(srcrepo, dstrepo)
43134
75ad8af9c95e upgrade: allow upgrade to repository using sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
   279
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   280
    # Migrating filelogs
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   281
    ui.status(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   282
        _(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   283
            b'migrating %d filelogs containing %d revisions '
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   284
            b'(%s in store; %s tracked data)\n'
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   285
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   286
        % (
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   287
            fcount,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   288
            frevcount,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   289
            util.bytecount(fsrcsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   290
            util.bytecount(frawsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   291
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   292
    )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   293
    progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount)
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   294
    for unencoded, (rl_type, oldrl) in sorted(filelogs.items()):
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   295
        newrl = _perform_clone(
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   296
            ui,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   297
            dstrepo,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   298
            tr,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   299
            oldrl,
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   300
            rl_type,
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   301
            unencoded,
46217
02df91e895bd engine: pass upgrade operation inside `_perform_clone()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46216
diff changeset
   302
            upgrade_op,
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   303
            sidedata_helpers,
46193
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   304
            oncopiedrevision,
85f7cf314b39 engine: refactor actual cloning code into separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
   305
        )
39870
b399ff55ee6d upgrade: use storageinfo() for obtaining storage metadata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39859
diff changeset
   306
        info = newrl.storageinfo(storedsize=True)
46214
5dfa837d933e engine: refactor how total dstsize is calculated
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
   307
        fdstsize += info[b'storedsize'] or 0
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   308
    ui.status(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   309
        _(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   310
            b'finished migrating %d filelog revisions across %d '
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   311
            b'filelogs; change in size: %s\n'
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   312
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   313
        % (frevcount, fcount, util.bytecount(fdstsize - fsrcsize))
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   314
    )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   315
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   316
    # Migrating manifests
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   317
    ui.status(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   318
        _(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   319
            b'migrating %d manifests containing %d revisions '
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   320
            b'(%s in store; %s tracked data)\n'
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   321
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   322
        % (
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   323
            mcount,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   324
            mrevcount,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   325
            util.bytecount(msrcsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   326
            util.bytecount(mrawsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   327
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   328
    )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   329
    if progress:
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   330
        progress.complete()
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   331
    progress = srcrepo.ui.makeprogress(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   332
        _(b'manifest revisions'), total=mrevcount
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   333
    )
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   334
    for unencoded, (rl_type, oldrl) in sorted(manifests.items()):
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   335
        newrl = _perform_clone(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   336
            ui,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   337
            dstrepo,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   338
            tr,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   339
            oldrl,
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   340
            rl_type,
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   341
            unencoded,
46217
02df91e895bd engine: pass upgrade operation inside `_perform_clone()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46216
diff changeset
   342
            upgrade_op,
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   343
            sidedata_helpers,
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   344
            oncopiedrevision,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   345
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   346
        info = newrl.storageinfo(storedsize=True)
46214
5dfa837d933e engine: refactor how total dstsize is calculated
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
   347
        mdstsize += info[b'storedsize'] or 0
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   348
    ui.status(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   349
        _(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   350
            b'finished migrating %d manifest revisions across %d '
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   351
            b'manifests; change in size: %s\n'
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   352
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   353
        % (mrevcount, mcount, util.bytecount(mdstsize - msrcsize))
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   354
    )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   355
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   356
    # Migrating changelog
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   357
    ui.status(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   358
        _(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   359
            b'migrating changelog containing %d revisions '
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   360
            b'(%s in store; %s tracked data)\n'
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   361
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   362
        % (
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   363
            crevcount,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   364
            util.bytecount(csrcsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   365
            util.bytecount(crawsize),
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   366
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   367
    )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   368
    if progress:
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   369
        progress.complete()
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   370
    progress = srcrepo.ui.makeprogress(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   371
        _(b'changelog revisions'), total=crevcount
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   372
    )
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   373
    for unencoded, (rl_type, oldrl) in sorted(changelogs.items()):
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   374
        newrl = _perform_clone(
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   375
            ui,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   376
            dstrepo,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   377
            tr,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   378
            oldrl,
46896
cf49e54ef965 upgrade: take advantage of the new information returned by `store.walk`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46895
diff changeset
   379
            rl_type,
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   380
            unencoded,
46217
02df91e895bd engine: pass upgrade operation inside `_perform_clone()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46216
diff changeset
   381
            upgrade_op,
47084
27f1191b1305 sidedata: replace sidedata upgrade mechanism with the new one
Raphaël Gomès <rgomes@octobus.net>
parents: 46897
diff changeset
   382
            sidedata_helpers,
46194
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   383
            oncopiedrevision,
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   384
        )
4d1cec4e5e1f engine: unwrap a hard to understand for loop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46193
diff changeset
   385
        info = newrl.storageinfo(storedsize=True)
46214
5dfa837d933e engine: refactor how total dstsize is calculated
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
   386
        cdstsize += info[b'storedsize'] or 0
38399
185588cb0c4b upgrade: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
   387
    progress.complete()
44798
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44797
diff changeset
   388
    ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   389
        _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   390
            b'finished migrating %d changelog revisions; change in size: '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   391
            b'%s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   392
        )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   393
        % (crevcount, util.bytecount(cdstsize - csrcsize))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   394
    )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   395
46214
5dfa837d933e engine: refactor how total dstsize is calculated
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
   396
    dstsize = fdstsize + mdstsize + cdstsize
44798
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44797
diff changeset
   397
    ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   398
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   399
            b'finished migrating %d total revisions; total change in store '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   400
            b'size: %s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   401
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   402
        % (revcount, util.bytecount(dstsize - srcsize))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   403
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   404
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   405
46229
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   406
def _files_to_copy_post_revlog_clone(srcrepo):
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   407
    """yields files which should be copied to destination after revlogs
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   408
    are cloned"""
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   409
    for path, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   410
        # don't copy revlogs as they are already cloned
46897
1c52d77d7861 upgrade: do not hardcore file extension of revlogs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46896
diff changeset
   411
        if store.revlog_type(path) is not None:
46229
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   412
            continue
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   413
        # Skip transaction related files.
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   414
        if path.startswith(b'undo'):
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   415
            continue
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   416
        # Only copy regular files.
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   417
        if kind != stat.S_IFREG:
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   418
            continue
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   419
        # Skip other skipped files.
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   420
        if path in (b'lock', b'fncache'):
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   421
            continue
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   422
        # TODO: should we skip cache too?
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   423
46229
52abb1af2995 engine: prevent a function call for each store file
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
   424
        yield path
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   425
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   426
46220
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   427
def _replacestores(currentrepo, upgradedrepo, backupvfs, upgrade_op):
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   428
    """Replace the stores after current repository is upgraded
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   429
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   430
    Creates a backup of current repository store at backup path
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   431
    Replaces upgraded store files in current repo from upgraded one
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   432
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   433
    Arguments:
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   434
      currentrepo: repo object of current repository
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   435
      upgradedrepo: repo object of the upgraded data
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   436
      backupvfs: vfs object for the backup path
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   437
      upgrade_op: upgrade operation object
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   438
                  to be used to decide what all is upgraded
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   439
    """
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   440
    # TODO: don't blindly rename everything in store
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   441
    # There can be upgrades where store is not touched at all
46375
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   442
    if upgrade_op.backup_store:
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   443
        util.rename(currentrepo.spath, backupvfs.join(b'store'))
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   444
    else:
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   445
        currentrepo.vfs.rmtree(b'store', forcibly=True)
46220
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   446
    util.rename(upgradedrepo.spath, currentrepo.spath)
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   447
1ca7865c245d engine: refactor code to replace stores in separate function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46219
diff changeset
   448
46219
481d9aed669c engine: make hook point for extension a public function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46218
diff changeset
   449
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
   450
    """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
   451
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   452
    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
   453
    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
   454
    """
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   455
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   456
46056
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46046
diff changeset
   457
def upgrade(ui, srcrepo, dstrepo, upgrade_op):
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   458
    """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
   459
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   460
    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
   461
    repository and a temporary destination repository.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   462
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   463
    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
   464
    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
   465
    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
   466
    """
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   467
    assert srcrepo.currentwlock()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   468
    assert dstrepo.currentwlock()
46375
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   469
    backuppath = None
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   470
    backupvfs = None
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   471
44798
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44797
diff changeset
   472
    ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   473
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   474
            b'(it is safe to interrupt this process any time before '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   475
            b'data migration completes)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   476
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   477
    )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   478
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   479
    if upgrade_actions.dirstatev2 in upgrade_op.upgrade_actions:
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   480
        ui.status(_(b'upgrading to dirstate-v2 from v1\n'))
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   481
        upgrade_dirstate(ui, srcrepo, upgrade_op, b'v1', b'v2')
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   482
        upgrade_op.upgrade_actions.remove(upgrade_actions.dirstatev2)
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   483
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   484
    if upgrade_actions.dirstatev2 in upgrade_op.removed_actions:
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   485
        ui.status(_(b'downgrading from dirstate-v2 to v1\n'))
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   486
        upgrade_dirstate(ui, srcrepo, upgrade_op, b'v2', b'v1')
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   487
        upgrade_op.removed_actions.remove(upgrade_actions.dirstatev2)
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   488
48790
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   489
    if upgrade_actions.dirstatetrackedkey in upgrade_op.upgrade_actions:
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   490
        ui.status(_(b'create dirstate-tracked-key file\n'))
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   491
        upgrade_tracked_key(ui, srcrepo, upgrade_op, add=True)
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   492
        upgrade_op.upgrade_actions.remove(upgrade_actions.dirstatetrackedkey)
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   493
    elif upgrade_actions.dirstatetrackedkey in upgrade_op.removed_actions:
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   494
        ui.status(_(b'remove dirstate-tracked-key file\n'))
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   495
        upgrade_tracked_key(ui, srcrepo, upgrade_op, add=False)
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   496
        upgrade_op.removed_actions.remove(upgrade_actions.dirstatetrackedkey)
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   497
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   498
    if not (upgrade_op.upgrade_actions or upgrade_op.removed_actions):
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   499
        return
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   500
46467
45c3a263d5d1 engine: 'if not, else' -> 'if, else'
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46380
diff changeset
   501
    if upgrade_op.requirements_only:
45c3a263d5d1 engine: 'if not, else' -> 'if, else'
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46380
diff changeset
   502
        ui.status(_(b'upgrading repository requirements\n'))
45c3a263d5d1 engine: 'if not, else' -> 'if, else'
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46380
diff changeset
   503
        scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
46472
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   504
    # if there is only one action and that is persistent nodemap upgrade
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   505
    # directly write the nodemap file and update requirements instead of going
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   506
    # through the whole cloning process
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   507
    elif (
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   508
        len(upgrade_op.upgrade_actions) == 1
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   509
        and b'persistent-nodemap' in upgrade_op.upgrade_actions_names
46472
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   510
        and not upgrade_op.removed_actions
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   511
    ):
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   512
        ui.status(
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   513
            _(b'upgrading repository to use persistent nodemap feature\n')
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   514
        )
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   515
        with srcrepo.transaction(b'upgrade') as tr:
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   516
            unfi = srcrepo.unfiltered()
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   517
            cl = unfi.changelog
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   518
            nodemap.persist_nodemap(tr, cl, force=True)
46525
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   519
            # we want to directly operate on the underlying revlog to force
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   520
            # create a nodemap file. This is fine since this is upgrade code
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   521
            # and it heavily relies on repository being revlog based
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   522
            # hence accessing private attributes can be justified
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   523
            nodemap.persist_nodemap(
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   524
                tr, unfi.manifestlog._rootstore._revlog, force=True
636853347e14 upgrade: write nodemap for manifests too
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46472
diff changeset
   525
            )
46472
98e39f04d60e upgrade: implement partial upgrade for upgrading persistent-nodemap
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46467
diff changeset
   526
        scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
46526
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   527
    elif (
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   528
        len(upgrade_op.removed_actions) == 1
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   529
        and [
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   530
            x
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   531
            for x in upgrade_op.removed_actions
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   532
            if x.name == b'persistent-nodemap'
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   533
        ]
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   534
        and not upgrade_op.upgrade_actions
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   535
    ):
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   536
        ui.status(
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   537
            _(b'downgrading repository to not use persistent nodemap feature\n')
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   538
        )
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   539
        with srcrepo.transaction(b'upgrade') as tr:
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   540
            unfi = srcrepo.unfiltered()
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   541
            cl = unfi.changelog
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   542
            nodemap.delete_nodemap(tr, srcrepo, cl)
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   543
            # check comment 20 lines above for accessing private attributes
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   544
            nodemap.delete_nodemap(
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   545
                tr, srcrepo, unfi.manifestlog._rootstore._revlog
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   546
            )
67b5fafd3a46 upgrade: speed up when we have only nodemap to downgrade
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46525
diff changeset
   547
        scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
46467
45c3a263d5d1 engine: 'if not, else' -> 'if, else'
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46380
diff changeset
   548
    else:
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   549
        with dstrepo.transaction(b'upgrade') as tr:
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   550
            _clonerevlogs(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   551
                ui,
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   552
                srcrepo,
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   553
                dstrepo,
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   554
                tr,
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   555
                upgrade_op,
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   556
            )
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   557
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   558
        # Now copy other files in the store directory.
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   559
        for p in _files_to_copy_post_revlog_clone(srcrepo):
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   560
            srcrepo.ui.status(_(b'copying %s\n') % p)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   561
            src = srcrepo.store.rawvfs.join(p)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   562
            dst = dstrepo.store.rawvfs.join(p)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   563
            util.copyfile(src, dst, copystat=True)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   564
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   565
        finishdatamigration(ui, srcrepo, dstrepo, requirements)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   566
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   567
        ui.status(_(b'data fully upgraded in a temporary repository\n'))
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   568
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   569
        if upgrade_op.backup_store:
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   570
            backuppath = pycompat.mkdtemp(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   571
                prefix=b'upgradebackup.', dir=srcrepo.path
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   572
            )
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   573
            backupvfs = vfsmod.vfs(backuppath)
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   574
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   575
            # Make a backup of requires file first, as it is the first to be modified.
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   576
            util.copyfile(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   577
                srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   578
            )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   579
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   580
        # We install an arbitrary requirement that clients must not support
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   581
        # as a mechanism to lock out new clients during the data swap. This is
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   582
        # better than allowing a client to continue while the repository is in
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   583
        # an inconsistent state.
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   584
        ui.status(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   585
            _(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   586
                b'marking source repository as being upgraded; clients will be '
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   587
                b'unable to read from repository\n'
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   588
            )
46375
2e8a844d0ae0 upgrade: don't create store backup if `--no-backup` is passed
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46252
diff changeset
   589
        )
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   590
        scmutil.writereporequirements(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   591
            srcrepo, srcrepo.requirements | {b'upgradeinprogress'}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   592
        )
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   593
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   594
        ui.status(_(b'starting in-place swap of repository data\n'))
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   595
        if upgrade_op.backup_store:
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   596
            ui.status(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   597
                _(b'replaced files will be backed up at %s\n') % backuppath
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   598
            )
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   599
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   600
        # Now swap in the new store directory. Doing it as a rename should make
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   601
        # the operation nearly instantaneous and atomic (at least in well-behaved
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   602
        # environments).
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   603
        ui.status(_(b'replacing store...\n'))
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   604
        tstart = util.timer()
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   605
        _replacestores(srcrepo, dstrepo, backupvfs, upgrade_op)
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   606
        elapsed = util.timer() - tstart
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   607
        ui.status(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   608
            _(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   609
                b'store replacement complete; repository was inconsistent for '
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   610
                b'%0.1fs\n'
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   611
            )
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   612
            % elapsed
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   613
        )
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   614
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   615
        # We first write the requirements file. Any new requirements will lock
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   616
        # out legacy clients.
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   617
        ui.status(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   618
            _(
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   619
                b'finalizing requirements file and making repository readable '
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   620
                b'again\n'
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   621
            )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
   622
        )
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   623
        scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   624
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   625
        if upgrade_op.backup_store:
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   626
            # The lock file from the old store won't be removed because nothing has a
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   627
            # reference to its new location. So clean it up manually. Alternatively, we
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   628
            # could update srcrepo.svfs and other variables to point to the new
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   629
            # location. This is simpler.
46794
e2f7b2695ba1 merge with stable
Matt Harbison <matt_harbison@yahoo.com>
parents: 46780 46695
diff changeset
   630
            assert backupvfs is not None  # help pytype
46379
ee9002b99595 engine: add `if True` to prepare for next patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46375
diff changeset
   631
            backupvfs.unlink(b'store/lock')
30781
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   632
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   633
    return backuppath
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   634
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   635
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   636
def upgrade_dirstate(ui, srcrepo, upgrade_op, old, new):
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   637
    if upgrade_op.backup_store:
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   638
        backuppath = pycompat.mkdtemp(
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   639
            prefix=b'upgradebackup.', dir=srcrepo.path
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   640
        )
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   641
        ui.status(_(b'replaced files will be backed up at %s\n') % backuppath)
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   642
        backupvfs = vfsmod.vfs(backuppath)
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   643
        util.copyfile(
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   644
            srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   645
        )
48437
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   646
        try:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   647
            util.copyfile(
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   648
                srcrepo.vfs.join(b'dirstate'), backupvfs.join(b'dirstate')
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   649
            )
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   650
        except (IOError, OSError) as e:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   651
            # The dirstate does not exist on an empty repo or a repo with no
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   652
            # revision checked out
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   653
            if e.errno != errno.ENOENT:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   654
                raise
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   655
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   656
    assert srcrepo.dirstate._use_dirstate_v2 == (old == b'v2')
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   657
    srcrepo.dirstate._map.preload()
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   658
    srcrepo.dirstate._use_dirstate_v2 = new == b'v2'
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   659
    srcrepo.dirstate._map._use_dirstate_v2 = srcrepo.dirstate._use_dirstate_v2
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   660
    srcrepo.dirstate._dirty = True
48437
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   661
    try:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   662
        srcrepo.vfs.unlink(b'dirstate')
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   663
    except (IOError, OSError) as e:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   664
        # The dirstate does not exist on an empty repo or a repo with no
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   665
        # revision checked out
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   666
        if e.errno != errno.ENOENT:
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   667
            raise
6e4999cb085e dirstate-v2: fix upgrade on an empty repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48068
diff changeset
   668
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   669
    srcrepo.dirstate.write(None)
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   670
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47149
diff changeset
   671
    scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
48790
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   672
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   673
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   674
def upgrade_tracked_key(ui, srcrepo, upgrade_op, add):
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   675
    if add:
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   676
        srcrepo.dirstate._use_tracked_key = True
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   677
        srcrepo.dirstate._dirty = True
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   678
        srcrepo.dirstate._dirty_tracked_set = True
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   679
        srcrepo.dirstate.write(None)
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   680
    if not add:
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   681
        srcrepo.dirstate.delete_tracked_key()
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   682
5ba24e886cec tracked-key: make it possible to upgrade to and downgrade from the feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48437
diff changeset
   683
    scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)