mercurial/repair.py
author Jun Wu <quark@fb.com>
Thu, 16 Feb 2017 08:01:19 -0800
changeset 31006 d4916aebf3d0
parent 30975 22fbca1d11ed
child 31232 254f98326eef
permissions -rw-r--r--
runtests: export LOCALIP Previously, tests hard-code local IP address as "127.0.0.1". That won't work for IPv6. This patch exports the $LOCALIP environment variable, which is set to "::1" if we decide to use IPv6.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# repair.py - functions for repository repair for mercurial
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
# Copyright 2005, 2006 Chris Mason <mason@suse.com>
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
# Copyright 2007 Matt Mackall
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8073
diff changeset
     6
# 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
     7
# 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
     8
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
     9
from __future__ import absolute_import
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    10
16440
692bf06bb1af repair: fix missing import
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 16388
diff changeset
    11
import errno
29341
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 29196
diff changeset
    12
import hashlib
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
    13
import stat
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
    14
import tempfile
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    16
from .i18n import _
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    17
from .node import short
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    18
from . import (
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    19
    bundle2,
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    20
    changegroup,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    21
    changelog,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26425
diff changeset
    22
    error,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    23
    exchange,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    24
    manifest,
28868
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
    25
    obsolete,
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
    26
    revlog,
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
    27
    scmutil,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    28
    util,
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    29
)
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
    30
15386
6051d8e7e133 strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents: 15068
diff changeset
    31
def _bundle(repo, bases, heads, node, suffix, compress=True):
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    32
    """create a bundle with the specified revisions as a backup"""
27930
7cbb3a01fa38 repair: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27875
diff changeset
    33
    cgversion = changegroup.safeversion(repo)
23898
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
    34
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
    35
    cg = changegroup.changegroupsubset(repo, bases, heads, 'strip',
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
    36
                                       version=cgversion)
20977
a57dcd11be34 repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20975
diff changeset
    37
    backupdir = "strip-backup"
a57dcd11be34 repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20975
diff changeset
    38
    vfs = repo.vfs
a57dcd11be34 repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20975
diff changeset
    39
    if not vfs.isdir(backupdir):
a57dcd11be34 repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20975
diff changeset
    40
        vfs.mkdir(backupdir)
23835
aa4a1672583e bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents: 22818
diff changeset
    41
aa4a1672583e bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents: 22818
diff changeset
    42
    # Include a hash of all the nodes in the filename for uniqueness
25340
28800ab40395 repair: use _hexlist() to build revset expression from binary nodes
Yuya Nishihara <yuya@tcha.org>
parents: 25300
diff changeset
    43
    allcommits = repo.set('%ln::%ln', bases, heads)
23835
aa4a1672583e bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents: 22818
diff changeset
    44
    allhashes = sorted(c.hex() for c in allcommits)
29341
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 29196
diff changeset
    45
    totalhash = hashlib.sha1(''.join(allhashes)).hexdigest()
23835
aa4a1672583e bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents: 22818
diff changeset
    46
    name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)
aa4a1672583e bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents: 22818
diff changeset
    47
26425
eb21b6679dc6 strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26423
diff changeset
    48
    comp = None
26423
c93f91c1db1c strip: use bundle2 + cg2 by default when repository use general delta
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26014
diff changeset
    49
    if cgversion != '01':
24686
e0e28e910fa3 bundle2: rename format, parts and config to final names
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24252
diff changeset
    50
        bundletype = "HG20"
26425
eb21b6679dc6 strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26423
diff changeset
    51
        if compress:
eb21b6679dc6 strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26423
diff changeset
    52
            comp = 'BZ'
23898
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
    53
    elif compress:
11791
00cde9bddbe4 repair: do not compress partial bundle if we do not keep it on disk
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11600
diff changeset
    54
        bundletype = "HG10BZ"
00cde9bddbe4 repair: do not compress partial bundle if we do not keep it on disk
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11600
diff changeset
    55
    else:
00cde9bddbe4 repair: do not compress partial bundle if we do not keep it on disk
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11600
diff changeset
    56
        bundletype = "HG10UN"
28666
ae53ecc47414 bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28466
diff changeset
    57
    return bundle2.writebundle(repo.ui, cg, name, bundletype, vfs,
26425
eb21b6679dc6 strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26423
diff changeset
    58
                                   compression=comp)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    59
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    60
def _collectfiles(repo, striprev):
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    61
    """find out the filelogs affected by the strip"""
8462
e7e4e41b3bbc repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8363
diff changeset
    62
    files = set()
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    64
    for x in xrange(striprev, len(repo)):
8479
3e16c0fc2241 repair: bulk update sets
Martin Geisler <mg@lazybytes.net>
parents: 8462
diff changeset
    65
        files.update(repo[x].files())
5902
98f8dec8f437 repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5901
diff changeset
    66
8462
e7e4e41b3bbc repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8363
diff changeset
    67
    return sorted(files)
5902
98f8dec8f437 repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5901
diff changeset
    68
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    69
def _collectbrokencsets(repo, files, striprev):
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    70
    """return the changesets which will be broken by the truncation"""
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    71
    s = set()
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    72
    def collectone(revlog):
20074
5fc2ae1c631b strip: add faster revlog strip computation
Durham Goode <durham@fb.com>
parents: 18766
diff changeset
    73
        _, brokenset = revlog.getstrippoint(striprev)
5fc2ae1c631b strip: add faster revlog strip computation
Durham Goode <durham@fb.com>
parents: 18766
diff changeset
    74
        s.update([revlog.linkrev(r) for r in brokenset])
5909
f45f7390c1c5 strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5905
diff changeset
    75
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30371
diff changeset
    76
    collectone(repo.manifestlog._revlog)
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    77
    for fname in files:
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    78
        collectone(repo.file(fname))
5909
f45f7390c1c5 strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5905
diff changeset
    79
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    80
    return s
5909
f45f7390c1c5 strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5905
diff changeset
    81
22057
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    82
def strip(ui, repo, nodelist, backup=True, topic='backup'):
27553
56caab876bd8 repair: improves documentation of strip regarding locks
Laurent Charignon <lcharignon@fb.com>
parents: 27157
diff changeset
    83
    # This function operates within a transaction of its own, but does
56caab876bd8 repair: improves documentation of strip regarding locks
Laurent Charignon <lcharignon@fb.com>
parents: 27157
diff changeset
    84
    # not take any lock on the repo.
22057
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    85
    # Simple way to maintain backwards compatibility for this
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    86
    # argument.
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    87
    if backup in ['none', 'strip']:
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    88
        backup = False
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
    89
18004
747a2f43d5d9 clfilter: strip logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17922
diff changeset
    90
    repo = repo.unfiltered()
