mercurial/repair.py
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 19 Feb 2008 19:20:10 -0300
changeset 6144 08e0825b8106
parent 5910 b9a830fa10f6
child 6147 53ae5af55db3
permissions -rw-r--r--
revlog.revision: avoid opening the datafile without need. If there's no inline data, revlog.revision opens the data file every time it's called. This is useful if we're going to call chunk many times, but, if we're going to call it only once, it's better to let chunk open the file - if we're lucky, all the data we're going to need is already cached and we won't need to even look at the file.
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
#
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
5899
d7388ad85511 repair.py: use node.* directly
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5898
diff changeset
     9
import changegroup, os
d7388ad85511 repair.py: use node.* directly
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5898
diff changeset
    10
from node import *
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    12
def _limitheads(cl, stoprev):
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    13
    """return the list of all revs >= stoprev that have no children"""
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    14
    seen = {}
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    15
    heads = []
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    17
    for r in xrange(cl.count() - 1, stoprev - 1, -1):
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    18
        if r not in seen:
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    19
            heads.append(r)
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    20
        for p in cl.parentrevs(r):
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    21
            seen[p] = 1
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    22
    return heads
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
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
    24
def _bundle(repo, bases, heads, node, suffix, extranodes=None):
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    25
    """create a bundle with the specified revisions as a backup"""
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
    26
    cg = repo.changegroupsubset(bases, heads, 'strip', extranodes)
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    27
    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
    28
    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
    29
        os.mkdir(backupdir)
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    30
    name = os.path.join(backupdir, "%s-%s" % (short(node), suffix))
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    31
    repo.ui.warn("saving bundle to %s\n" % name)
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    32
    return changegroup.writebundle(cg, name, "HG10BZ")
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    34
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
    35
    """find out the filelogs affected by the strip"""
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    36
    files = {}
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    38
    for x in xrange(striprev, repo.changelog.count()):
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    39
        for name in repo.changectx(x).files():
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    40
            if name in files:
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    41
                continue
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    42
            files[name] = 1
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
    43
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    44
    files = files.keys()
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    45
    files.sort()
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
    46
    return 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
    47
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
    48
def _collectextranodes(repo, files, link):
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
    """return the nodes that have to be saved before the strip"""
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
    50
    def collectone(revlog):
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
    51
        extra = []
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
    52
        startrev = count = revlog.count()
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
        # find the truncation point of the revlog
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
    54
        for i in xrange(0, count):
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
            node = revlog.node(i)
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
            lrev = revlog.linkrev(node)
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
            if lrev >= link:
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
    58
                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
    59
                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
    60
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
    61
        # see if any revision after that point has a linkrev less than link
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
    62
        # (we have to manually save these guys)
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
    63
        for i in xrange(startrev, count):
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
    64
            node = revlog.node(i)
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
    65
            lrev = revlog.linkrev(node)
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
    66
            if lrev < link:
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
    67
                extra.append((node, cl.node(lrev)))
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
    68
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
    69
        return extra
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
    70
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
    71
    extranodes = {}
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
    72
    cl = repo.changelog
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
    73
    extra = collectone(repo.manifest)
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
    74
    if extra:
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
        extranodes[1] = extra
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
    76
    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
    77
        f = repo.file(fname)
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
    78
        extra = collectone(f)
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
        if extra:
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
    80
            extranodes[fname] = extra
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
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
    82
    return extranodes
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
    83
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    84
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
    85
    cl = repo.changelog
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    86
    # 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
    87
    pp = cl.parents(node)
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
    88
    striprev = cl.rev(node)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    89
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    90
    # save is a list of all the branches we are truncating away
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    91
    # that we actually want to keep.  changegroup will be used
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    92
    # to preserve them and add them back after the truncate
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    93
    saveheads = []
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    94
    savebases = {}
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    95
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
    96
    heads = [cl.node(r) for r in _limitheads(cl, striprev)]
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    97
    seen = {}
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    98
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    99
    # search through all the heads, finding those where the revision
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   100
    # we want to strip away is an ancestor.  Also look for merges
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   101
    # that might be turned into new heads by the strip.
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   102
    while heads:
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   103
        h = heads.pop()
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   104
        n = h
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   105
        while True:
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   106
            seen[n] = 1
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
   107
            pp = cl.parents(n)
5899
d7388ad85511 repair.py: use node.* directly
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5898
diff changeset
   108
            if pp[1] != nullid:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   109
                for p in pp:
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
   110
                    if cl.rev(p) > striprev and p not in seen:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   111
                        heads.append(p)
5899
d7388ad85511 repair.py: use node.* directly
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5898
diff changeset
   112
            if pp[0] == nullid:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   113
                break
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
   114
            if cl.rev(pp[0]) < striprev:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   115
                break
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   116
            n = pp[0]
5900
1206e3dfc906 repair.py: nodes are nodes, revs are revs
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5899
diff changeset
   117
            if n == node:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   118
                break
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
   119
        r = cl.reachable(h, node)
5900
1206e3dfc906 repair.py: nodes are nodes, revs are revs
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5899
diff changeset
   120
        if node not in r:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   121
            saveheads.append(h)
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   122
            for x in r:
5901
16f4129c19ac repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5900
diff changeset
   123
                if cl.rev(x) > striprev:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   124
                    savebases[x] = 1
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   125
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   126
    files = _collectfiles(repo, 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
   127
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   128
    extranodes = _collectextranodes(repo, files, 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
   129
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   130
    # create a changegroup for all the branches we need to keep
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   131
    if backup == "all":
5905
3afbd82a6c82 repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5904
diff changeset
   132
        _bundle(repo, [node], cl.heads(), node, 'backup')
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
   133
    if saveheads or extranodes:
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
   134
        chgrpfile = _bundle(repo, savebases.keys(), saveheads, node, 'temp',
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
   135
                            extranodes)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   136
5910
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   137
    cl.strip(striprev)
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   138
    repo.manifest.strip(striprev)
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   139
    for name in files:
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   140
        f = repo.file(name)
b9a830fa10f6 simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5909
diff changeset
   141
        f.strip(striprev)
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   142
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
   143
    if saveheads or extranodes:
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   144
        ui.status("adding branch\n")
5898
52cfe86ebe55 repair.py: don't import commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4702
diff changeset
   145
        f = open(chgrpfile, "rb")
52cfe86ebe55 repair.py: don't import commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4702
diff changeset
   146
        gen = changegroup.readbundle(f, chgrpfile)
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
   147
        repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True)
5898
52cfe86ebe55 repair.py: don't import commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4702
diff changeset
   148
        f.close()
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   149
        if backup != "strip":
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   150
            os.unlink(chgrpfile)
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   151