mercurial/repair.py
author Matt Mackall <mpm@selenic.com>
Sat, 29 Oct 2011 17:38:13 -0500
branchstable
changeset 15385 4439ec496378
parent 15068 73307643a09f
child 15386 6051d8e7e133
permissions -rw-r--r--
largefiles: avoid checking requirements on every command When largefiles is enabled, commands on large repositories which don't require largefiles could be slowed down substantially. Disable checking this for every command.
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
14064
e4bfb9c337f3 remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents: 13747
diff changeset
     9
from mercurial import changegroup, bookmarks
e4bfb9c337f3 remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents: 13747
diff changeset
    10
from mercurial.node import short
e4bfb9c337f3 remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents: 13747
diff changeset
    11
from mercurial.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
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
    14
def _bundle(repo, cg, 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"""
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    16
    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
    17
    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
    18
        os.mkdir(backupdir)
11333
e83aff248c17 strip: backup bundles should use the .hg extension
Matt Mackall <mpm@selenic.com>
parents: 11202
diff changeset
    19
    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
    20
    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
    21
        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
    22
    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
    23
        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
    24
    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
    25
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    26
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
    27
    """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
    28
    files = set()
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    30
    for x in xrange(striprev, len(repo)):
8479
3e16c0fc2241 repair: bulk update sets
Martin Geisler <mg@lazybytes.net>
parents: 8462
diff changeset
    31
        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
    32
8462
e7e4e41b3bbc repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8363
diff changeset
    33
    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
    34
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    35
def _collectbrokencsets(repo, files, striprev):
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    36
    """return the changesets which will be broken by the truncation"""
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    37
    s = set()
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    38
    def collectone(revlog):
13715
2edf41a90b9d repair: revlog has an iterator
Matt Mackall <mpm@selenic.com>
parents: 13705
diff changeset
    39
        links = (revlog.linkrev(i) for i in 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
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    41
        for lrev in links:
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    42
            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
    43
                break
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    44
        # see if any revision after this point has a linkrev
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    45
        # less than striprev (those will be broken by strip)
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    46
        for lrev in links:
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    47
            if lrev < striprev:
13747
cede00420e1e code indentation fixes
Patrick Mezard <pmezard@gmail.com>
parents: 13715
diff changeset
    48
                s.add(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
    49
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    50
    collectone(repo.manifest)
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    51
    for fname in files:
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    52
        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
    53
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    54
    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
    55
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    56
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
    57
    cl = repo.changelog
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    58
    # 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
    59
    striprev = cl.rev(node)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    60
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
    61
    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
    62
6147
53ae5af55db3 repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5910
diff changeset
    63
    # 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
    64
    # 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
    65
    # 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
    66
    # 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
    67
    # 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
    68
    # (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
    69
    #  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
    70
    tostrip = set(cl.descendants(striprev))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    71
    tostrip.add(striprev)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    72
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    73
    files = _collectfiles(repo, striprev)
13705
73cfb7a5aa56 strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents: 13702
diff changeset
    74
    saverevs = _collectbrokencsets(repo, files, striprev)
13702
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    75
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    76
    # compute heads
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    77
    saveheads = set(saverevs)
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    78
    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
    79
        if r not in tostrip:
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    80
            saverevs.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    81
            saveheads.difference_update(cl.parentrevs(r))
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    82
            saveheads.add(r)
ffd370aa050b strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13362
diff changeset
    83
    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
    84
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
    85
    # compute common nodes
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
    86
    savecommon = set(cl.node(p) for r in saverevs for p in cl.parentrevs(r)
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
    87
                     if p not in saverevs and p not in tostrip)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    88
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    89
    bm = repo._bookmarks
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    90
    updatebm = []
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    91
    for m in bm:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    92
        rev = repo[bm[m]].rev()
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    93
        if rev in tostrip:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    94
            updatebm.append(m)
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
    95
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    96
    # 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
    97
    backupfile = None
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    98
    if backup == "all":
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
    99
        allnodes=[cl.node(r) for r in xrange(striprev, len(cl))]
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   100
        cg = repo._changegroup(allnodes, 'strip')
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   101
        backupfile = _bundle(repo, cg, node, 'backup')
11200
12e5149cafca strip: improve full backup message
Matt Mackall <mpm@selenic.com>
parents: 11197
diff changeset
   102
        repo.ui.status(_("saved backup bundle to %s\n") % backupfile)
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   103
    if saveheads or savecommon:
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
   104
        # do not compress partial bundle if we remove it from disk later
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   105
        cg = repo.getbundle('strip', common=savecommon, heads=saveheads)
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   106
        chgrpfile = _bundle(repo, cg, node, 'temp', compress=keeppartialbundle)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   107
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   108
    mfst = repo.manifest
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   109
10881
a685011ed38e localrepo: add desc parameter to transaction
Steve Borho <steve@borho.org>
parents: 10263
diff changeset
   110
    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
   111
    offset = len(tr.entries)
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   112
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   113
    try:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   114
        tr.startgroup()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   115
        cl.strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   116
        mfst.strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   117
        for fn in files:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   118
            repo.file(fn).strip(striprev, tr)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   119
        tr.endgroup()
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   120
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   121
        try:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   122
            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
   123
                file, troffset, ignore = tr.entries[i]
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   124
                repo.sopener(file, 'a').truncate(troffset)
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   125
            tr.close()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   126
        except:
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   127
            tr.abort()
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   128
            raise
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   129
15068
73307643a09f repair: switch from changegroupsubset to getbundle
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14064
diff changeset
   130
        if saveheads or savecommon:
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   131
            ui.note(_("adding branch\n"))
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   132
            f = open(chgrpfile, "rb")
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   133
            gen = changegroup.readbundle(f, chgrpfile)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   134
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   135
                # silence internal shuffling chatter
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   136
                repo.ui.pushbuffer()
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   137
            repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True)
11202
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   138
            if not repo.ui.verbose:
f974fe896921 strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents: 11200
diff changeset
   139
                repo.ui.popbuffer()
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   140
            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
   141
            if not keeppartialbundle:
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   142
                os.unlink(chgrpfile)
13362
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   143
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   144
        for m in updatebm:
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   145
            bm[m] = repo['.'].node()
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   146
        bookmarks.write(repo)
ee01d9d84115 bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents: 12057
diff changeset
   147
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   148
    except:
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   149
        if backupfile:
11600
76454cbc11e4 mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 11333
diff changeset
   150
            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
   151
                    % backupfile)
11197
4bb4895e1693 strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents: 10881
diff changeset
   152
        elif saveheads:
11600
76454cbc11e4 mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 11333
diff changeset
   153
            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
   154
                    % chgrpfile)
8073
e8a28556a0a8 strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 7361
diff changeset
   155
        raise
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   156
9150
09a1ee498756 localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9125
diff changeset
   157
    repo.destroyed()