18310
4499ba5ac35c localrepo: introduce destroying function
Idan Kamara <idankk86@gmail.com>
parents: 18121
diff changeset
    91
    repo.destroying()
17013
c8eda7bbdcab strip: incrementally update the branchheads cache after a strip
Joshua Redstone <joshua.redstone@fb.com>
parents: 16867
diff changeset
    92
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
    93
    cl = repo.changelog
16237
b5c0c7d0f83f repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents: 15901
diff changeset
    94
    # TODO handle undo of merge sets
16252
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
    95
    if isinstance(nodelist, str):
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
    96
        nodelist = [nodelist]
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
    97
    striplist = [cl.rev(node) for node in nodelist]
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
    98
    striprev = min(striplist)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    99
30707
987dbe87aad6 repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents: 30706
diff changeset
   100
    files = _collectfiles(repo, striprev)
987dbe87aad6 repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents: 30706
diff changeset
   101
    saverevs = _collectbrokencsets(repo, files, striprev)
987dbe87aad6 repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents: 30706
diff changeset
   102
6147
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   103
    # Some revisions with rev > striprev may not be descendants of striprev.
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   104
    # We have to find these revisions and put them in a bundle, so that
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   105
    # we can restore them after the truncations.
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   106
    # To create the bundle we use repo.changegroupsubset which requires
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   107
    # the list of heads and bases of the set of interesting revisions.
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   108
    # (head = revision in the set that has no descendant in the set;
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   109
    #  base = revision in the set that has no ancestor in the set)
16252
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
   110
    tostrip = set(striplist)
30707
987dbe87aad6 repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents: 30706
diff changeset
   111
    saveheads = set(saverevs)
30706
2e4862646f02 repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents: 30375
diff changeset
   112
    for r in cl.revs(start=striprev + 1):
2e4862646f02 repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents: 30375
diff changeset
   113
        if any(p in tostrip for p in cl.parentrevs(r)):
2e4862646f02 repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents: 30375
diff changeset
   114
            tostrip.add(r)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   115
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   116
        if r not in tostrip:
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   117
            saverevs.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   118
            saveheads.difference_update(cl.parentrevs(r))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   119
            saveheads.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   120
    saveheads = [cl.node(r) for r in saveheads]
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   121
15386
6051d8e7e133 strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents: 15068
diff changeset
   122
    # compute base nodes
6051d8e7e133 strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents: 15068
diff changeset
   123
    if saverevs:
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16745
diff changeset
   124
        descendants = set(cl.descendants(saverevs))
15386
6051d8e7e133 strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents: 15068
diff changeset
   125
        saverevs.difference_update(descendants)
6051d8e7e133 strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents: 15068
diff changeset
   126
    savebases = [cl.node(r) for r in saverevs]
16252
cf17e76be4dd strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15901
diff changeset
   127
    stripbases = [cl.node(r) for r in tostrip]
18040
fe8caf28d580 strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents: 18004
diff changeset
   128
fe8caf28d580 strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents: 18004
diff changeset
   129
    # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)), but
fe8caf28d580 strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents: 18004
diff changeset
   130
    # is much faster
fe8caf28d580 strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents: 18004
diff changeset
   131
    newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip)
17264
ec7b9bec19c9 strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents: 17013
diff changeset
   132
    if newbmtarget:
22818
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22057
diff changeset
   133
        newbmtarget = repo[newbmtarget.first()].node()
17264
ec7b9bec19c9 strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents: 17013
diff changeset
   134
    else:
ec7b9bec19c9 strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents: 17013
diff changeset
   135
        newbmtarget = '.'
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   136
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   137
    bm = repo._bookmarks
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   138
    updatebm = []
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   139
    for m in bm:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   140
        rev = repo[bm[m]].rev()
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   141
        if rev in tostrip:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   142
            updatebm.append(m)
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   143
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   144
    # create a changegroup for all the branches we need to keep
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   145
    backupfile = None
20979
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   146
    vfs = repo.vfs
24252
f962692853c0 repair: define explicit local variable, don't reuse a comprehension variable
Mike Edgar <adgar@google.com>
parents: 24170
diff changeset
   147
    node = nodelist[-1]
22057
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
   148
    if backup:
16388
e03d8a40521f repair: allow giving strip backup a different name
Idan Kamara <idankk86@gmail.com>
parents: 16253
diff changeset
   149
        backupfile = _bundle(repo, stripbases, cl.heads(), node, topic)
20979
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   150
        repo.ui.status(_("saved backup bundle to %s\n") %
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   151
                       vfs.join(backupfile))
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   152
        repo.ui.log("backupbundle", "saved backup bundle to %s\n",
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   153
                    vfs.join(backupfile))
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   154
    tmpbundlefile = None
29951
e7acbe538baf strip: simplify some repeated conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 29708
diff changeset
   155
    if saveheads:
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   156
        # do not compress temporary bundle if we remove it from disk later
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   157
        tmpbundlefile = _bundle(repo, savebases, saveheads, node, 'temp',
22057
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
   158
                            compress=False)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   159
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30371
diff changeset
   160
    mfst = repo.manifestlog._revlog
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   161
25300
678d0bfdd31a repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24863
diff changeset
   162
    curtr = repo.currenttransaction()
678d0bfdd31a repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24863
diff changeset
   163
    if curtr is not None:
678d0bfdd31a repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24863
diff changeset
   164
        del curtr  # avoid carrying reference to transaction for nothing
678d0bfdd31a repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24863
diff changeset
   165
        msg = _('programming error: cannot strip from inside a transaction')
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26425
diff changeset
   166
        raise error.Abort(msg, hint=_('contact your extension maintainer'))
25300
678d0bfdd31a repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24863
diff changeset
   167
27873
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   168
    try:
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   169
        with repo.transaction("strip") as tr:
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   170
            offset = len(tr.entries)
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   171
27873
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   172
            tr.startgroup()
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   173
            cl.strip(striprev, tr)
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   174
            mfst.strip(striprev, tr)
29464
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   175
            if 'treemanifest' in repo.requirements: # safe but unnecessary
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   176
                                                    # otherwise
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   177
                for unencoded, encoded, size in repo.store.datafiles():
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   178
                    if (unencoded.startswith('meta/') and
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   179
                        unencoded.endswith('00manifest.i')):
87c184c9bfef treemanifests: actually strip directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 29341
diff changeset
   180
                        dir = unencoded[5:-12]
30371
fccc3eea2ddb manifest: delete unused dirlog and _newmanifest functions
Durham Goode <durham@fb.com>
parents: 30274
diff changeset
   181
                        repo.manifestlog._revlog.dirlog(dir).strip(striprev, tr)
27873
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   182
            for fn in files:
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   183
                repo.file(fn).strip(striprev, tr)
