mercurial/repair.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 20 Mar 2011 00:50:22 +0100
changeset 13702 ffd370aa050b
parent 13362 ee01d9d84115
child 13705 73cfb7a5aa56
permissions -rw-r--r--
strip: remove usage of extranodes Instead of computing the exact set of missing revlog revisions, we only compute the set of missing/broken changesets. The resulting bundle can be slightly bigger but we will be able to get rid of the ugly extranodes handling in changegroupsubset.
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
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
     9
import changegroup, bookmarks
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 6147
diff changeset
    10
from node import nullrev, short
6953
63b5f4c73c98 i18n: mark strings for translation in Mercurial
Martin Geisler <mg@daimi.au.dk>
parents: 6750
diff changeset
    11
from i18n import _
8312
b87a50b7125c separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents: 8225
diff changeset
    12
import os
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    14
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
    15
    """create a bundle with the specified revisions as a backup"""
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    16
    cg = repo.changegroupsubset(bases, heads, 'strip')
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    17
    backupdir = repo.join("strip-backup")
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    18
    if not os.path.isdir(backupdir):
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    19
        os.mkdir(backupdir)
11333
e83aff248c17 strip: backup bundles should use the .hg extension
Matt Mackall <mpm@selenic.com>
parents: 11202
diff changeset
    20
    name = os.path.join(backupdir, "%s-%s.hg" % (short(node), suffix))
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
    21
    if compress:
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
    22
        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
    23
    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
    24
        bundletype = "HG10UN"
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
    25
    return changegroup.writebundle(cg, name, bundletype)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    27
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
    28
    """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
    29
    files = set()
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    31
    for x in xrange(striprev, len(repo)):
8479
3e16c0fc2241 repair: bulk update sets
Martin Geisler <mg@lazybytes.net>
parents: 8462
diff changeset
    32
        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
    33
8462
e7e4e41b3bbc repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8363
diff changeset
    34
    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
    35
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    36
def _collectbrokencsets(repo, files, striprev):
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    37
    """return the changesets which will be broken by the truncation"""
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    38
    def collectone(revlog):
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    39
        startrev = count = len(revlog)
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
    40
        # find the truncation point of the revlog
8624
2b3dec0ef3ae replace xrange(0, n) with xrange(n)
Martin Geisler <mg@lazybytes.net>
parents: 8479
diff changeset
    41
        for i in xrange(count):
7361
9fe97eea5510 linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents: 6953
diff changeset
    42
            lrev = revlog.linkrev(i)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    43
            if lrev >= striprev:
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
    44
                startrev = i + 1
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
    45
                break
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
    46
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    47
        # see if any revision after that point has a linkrev less than striprev
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    48
        # (those will be broken by strip)
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
    49
        for i in xrange(startrev, count):
7361
9fe97eea5510 linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents: 6953
diff changeset
    50
            lrev = revlog.linkrev(i)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    51
            if lrev < striprev:
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    52
                yield lrev
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
    53
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    54
    for rev in collectone(repo.manifest):
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    55
        yield rev
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
    56
    for fname in files:
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
    57
        f = repo.file(fname)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    58
        for rev in collectone(f):
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    59
            yield rev
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
    60
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    61
def strip(ui, repo, node, backup="all"):
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
    62
    cl = repo.changelog
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
    # TODO delete the undo files, and handle undo of merge sets
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
    64
    striprev = cl.rev(node)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    65
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
    66
    keeppartialbundle = backup == 'strip'
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
    67
6147
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
    68
    # 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
    69
    # 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
    70
    # 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
    71
    # 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
    72
    # 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
    73
    # (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
    74
    #  base = revision in the set that has no ancestor in the set)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    75
    tostrip = set(cl.descendants(striprev))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    76
    tostrip.add(striprev)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    77
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    78
    files = _collectfiles(repo, striprev)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    79
    saverevs = set(_collectbrokencsets(repo, files, striprev))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    80
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    81
    # compute heads
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    82
    saveheads = set(saverevs)
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    83
    for r in xrange(striprev + 1, len(cl)):
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    84
        if r not in tostrip:
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    85
            saverevs.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    86
            saveheads.difference_update(cl.parentrevs(r))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    87
            saveheads.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    88
    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
    89
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    90
    # compute base nodes
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    91
    if saverevs:
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    92
        descendants = set(cl.descendants(*saverevs))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    93
        saverevs.difference_update(descendants)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    94
    savebases = [cl.node(r) for r in saverevs]
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    95
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    96
    bm = repo._bookmarks
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    97
    updatebm = []
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    98
    for m in bm:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    99
        rev = repo[bm[m]].rev()
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   100
        if rev in tostrip:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   101
            updatebm.append(m)
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   102
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   103
    # 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
   104
    backupfile = None
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   105
    if backup == "all":
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   106
        backupfile = _bundle(repo, [node], cl.heads(), node, 'backup')
11200
12e5149cafca strip: improve full backup message
Matt Mackall <mpm@selenic.com>
parents: 11197
diff changeset
   107
        repo.ui.status(_("saved backup bundle to %s\n") % backupfile)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   108
    if saveheads or savebases:
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
   109
        # do not compress partial bundle if we remove it from disk later
6147
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
   110
        chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp',
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   111
                            compress=keeppartialbundle)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   112
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   113
    mfst = repo.manifest
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   114
10881
a685011ed38e localrepo: add desc parameter to transaction
Steve Borho <steve@borho.org>
parents: 10263
diff changeset
   115
    tr = repo.transaction("strip")
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   116
    offset = len(tr.entries)
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   117
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   118
    try:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   119
        tr.startgroup()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   120
        cl.strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   121
        mfst.strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   122
        for fn in files:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   123
            repo.file(fn).strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   124
        tr.endgroup()
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   125
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   126
        try:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   127
            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
   128
                file, troffset, ignore = tr.entries[i]
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   129
                repo.sopener(file, 'a').truncate(troffset)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   130
            tr.close()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   131
        except:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   132
            tr.abort()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   133
            raise
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   134
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
   135
        if saveheads or savebases:
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   136
            ui.note(_("adding branch\n"))
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   137
            f = open(chgrpfile, "rb")
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   138
            gen = changegroup.readbundle(f, chgrpfile)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   139
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   140
                # silence internal shuffling chatter
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   141
                repo.ui.pushbuffer()
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   142
            repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   143
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   144
                repo.ui.popbuffer()
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   145
            f.close()
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
   146
            if not keeppartialbundle:
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   147
                os.unlink(chgrpfile)
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   148
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   149
        for m in updatebm:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   150
            bm[m] = repo['.'].node()
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   151
        bookmarks.write(repo)
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   152
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   153
    except:
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   154
        if backupfile:
11600
76454cbc11e4 mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 11333
diff changeset
   155
            ui.warn(_("strip failed, full bundle stored in '%s'\n")
76454cbc11e4 mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 11333
diff changeset
   156
                    % backupfile)
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   157
        elif saveheads:
11600
76454cbc11e4 mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 11333
diff changeset
   158
            ui.warn(_("strip failed, partial bundle stored in '%s'\n")
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   159
                    % chgrpfile)
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   160
        raise
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   161
9150
09a1ee498756 localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9125
diff changeset
   162
    repo.destroyed()