Mercurial > public > mercurial-scm > hg
comparison mercurial/repair.py @ 5909:f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
When we remove revision N from the repository, all revisions >= N are
affected: either it's a descendant from N and will also be removed, or
it's not a descendant of N and will be renumbered.
As a consequence, we have to (at least temporarily) remove all filelog
and manifest revisions that have a linkrev >= N, readding some of them
later.
Unfortunately, it's possible to have a revlog with two revisions
r1 and r2 such that r1 < r2, but linkrev(r1) > linkrev(r2). If we try
to strip revision linkrev(r1) from the repository, we'll also lose
revision r2 when we truncate this revlog.
We already use changegroupsubset to create a temporary changegroup
containing the revisions that have to be restored, but that function is
unable to detect that we also wanted to save the r2 in the case above.
So we manually calculate these extra nodes and pass it to changegroupsubset.
This should fix issue764.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 19 Jan 2008 18:01:16 -0200 |
parents | 3afbd82a6c82 |
children | b9a830fa10f6 |
comparison
equal
deleted
inserted
replaced
5908:afa1e6122be7 | 5909:f45f7390c1c5 |
---|---|
19 heads.append(r) | 19 heads.append(r) |
20 for p in cl.parentrevs(r): | 20 for p in cl.parentrevs(r): |
21 seen[p] = 1 | 21 seen[p] = 1 |
22 return heads | 22 return heads |
23 | 23 |
24 def _bundle(repo, bases, heads, node, suffix): | 24 def _bundle(repo, bases, heads, node, suffix, extranodes=None): |
25 """create a bundle with the specified revisions as a backup""" | 25 """create a bundle with the specified revisions as a backup""" |
26 cg = repo.changegroupsubset(bases, heads, 'strip') | 26 cg = repo.changegroupsubset(bases, heads, 'strip', extranodes) |
27 backupdir = repo.join("strip-backup") | 27 backupdir = repo.join("strip-backup") |
28 if not os.path.isdir(backupdir): | 28 if not os.path.isdir(backupdir): |
29 os.mkdir(backupdir) | 29 os.mkdir(backupdir) |
30 name = os.path.join(backupdir, "%s-%s" % (short(node), suffix)) | 30 name = os.path.join(backupdir, "%s-%s" % (short(node), suffix)) |
31 repo.ui.warn("saving bundle to %s\n" % name) | 31 repo.ui.warn("saving bundle to %s\n" % name) |
41 if name in filenodes: | 41 if name in filenodes: |
42 continue | 42 continue |
43 filenodes[name] = mm.get(name) | 43 filenodes[name] = mm.get(name) |
44 | 44 |
45 return filenodes | 45 return filenodes |
46 | |
47 def _collectextranodes(repo, files, link): | |
48 """return the nodes that have to be saved before the strip""" | |
49 def collectone(revlog): | |
50 extra = [] | |
51 startrev = count = revlog.count() | |
52 # find the truncation point of the revlog | |
53 for i in xrange(0, count): | |
54 node = revlog.node(i) | |
55 lrev = revlog.linkrev(node) | |
56 if lrev >= link: | |
57 startrev = i + 1 | |
58 break | |
59 | |
60 # see if any revision after that point has a linkrev less than link | |
61 # (we have to manually save these guys) | |
62 for i in xrange(startrev, count): | |
63 node = revlog.node(i) | |
64 lrev = revlog.linkrev(node) | |
65 if lrev < link: | |
66 extra.append((node, cl.node(lrev))) | |
67 | |
68 return extra | |
69 | |
70 extranodes = {} | |
71 cl = repo.changelog | |
72 extra = collectone(repo.manifest) | |
73 if extra: | |
74 extranodes[1] = extra | |
75 for fname in files: | |
76 f = repo.file(fname) | |
77 extra = collectone(f) | |
78 if extra: | |
79 extranodes[fname] = extra | |
80 | |
81 return extranodes | |
46 | 82 |
47 def _stripall(repo, striprev, filenodes): | 83 def _stripall(repo, striprev, filenodes): |
48 """strip the requested nodes from the filelogs""" | 84 """strip the requested nodes from the filelogs""" |
49 # we go in two steps here so the strip loop happens in a | 85 # we go in two steps here so the strip loop happens in a |
50 # sensible order. When stripping many files, this helps keep | 86 # sensible order. When stripping many files, this helps keep |
100 saveheads.append(h) | 136 saveheads.append(h) |
101 for x in r: | 137 for x in r: |
102 if cl.rev(x) > striprev: | 138 if cl.rev(x) > striprev: |
103 savebases[x] = 1 | 139 savebases[x] = 1 |
104 | 140 |
141 filenodes = _collectfilenodes(repo, striprev) | |
142 | |
143 extranodes = _collectextranodes(repo, filenodes, striprev) | |
144 | |
105 # create a changegroup for all the branches we need to keep | 145 # create a changegroup for all the branches we need to keep |
106 if backup == "all": | 146 if backup == "all": |
107 _bundle(repo, [node], cl.heads(), node, 'backup') | 147 _bundle(repo, [node], cl.heads(), node, 'backup') |
108 if saveheads: | 148 if saveheads or extranodes: |
109 chgrpfile = _bundle(repo, savebases.keys(), saveheads, node, 'temp') | 149 chgrpfile = _bundle(repo, savebases.keys(), saveheads, node, 'temp', |
150 extranodes) | |
110 | 151 |
111 filenodes = _collectfilenodes(repo, striprev) | |
112 _stripall(repo, striprev, filenodes) | 152 _stripall(repo, striprev, filenodes) |
113 | 153 |
114 change = cl.read(node) | 154 change = cl.read(node) |
115 cl.strip(striprev, striprev) | 155 cl.strip(striprev, striprev) |
116 repo.manifest.strip(repo.manifest.rev(change[0]), striprev) | 156 repo.manifest.strip(repo.manifest.rev(change[0]), striprev) |
117 if saveheads: | 157 if saveheads or extranodes: |
118 ui.status("adding branch\n") | 158 ui.status("adding branch\n") |
119 f = open(chgrpfile, "rb") | 159 f = open(chgrpfile, "rb") |
120 gen = changegroup.readbundle(f, chgrpfile) | 160 gen = changegroup.readbundle(f, chgrpfile) |
121 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile) | 161 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True) |
122 f.close() | 162 f.close() |
123 if backup != "strip": | 163 if backup != "strip": |
124 os.unlink(chgrpfile) | 164 os.unlink(chgrpfile) |
125 | 165 |