60ea60fea5f3 with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27871
diff changeset
   184
            tr.endgroup()
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   185
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   186
            for i in xrange(offset, len(tr.entries)):
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   187
                file, troffset, ignore = tr.entries[i]
30001
e38d85be978f repair: open a file with checkambig=True to avoid file stat ambiguity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29954
diff changeset
   188
                with repo.svfs(file, 'a', checkambig=True) as fp:
e38d85be978f repair: open a file with checkambig=True to avoid file stat ambiguity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29954
diff changeset
   189
                    fp.truncate(troffset)
20885
f49d60fa40a5 fncache: clean up fncache during strips
Durham Goode <durham@fb.com>
parents: 20074
diff changeset
   190
                if troffset == 0:
f49d60fa40a5 fncache: clean up fncache during strips
Durham Goode <durham@fb.com>
parents: 20074
diff changeset
   191
                    repo.store.markremoved(file)
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   192
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   193
        if tmpbundlefile:
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   194
            ui.note(_("adding branch\n"))
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   195
            f = vfs.open(tmpbundlefile, "rb")
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   196
            gen = exchange.readbundle(ui, f, tmpbundlefile, vfs)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   197
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   198
                # silence internal shuffling chatter
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   199
                repo.ui.pushbuffer()
23898
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
   200
            if isinstance(gen, bundle2.unbundle20):
27875
add2ba16430e with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27873
diff changeset
   201
                with repo.transaction('strip') as tr:
add2ba16430e with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents: 27873
diff changeset
   202
                    tr.hookargs = {'source': 'strip',
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   203
                                   'url': 'bundle:' + vfs.join(tmpbundlefile)}
26797
75d550b7d8f5 strip: pass source and url to bundle2 processing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26701
diff changeset
   204
                    bundle2.applybundle(repo, gen, tr, source='strip',
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   205
                                        url='bundle:' + vfs.join(tmpbundlefile))
23898
b21c2e0ee8a3 repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents: 23895
diff changeset
   206
            else:
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   207
                gen.apply(repo, 'strip', 'bundle:' + vfs.join(tmpbundlefile),
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   208
                          True)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   209
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   210
                repo.ui.popbuffer()
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   211
            f.close()
29196
bf7b8157c483 strip: invalidate phase cache after stripping changeset (issue5235)
Laurent Charignon <lcharignon@fb.com>
parents: 28868
diff changeset
   212
        repo._phasecache.invalidate()
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   213
27157
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   214
        for m in updatebm:
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   215
            bm[m] = repo[newbmtarget].node()
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   216
        lock = tr = None
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   217
        try:
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   218
            lock = repo.lock()
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   219
            tr = repo.transaction('repair')
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   220
            bm.recordchange(tr)
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   221
            tr.close()
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   222
        finally:
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   223
            tr.release()
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   224
            lock.release()
5f2e4eb08e41 repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents: 26797
diff changeset
   225
16237
b5c0c7d0f83f repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents: 15901
diff changeset
   226
        # remove undo files
20975
37cdf1fca1b2 localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20933
diff changeset
   227
        for undovfs, undofile in repo.undofiles():
16237
b5c0c7d0f83f repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents: 15901
diff changeset
   228
            try:
20975
37cdf1fca1b2 localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20933
diff changeset
   229
                undovfs.unlink(undofile)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25652
diff changeset
   230
            except OSError as e:
16237
b5c0c7d0f83f repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents: 15901
diff changeset
   231
                if e.errno != errno.ENOENT:
20975
37cdf1fca1b2 localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20933
diff changeset
   232
                    ui.warn(_('error removing %s: %s\n') %
37cdf1fca1b2 localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20933
diff changeset
   233
                            (undovfs.join(undofile), str(e)))
16237
b5c0c7d0f83f repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents: 15901
diff changeset
   234
16705
c2d9ef43ff6c check-code: ignore naked excepts with a "re-raise" comment
Brodie Rao <brodie@sf.io>
parents: 16628
diff changeset
   235
    except: # re-raises
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   236
        if backupfile:
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   237
            ui.warn(_("strip failed, backup bundle stored in '%s'\n")
20979
ad5b61370514 repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20977
diff changeset
   238
                    % vfs.join(backupfile))
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   239
        if tmpbundlefile:
29953
94ebf56db04e strip: clarify that user action is required to recover temp bundle
Martin von Zweigbergk <martinvonz@google.com>
parents: 29952
diff changeset
   240
            ui.warn(_("strip failed, unrecovered changes stored in '%s'\n")
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   241
                    % vfs.join(tmpbundlefile))
29953
94ebf56db04e strip: clarify that user action is required to recover temp bundle
Martin von Zweigbergk <martinvonz@google.com>
parents: 29952
diff changeset
   242
            ui.warn(_("(fix the problem, then recover the changesets with "
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   243
                      "\"hg unbundle '%s'\")\n") % vfs.join(tmpbundlefile))
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   244
        raise
22057
445472225ccd strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21064
diff changeset
   245
    else:
29954
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   246
        if tmpbundlefile:
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   247
            # Remove temporary bundle only if there were no exceptions
769aee32fae0 strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents: 29953
diff changeset
   248
            vfs.unlink(tmpbundlefile)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   249
18395
904b7109938e destroyed: drop complex branchcache rebuilt logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18311
diff changeset
   250
    repo.destroyed()
30274
c1345969f6c5 repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents: 30001
diff changeset
   251
    # return the backup file path (or None if 'backup' was False) so
c1345969f6c5 repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents: 30001
diff changeset
   252
    # extensions can use it
c1345969f6c5 repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents: 30001
diff changeset
   253
    return backupfile
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   254
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   255
def rebuildfncache(ui, repo):
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   256
    """Rebuilds the fncache file from repo history.
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   257
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   258
    Missing entries will be added. Extra entries will be removed.
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   259
    """
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   260
    repo = repo.unfiltered()
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   261
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   262
    if 'fncache' not in repo.requirements:
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   263
        ui.warn(_('(not rebuilding fncache because repository does not '
25874
3e84f40232c7 repair: fix typo in warning message
Wagner Bruna <wbruna@yahoo.com>
parents: 25845
diff changeset
   264
                  'support fncache)\n'))
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   265
        return
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   266
27860
0da102e4f203 with: use context manager in rebuildfncache again
Bryan O'Sullivan <bryano@fb.com>
parents: 27553
diff changeset
   267
    with repo.lock():
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   268
        fnc = repo.store.fncache
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   269
        # Trigger load of fncache.
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   270
        if 'irrelevant' in fnc:
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   271
            pass
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   272
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   273
        oldentries = set(fnc.entries)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   274
        newentries = set()
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   275
        seenfiles = set()
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   276
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   277
        repolen = len(repo)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   278
        for rev in repo:
28466
c7d45c5a8cea repair: specify unit for ui.progress in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents: 28465
diff changeset
   279
            ui.progress(_('rebuilding'), rev, total=repolen,
c7d45c5a8cea repair: specify unit for ui.progress in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents: 28465
diff changeset
   280
                        unit=_('changesets'))
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   281
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   282
            ctx = repo[rev]
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   283
            for f in ctx.files():
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   284
                # This is to minimize I/O.
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   285
                if f in seenfiles:
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   286
                    continue
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   287
                seenfiles.add(f)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   288
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   289
                i = 'data/%s.i' % f
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   290
                d = 'data/%s.d' % f
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   291
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   292
                if repo.store._exists(i):
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   293
                    newentries.add(i)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   294
                if repo.store._exists(d):
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   295
                    newentries.add(d)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   296
28465
43eb31ea2dcb repair: use 'rebuilding' progress topic in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents: 28031
diff changeset
   297
        ui.progress(_('rebuilding'), None)
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   298
28031
6f248ba85309 treemanifest: fix debugrebuildfncache
Martin von Zweigbergk <martinvonz@google.com>
parents: 28007
diff changeset
   299
        if 'treemanifest' in repo.requirements: # safe but unnecessary otherwise
28007
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   300
            for dir in util.dirs(seenfiles):
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   301
                i = 'meta/%s/00manifest.i' % dir
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   302
                d = 'meta/%s/00manifest.d' % dir
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   303
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   304
                if repo.store._exists(i):
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   305
                    newentries.add(i)
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   306
                if repo.store._exists(d):
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   307
                    newentries.add(d)
fb92927f9775 treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents: 27930
diff changeset
   308
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   309
        addcount = len(newentries - oldentries)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   310
        removecount = len(oldentries - newentries)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   311
        for p in sorted(oldentries - newentries):
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   312
            ui.write(_('removing %s\n') % p)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   313
        for p in sorted(newentries - oldentries):
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   314
            ui.write(_('adding %s\n') % p)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   315
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   316
        if addcount or removecount:
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   317
            ui.write(_('%d items added, %d removed from fncache\n') %
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   318
                     (addcount, removecount))
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   319
            fnc.entries = newentries
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   320
            fnc._dirty = True
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   321
27871
f1c316fd91f9 with: use context manager in rebuildfncache
Bryan O'Sullivan <bryano@fb.com>
parents: 27860
diff changeset
   322
            with repo.transaction('fncache') as tr:
25652
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   323
                fnc.write(tr)
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   324
        else:
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   325
            ui.write(_('fncache already up to date\n'))
2882d6886919 repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25404
diff changeset
   326
26624
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   327
def stripbmrevset(repo, mark):
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   328
    """
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   329
    The revset to strip when strip is called with -B mark
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   330
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   331
    Needs to live here so extensions can use it and wrap it even when strip is
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   332
    not enabled or not present on a box.
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   333
    """
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   334
    return repo.revs("ancestors(bookmark(%s)) - "
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   335
                     "ancestors(head() and not bookmark(%s)) - "
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   336
                     "ancestors(bookmark() and not bookmark(%s))",
bcace0fbb4c8 strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents: 26587
diff changeset
   337
                     mark, mark, mark)
28868
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   338
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   339
def deleteobsmarkers(obsstore, indices):
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   340
    """Delete some obsmarkers from obsstore and return how many were deleted
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   341
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   342
    'indices' is a list of ints which are the indices
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   343
    of the markers to be deleted.
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   344
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   345
    Every invocation of this function completely rewrites the obsstore file,
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   346
    skipping the markers we want to be removed. The new temporary file is
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   347
    created, remaining markers are written there and on .close() this file
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   348
    gets atomically renamed to obsstore, thus guaranteeing consistency."""
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   349
    if not indices:
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   350
        # we don't want to rewrite the obsstore with the same content
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   351
        return
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   352
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   353
    left = []
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   354
    current = obsstore._all
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   355
    n = 0
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   356
    for i, m in enumerate(current):
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   357
        if i in indices:
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   358
            n += 1
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   359
            continue
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   360
        left.append(m)
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   361
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   362
    newobsstorefile = obsstore.svfs('obsstore', 'w', atomictemp=True)
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   363
    for bytes in obsolete.encodemarkers(left, True, obsstore._version):
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   364
        newobsstorefile.write(bytes)
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   365
    newobsstorefile.close()
445a25bb70be obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents: 28666
diff changeset
   366
    return n
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   367
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   368
def upgraderequiredsourcerequirements(repo):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   369
    """Obtain requirements required to be present to upgrade a repo.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   370
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   371
    An upgrade will not be allowed if the repository doesn't have the
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   372
    requirements returned by this function.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   373
    """
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   374
    return set([
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   375
        # Introduced in Mercurial 0.9.2.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   376
        'revlogv1',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   377
        # Introduced in Mercurial 0.9.2.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   378
        'store',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   379
    ])
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   380
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   381
def upgradeblocksourcerequirements(repo):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   382
    """Obtain requirements that will prevent an upgrade from occurring.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   383
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   384
    An upgrade cannot be performed if the source repository contains a
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   385
    requirements in the returned set.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   386
    """
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   387
    return set([
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   388
        # The upgrade code does not yet support these experimental features.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   389
        # This is an artificial limitation.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   390
        'manifestv2',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   391
        'treemanifest',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   392
        # This was a precursor to generaldelta and was never enabled by default.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   393
        # It should (hopefully) not exist in the wild.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   394
        'parentdelta',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   395
        # Upgrade should operate on the actual store, not the shared link.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   396
        'shared',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   397
    ])
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   398
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   399
def upgradesupportremovedrequirements(repo):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   400
    """Obtain requirements that can be removed during an upgrade.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   401
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   402
    If an upgrade were to create a repository that dropped a requirement,
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   403
    the dropped requirement must appear in the returned set for the upgrade
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   404
    to be allowed.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   405
    """
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   406
    return set()
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   407
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   408
def upgradesupporteddestrequirements(repo):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   409
    """Obtain requirements that upgrade supports in the destination.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   410
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   411
    If the result of the upgrade would create requirements not in this set,
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   412
    the upgrade is disallowed.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   413
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   414
    Extensions should monkeypatch this to add their custom requirements.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   415
    """
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   416
    return set([
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   417
        'dotencode',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   418
        'fncache',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   419
        'generaldelta',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   420
        'revlogv1',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   421
        'store',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   422
    ])
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   423
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   424
def upgradeallowednewrequirements(repo):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   425
    """Obtain requirements that can be added to a repository during upgrade.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   426
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   427
    This is used to disallow proposed requirements from being added when
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   428
    they weren't present before.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   429
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   430
    We use a list of allowed requirement additions instead of a list of known
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   431
    bad additions because the whitelist approach is safer and will prevent
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   432
    future, unknown requirements from accidentally being added.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   433
    """
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   434
    return set([
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   435
        'dotencode',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   436
        'fncache',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   437
        'generaldelta',
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   438
    ])
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   439
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   440
deficiency = 'deficiency'
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   441
optimisation = 'optimization'
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   442
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   443
class upgradeimprovement(object):
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   444
    """Represents an improvement that can be made as part of an upgrade.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   445
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   446
    The following attributes are defined on each instance:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   447
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   448
    name
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   449
       Machine-readable string uniquely identifying this improvement. It
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   450
       will be mapped to an action later in the upgrade process.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   451
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   452
    type
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   453
       Either ``deficiency`` or ``optimisation``. A deficiency is an obvious
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   454
       problem. An optimization is an action (sometimes optional) that
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   455
       can be taken to further improve the state of the repository.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   456
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   457
    description
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   458
       Message intended for humans explaining the improvement in more detail,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   459
       including the implications of it. For ``deficiency`` types, should be
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   460
       worded in the present tense. For ``optimisation`` types, should be
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   461
       worded in the future tense.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   462
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   463
    upgrademessage
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   464
       Message intended for humans explaining what an upgrade addressing this
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   465
       issue will do. Should be worded in the future tense.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   466
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   467
    fromdefault (``deficiency`` types only)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   468
       Boolean indicating whether the current (deficient) state deviates
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   469
       from Mercurial's default configuration.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   470
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   471
    fromconfig (``deficiency`` types only)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   472
       Boolean indicating whether the current (deficient) state deviates
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   473
       from the current Mercurial configuration.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   474
    """
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   475
    def __init__(self, name, type, description, upgrademessage, **kwargs):
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   476
        self.name = name
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   477
        self.type = type
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   478
        self.description = description
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   479
        self.upgrademessage = upgrademessage
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   480
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   481
        for k, v in kwargs.items():
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   482
            setattr(self, k, v)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   483
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   484
def upgradefindimprovements(repo):
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   485
    """Determine improvements that can be made to the repo during upgrade.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   486
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   487
    Returns a list of ``upgradeimprovement`` describing repository deficiencies
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   488
    and optimizations.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   489
    """
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   490
    # Avoid cycle: cmdutil -> repair -> localrepo -> cmdutil
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   491
    from . import localrepo
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   492
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   493
    newreporeqs = localrepo.newreporequirements(repo)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   494
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   495
    improvements = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   496
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   497
    # We could detect lack of revlogv1 and store here, but they were added
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   498
    # in 0.9.2 and we don't support upgrading repos without these
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   499
    # requirements, so let's not bother.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   500
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   501
    if 'fncache' not in repo.requirements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   502
        improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   503
            name='fncache',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   504
            type=deficiency,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   505
            description=_('long and reserved filenames may not work correctly; '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   506
                          'repository performance is sub-optimal'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   507
            upgrademessage=_('repository will be more resilient to storing '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   508
                             'certain paths and performance of certain '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   509
                             'operations should be improved'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   510
            fromdefault=True,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   511
            fromconfig='fncache' in newreporeqs))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   512
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   513
    if 'dotencode' not in repo.requirements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   514
        improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   515
            name='dotencode',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   516
            type=deficiency,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   517
            description=_('storage of filenames beginning with a period or '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   518
                          'space may not work correctly'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   519
            upgrademessage=_('repository will be better able to store files '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   520
                             'beginning with a space or period'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   521
            fromdefault=True,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   522
            fromconfig='dotencode' in newreporeqs))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   523
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   524
    if 'generaldelta' not in repo.requirements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   525
        improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   526
            name='generaldelta',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   527
            type=deficiency,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   528
            description=_('deltas within internal storage are unable to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   529
                          'choose optimal revisions; repository is larger and '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   530
                          'slower than it could be; interaction with other '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   531
                          'repositories may require extra network and CPU '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   532
                          'resources, making "hg push" and "hg pull" slower'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   533
            upgrademessage=_('repository storage will be able to create '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   534
                             'optimal deltas; new repository data will be '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   535
                             'smaller and read times should decrease; '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   536
                             'interacting with other repositories using this '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   537
                             'storage model should require less network and '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   538
                             'CPU resources, making "hg push" and "hg pull" '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   539
                             'faster'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   540
            fromdefault=True,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   541
            fromconfig='generaldelta' in newreporeqs))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   542
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   543
    # Mercurial 4.0 changed changelogs to not use delta chains. Search for
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   544
    # changelogs with deltas.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   545
    cl = repo.changelog
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   546
    for rev in cl:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   547
        chainbase = cl.chainbase(rev)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   548
        if chainbase != rev:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   549
            improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   550
                name='removecldeltachain',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   551
                type=deficiency,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   552
                description=_('changelog storage is using deltas instead of '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   553
                              'raw entries; changelog reading and any '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   554
                              'operation relying on changelog data are slower '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   555
                              'than they could be'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   556
                upgrademessage=_('changelog storage will be reformated to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   557
                                 'store raw entries; changelog reading will be '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   558
                                 'faster; changelog size may be reduced'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   559
                fromdefault=True,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   560
                fromconfig=True))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   561
            break
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   562
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   563
    # Now for the optimizations.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   564
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   565
    # These are unconditionally added. There is logic later that figures out
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   566
    # which ones to apply.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   567
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   568
    improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   569
        name='redeltaparent',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   570
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   571
        description=_('deltas within internal storage will be recalculated to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   572
                      'choose an optimal base revision where this was not '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   573
                      'already done; the size of the repository may shrink and '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   574
                      'various operations may become faster; the first time '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   575
                      'this optimization is performed could slow down upgrade '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   576
                      'execution considerably; subsequent invocations should '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   577
                      'not run noticeably slower'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   578
        upgrademessage=_('deltas within internal storage will choose a new '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   579
                         'base revision if needed')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   580
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   581
    improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   582
        name='redeltamultibase',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   583
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   584
        description=_('deltas within internal storage will be recalculated '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   585
                      'against multiple base revision and the smallest '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   586
                      'difference will be used; the size of the repository may '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   587
                      'shrink significantly when there are many merges; this '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   588
                      'optimization will slow down execution in proportion to '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   589
                      'the number of merges in the repository and the amount '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   590
                      'of files in the repository; this slow down should not '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   591
                      'be significant unless there are tens of thousands of '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   592
                      'files and thousands of merges'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   593
        upgrademessage=_('deltas within internal storage will choose an '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   594
                         'optimal delta by computing deltas against multiple '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   595
                         'parents; may slow down execution time '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   596
                         'significantly')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   597
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   598
    improvements.append(upgradeimprovement(
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   599
        name='redeltaall',
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   600
        type=optimisation,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   601
        description=_('deltas within internal storage will always be '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   602
                      'recalculated without reusing prior deltas; this will '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   603
                      'likely make execution run several times slower; this '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   604
                      'optimization is typically not needed'),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   605
        upgrademessage=_('deltas within internal storage will be fully '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   606
                         'recomputed; this will likely drastically slow down '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   607
                         'execution time')))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   608
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   609
    return improvements
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   610
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   611
def upgradedetermineactions(repo, improvements, sourcereqs, destreqs,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   612
                            optimize):
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   613
    """Determine upgrade actions that will be performed.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   614
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   615
    Given a list of improvements as returned by ``upgradefindimprovements``,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   616
    determine the list of upgrade actions that will be performed.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   617
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   618
    The role of this function is to filter improvements if needed, apply
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   619
    recommended optimizations from the improvements list that make sense,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   620
    etc.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   621
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   622
    Returns a list of action names.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   623
    """
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   624
    newactions = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   625
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   626
    knownreqs = upgradesupporteddestrequirements(repo)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   627
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   628
    for i in improvements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   629
        name = i.name
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   630
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   631
        # If the action is a requirement that doesn't show up in the
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   632
        # destination requirements, prune the action.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   633
        if name in knownreqs and name not in destreqs:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   634
            continue
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   635
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   636
        if i.type == deficiency:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   637
            newactions.append(name)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   638
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   639
    newactions.extend(o for o in sorted(optimize) if o not in newactions)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   640
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   641
    # FUTURE consider adding some optimizations here for certain transitions.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   642
    # e.g. adding generaldelta could schedule parent redeltas.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   643
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   644
    return newactions
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   645
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   646
def _revlogfrompath(repo, path):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   647
    """Obtain a revlog from a repo path.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   648
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   649
    An instance of the appropriate class is returned.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   650
    """
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   651
    if path == '00changelog.i':
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   652
        return changelog.changelog(repo.svfs)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   653
    elif path.endswith('00manifest.i'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   654
        mandir = path[:-len('00manifest.i')]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   655
        return manifest.manifestrevlog(repo.svfs, dir=mandir)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   656
    else:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   657
        # Filelogs don't do anything special with settings. So we can use a
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   658
        # vanilla revlog.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   659
        return revlog.revlog(repo.svfs, path)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   660
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   661
def _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, aggressivemergedeltas):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   662
    """Copy revlogs between 2 repos."""
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   663
    revcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   664
    srcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   665
    srcrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   666
    dstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   667
    fcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   668
    frevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   669
    fsrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   670
    frawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   671
    fdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   672
    mcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   673
    mrevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   674
    msrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   675
    mrawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   676
    mdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   677
    crevcount = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   678
    csrcsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   679
    crawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   680
    cdstsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   681
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   682
    # 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
   683
    # source files and allows a unified progress bar to be displayed.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   684
    for unencoded, encoded, size in srcrepo.store.walk():
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   685
        if unencoded.endswith('.d'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   686
            continue
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   687
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   688
        rl = _revlogfrompath(srcrepo, unencoded)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   689
        revcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   690
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   691
        datasize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   692
        rawsize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   693
        idx = rl.index
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   694
        for rev in rl:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   695
            e = idx[rev]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   696
            datasize += e[1]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   697
            rawsize += e[2]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   698
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   699
        srcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   700
        srcrawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   701
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   702
        # This is for the separate progress bars.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   703
        if isinstance(rl, changelog.changelog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   704
            crevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   705
            csrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   706
            crawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   707
        elif isinstance(rl, manifest.manifestrevlog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   708
            mcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   709
            mrevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   710
            msrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   711
            mrawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   712
        elif isinstance(rl, revlog.revlog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   713
            fcount += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   714
            frevcount += len(rl)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   715
            fsrcsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   716
            frawsize += rawsize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   717
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   718
    if not revcount:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   719
        return
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   720
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   721
    ui.write(_('migrating %d total revisions (%d in filelogs, %d in manifests, '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   722
               '%d in changelog)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   723
             (revcount, frevcount, mrevcount, crevcount))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   724
    ui.write(_('migrating %s in store; %s tracked data\n') % (
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   725
             (util.bytecount(srcsize), util.bytecount(srcrawsize))))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   726
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   727
    # Used to keep track of progress.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   728
    progress = []
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   729
    def oncopiedrevision(rl, rev, node):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   730
        progress[1] += 1
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   731
        srcrepo.ui.progress(progress[0], progress[1], total=progress[2])
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   732
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   733
    # Do the actual copying.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   734
    # FUTURE this operation can be farmed off to worker processes.
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   735
    seen = set()
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   736
    for unencoded, encoded, size in srcrepo.store.walk():
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   737
        if unencoded.endswith('.d'):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   738
            continue
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   739
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   740
        oldrl = _revlogfrompath(srcrepo, unencoded)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   741
        newrl = _revlogfrompath(dstrepo, unencoded)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   742
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   743
        if isinstance(oldrl, changelog.changelog) and 'c' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   744
            ui.write(_('finished migrating %d manifest revisions across %d '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   745
                       'manifests; change in size: %s\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   746
                     (mrevcount, mcount, util.bytecount(mdstsize - msrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   747
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   748
            ui.write(_('migrating changelog containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   749
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   750
                     (crevcount, util.bytecount(csrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   751
                      util.bytecount(crawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   752
            seen.add('c')
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   753
            progress[:] = [_('changelog revisions'), 0, crevcount]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   754
        elif isinstance(oldrl, manifest.manifestrevlog) and 'm' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   755
            ui.write(_('finished migrating %d filelog revisions across %d '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   756
                       'filelogs; change in size: %s\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   757
                     (frevcount, fcount, util.bytecount(fdstsize - fsrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   758
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   759
            ui.write(_('migrating %d manifests containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   760
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   761
                     (mcount, mrevcount, util.bytecount(msrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   762
                      util.bytecount(mrawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   763
            seen.add('m')
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   764
            progress[:] = [_('manifest revisions'), 0, mrevcount]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   765
        elif 'f' not in seen:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   766
            ui.write(_('migrating %d filelogs containing %d revisions '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   767
                       '(%s in store; %s tracked data)\n') %
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   768
                     (fcount, frevcount, util.bytecount(fsrcsize),
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   769
                      util.bytecount(frawsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   770
            seen.add('f')
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   771
            progress[:] = [_('file revisions'), 0, frevcount]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   772
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   773
        ui.progress(progress[0], progress[1], total=progress[2])
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   774
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   775
        ui.note(_('cloning %d revisions from %s\n') % (len(oldrl), unencoded))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   776
        oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision,
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   777
                    deltareuse=deltareuse,
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   778
                    aggressivemergedeltas=aggressivemergedeltas)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   780
        datasize = 0
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   781
        idx = newrl.index
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   782
        for rev in newrl:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   783
            datasize += idx[rev][1]
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   784
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   785
        dstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   786
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   787
        if isinstance(newrl, changelog.changelog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   788
            cdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   789
        elif isinstance(newrl, manifest.manifestrevlog):
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   790
            mdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   791
        else:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   792
            fdstsize += datasize
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   793
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   794
    ui.progress(progress[0], None)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   795
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   796
    ui.write(_('finished migrating %d changelog revisions; change in size: '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   797
               '%s\n') % (crevcount, util.bytecount(cdstsize - csrcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   798
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   799
    ui.write(_('finished migrating %d total revisions; total change in store '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   800
               'size: %s\n') % (revcount, util.bytecount(dstsize - srcsize)))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   801
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   802
def _upgradefilterstorefile(srcrepo, dstrepo, requirements, path, mode, st):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   803
    """Determine whether to copy a store file during upgrade.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   804
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   805
    This function is called when migrating store files from ``srcrepo`` to
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   806
    ``dstrepo`` as part of upgrading a repository.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   807
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   808
    Args:
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   809
      srcrepo: repo we are copying from
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   810
      dstrepo: repo we are copying to
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   811
      requirements: set of requirements for ``dstrepo``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   812
      path: store file being examined
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   813
      mode: the ``ST_MODE`` file type of ``path``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   814
      st: ``stat`` data structure for ``path``
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   815
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   816
    Function should return ``True`` if the file is to be copied.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   817
    """
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   818
    # Skip revlogs.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   819
    if path.endswith(('.i', '.d')):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   820
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   821
    # Skip transaction related files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   822
    if path.startswith('undo'):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   823
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   824
    # Only copy regular files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   825
    if mode != stat.S_IFREG:
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   826
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   827
    # Skip other skipped files.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   828
    if path in ('lock', 'fncache'):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   829
        return False
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   830
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   831
    return True
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   832
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   833
def _upgradefinishdatamigration(ui, srcrepo, dstrepo, requirements):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   834
    """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
   835
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   836
    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
   837
    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
   838
    """
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   839
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   840
def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions):
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   841
    """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
   842
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   843
    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
   844
    repository and a temporary destination repository.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   845
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   846
    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
   847
    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
   848
    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
   849
    """
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   850
    assert srcrepo.currentwlock()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   851
    assert dstrepo.currentwlock()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   852
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   853
    ui.write(_('(it is safe to interrupt this process any time before '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   854
               'data migration completes)\n'))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   855
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   856
    if 'redeltaall' in actions:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   857
        deltareuse = revlog.revlog.DELTAREUSENEVER
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   858
    elif 'redeltaparent' in actions:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   859
        deltareuse = revlog.revlog.DELTAREUSESAMEREVS
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   860
    elif 'redeltamultibase' in actions:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   861
        deltareuse = revlog.revlog.DELTAREUSESAMEREVS
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   862
    else:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   863
        deltareuse = revlog.revlog.DELTAREUSEALWAYS
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   864
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   865
    with dstrepo.transaction('upgrade') as tr:
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   866
        _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse,
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   867
                     'redeltamultibase' in actions)
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   868
30780
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   869
    # Now copy other files in the store directory.
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   870
    for p, kind, st in srcrepo.store.vfs.readdir('', stat=True):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   871
        if not _upgradefilterstorefile(srcrepo, dstrepo, requirements,
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   872
                                       p, kind, st):
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   873
            continue
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   874
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   875
        srcrepo.ui.write(_('copying %s\n') % p)
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   876
        src = srcrepo.store.vfs.join(p)
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   877
        dst = dstrepo.store.vfs.join(p)
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   878
        util.copyfile(src, dst, copystat=True)
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   879
2603d04889e1 repair: copy non-revlog store files during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30779
diff changeset
   880
    _upgradefinishdatamigration(ui, srcrepo, dstrepo, requirements)
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   881
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   882
    ui.write(_('data fully migrated to temporary repository\n'))
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   883
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   884
    backuppath = tempfile.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   885
    backupvfs = scmutil.vfs(backuppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   886
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   887
    # Make a backup of requires file first, as it is the first to be modified.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   888
    util.copyfile(srcrepo.join('requires'), backupvfs.join('requires'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   889
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   890
    # We install an arbitrary requirement that clients must not support
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   891
    # as a mechanism to lock out new clients during the data swap. This is
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   892
    # better than allowing a client to continue while the repository is in
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   893
    # an inconsistent state.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   894
    ui.write(_('marking source repository as being upgraded; clients will be '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   895
               'unable to read from repository\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   896
    scmutil.writerequires(srcrepo.vfs,
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   897
                          srcrepo.requirements | set(['upgradeinprogress']))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   898
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   899
    ui.write(_('starting in-place swap of repository data\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   900
    ui.write(_('replaced files will be backed up at %s\n') %
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   901
             backuppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   902
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   903
    # Now swap in the new store directory. Doing it as a rename should make
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   904
    # the operation nearly instantaneous and atomic (at least in well-behaved
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   905
    # environments).
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   906
    ui.write(_('replacing store...\n'))
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30781
diff changeset
   907
    tstart = util.timer()
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   908
    util.rename(srcrepo.spath, backupvfs.join('store'))
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   909
    util.rename(dstrepo.spath, srcrepo.spath)
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30781
diff changeset
   910
    elapsed = util.timer() - tstart
30779
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   911
    ui.write(_('store replacement complete; repository was inconsistent for '
38aa1ca97b6a repair: migrate revlogs during upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30777
diff changeset
   912
               '%0.1fs\n') % elapsed)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   913
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   914
    # We first write the requirements file. Any new requirements will lock
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   915
    # out legacy clients.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   916
    ui.write(_('finalizing requirements file and making repository readable '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   917
               'again\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   918
    scmutil.writerequires(srcrepo.vfs, requirements)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   919
30781
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   920
    # The lock file from the old store won't be removed because nothing has a
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   921
    # reference to its new location. So clean it up manually. Alternatively, we
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   922
    # could update srcrepo.svfs and other variables to point to the new
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   923
    # location. This is simpler.
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   924
    backupvfs.unlink('store/lock')
f2c069bf78ee repair: clean up stale lock file from store backup
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30780
diff changeset
   925
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   926
    return backuppath
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
   927
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   928
def upgraderepo(ui, repo, run=False, optimize=None):
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   929
    """Upgrade a repository in place."""
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   930
    # Avoid cycle: cmdutil -> repair -> localrepo -> cmdutil
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   931
    from . import localrepo
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   932
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   933
    optimize = set(optimize or [])
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   934
    repo = repo.unfiltered()
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   935
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   936
    # Ensure the repository can be upgraded.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   937
    missingreqs = upgraderequiredsourcerequirements(repo) - repo.requirements
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   938
    if missingreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   939
        raise error.Abort(_('cannot upgrade repository; requirement '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   940
                            'missing: %s') % _(', ').join(sorted(missingreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   941
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   942
    blockedreqs = upgradeblocksourcerequirements(repo) & repo.requirements
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   943
    if blockedreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   944
        raise error.Abort(_('cannot upgrade repository; unsupported source '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   945
                            'requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   946
                          _(', ').join(sorted(blockedreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   947
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   948
    # FUTURE there is potentially a need to control the wanted requirements via
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   949
    # command arguments or via an extension hook point.
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   950
    newreqs = localrepo.newreporequirements(repo)
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   951
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   952
    noremovereqs = (repo.requirements - newreqs -
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   953
                   upgradesupportremovedrequirements(repo))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   954
    if noremovereqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   955
        raise error.Abort(_('cannot upgrade repository; requirement would be '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   956
                            'removed: %s') % _(', ').join(sorted(noremovereqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   957
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   958
    noaddreqs = (newreqs - repo.requirements -
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   959
                 upgradeallowednewrequirements(repo))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   960
    if noaddreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   961
        raise error.Abort(_('cannot upgrade repository; do not support adding '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   962
                            'requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   963
                          _(', ').join(sorted(noaddreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   964
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   965
    unsupportedreqs = newreqs - upgradesupporteddestrequirements(repo)
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   966
    if unsupportedreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   967
        raise error.Abort(_('cannot upgrade repository; do not support '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   968
                            'destination requirement: %s') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   969
                          _(', ').join(sorted(unsupportedreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   970
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   971
    # Find and validate all improvements that can be made.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   972
    improvements = upgradefindimprovements(repo)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   973
    for i in improvements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   974
        if i.type not in (deficiency, optimisation):
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   975
            raise error.Abort(_('unexpected improvement type %s for %s') % (
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   976
                i.type, i.name))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   977
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   978
    # Validate arguments.
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   979
    unknownoptimize = optimize - set(i.name for i in improvements
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   980
                                     if i.type == optimisation)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   981
    if unknownoptimize:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   982
        raise error.Abort(_('unknown optimization action requested: %s') %
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   983
                          ', '.join(sorted(unknownoptimize)),
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   984
                          hint=_('run without arguments to see valid '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   985
                                 'optimizations'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   986
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   987
    actions = upgradedetermineactions(repo, improvements, repo.requirements,
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   988
                                      newreqs, optimize)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
   989
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   990
    def printrequirements():
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   991
        ui.write(_('requirements\n'))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   992
        ui.write(_('   preserved: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   993
                 _(', ').join(sorted(newreqs & repo.requirements)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   994
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   995
        if repo.requirements - newreqs:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   996
            ui.write(_('   removed: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   997
                     _(', ').join(sorted(repo.requirements - newreqs)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   998
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
   999
        if newreqs - repo.requirements:
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1000
            ui.write(_('   added: %s\n') %
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1001
                     _(', ').join(sorted(newreqs - repo.requirements)))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1002
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1003
        ui.write('\n')
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1004
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1005
    def printupgradeactions():
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1006
        for action in actions:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1007
            for i in improvements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1008
                if i.name == action:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1009
                    ui.write('%s\n   %s\n\n' %
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1010
                             (i.name, i.upgrademessage))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1011
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1012
    if not run:
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1013
        fromdefault = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1014
        fromconfig = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1015
        optimizations = []
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1016
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1017
        for i in improvements:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1018
            assert i.type in (deficiency, optimisation)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1019
            if i.type == deficiency:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1020
                if i.fromdefault:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1021
                    fromdefault.append(i)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1022
                if i.fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1023
                    fromconfig.append(i)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1024
            else:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1025
                optimizations.append(i)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1026
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1027
        if fromdefault or fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1028
            fromconfignames = set(x.name for x in fromconfig)
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1029
            onlydefault = [i for i in fromdefault
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1030
                           if i.name not in fromconfignames]
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1031
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1032
            if fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1033
                ui.write(_('repository lacks features recommended by '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1034
                           'current config options:\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1035
                for i in fromconfig:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1036
                    ui.write('%s\n   %s\n\n' % (i.name, i.description))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1037
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1038
            if onlydefault:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1039
                ui.write(_('repository lacks features used by the default '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1040
                           'config options:\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1041
                for i in onlydefault:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1042
                    ui.write('%s\n   %s\n\n' % (i.name, i.description))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1043
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1044
            ui.write('\n')
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1045
        else:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1046
            ui.write(_('(no feature deficiencies found in existing '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1047
                       'repository)\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1048
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1049
        ui.write(_('performing an upgrade with "--run" will make the following '
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1050
                   'changes:\n\n'))
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1051
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
  1052
        printrequirements()
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1053
        printupgradeactions()
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1054
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1055
        unusedoptimize = [i for i in improvements
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1056
                          if i.name not in actions and i.type == optimisation]
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1057
        if unusedoptimize:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1058
            ui.write(_('additional optimizations are available by specifying '
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1059
                     '"--optimize <name>":\n\n'))
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1060
            for i in unusedoptimize:
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
  1061
                ui.write(_('%s\n   %s\n\n') % (i.name, i.description))
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1062
        return
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1063
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1064
    # Else we're in the run=true case.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1065
    ui.write(_('upgrade will perform the following actions:\n\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1066
    printrequirements()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1067
    printupgradeactions()
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1068
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1069
    ui.write(_('beginning upgrade...\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1070
    with repo.wlock():
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1071
        with repo.lock():
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1072
            ui.write(_('repository locked and read-only\n'))
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1073
            # Our strategy for upgrading the repository is to create a new,
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1074
            # temporary repository, write data to it, then do a swap of the
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1075
            # data. There are less heavyweight ways to do this, but it is easier
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1076
            # to create a new repo object than to instantiate all the components
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1077
            # (like the store) separately.
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1078
            tmppath = tempfile.mkdtemp(prefix='upgrade.', dir=repo.path)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1079
            backuppath = None
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1080
            try:
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1081
                ui.write(_('creating temporary repository to stage migrated '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1082
                           'data: %s\n') % tmppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1083
                dstrepo = localrepo.localrepository(repo.baseui,
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1084
                                                    path=tmppath,
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1085
                                                    create=True)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1086
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1087
                with dstrepo.wlock():
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1088
                    with dstrepo.lock():
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1089
                        backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1090
                                                  actions)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1091
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1092
            finally:
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1093
                ui.write(_('removing temporary repository %s\n') % tmppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1094
                repo.vfs.rmtree(tmppath, forcibly=True)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1095
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1096
                if backuppath:
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1097
                    ui.warn(_('copy of old repository backed up at %s\n') %
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1098
                            backuppath)
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1099
                    ui.warn(_('the old repository will not be deleted; remove '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1100
                              'it to free up disk space once the upgraded '
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
  1101
                              'repository is verified\n'))