Mercurial > hg
changeset 5902:98f8dec8f437
repair.py: split stripall into two functions; clean it up a bit
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 19 Jan 2008 18:01:16 -0200 |
parents | 16f4129c19ac |
children | bf20995f1ac3 |
files | mercurial/repair.py |
diffstat | 1 files changed, 24 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/repair.py Sat Jan 19 18:01:16 2008 -0200 +++ b/mercurial/repair.py Sat Jan 19 18:01:16 2008 -0200 @@ -39,34 +39,34 @@ ui.warn("saving bundle to %s\n" % name) return changegroup.writebundle(cg, name, "HG10BZ") - def stripall(striprev): - mm = repo.changectx(node).manifest() - seen = {} + def collectfilenodes(repo, striprev): + """find out the first node that should be stripped from each filelog""" + mm = repo.changectx(striprev).manifest() + filenodes = {} for x in xrange(striprev, repo.changelog.count()): - for f in repo.changectx(x).files(): - if f in seen: + for name in repo.changectx(x).files(): + if name in filenodes: continue - seen[f] = 1 - if f in mm: - filerev = mm[f] - else: - filerev = 0 - seen[f] = filerev + filenodes[name] = mm.get(name) + + return filenodes + + def stripall(repo, striprev, filenodes): + """strip the requested nodes from the filelogs""" # we go in two steps here so the strip loop happens in a # sensible order. When stripping many files, this helps keep # our disk access patterns under control. - seen_list = seen.keys() - seen_list.sort() - for f in seen_list: - ff = repo.file(f) - filerev = seen[f] - if filerev != 0: - if filerev in ff.nodemap: - filerev = ff.rev(filerev) - else: - filerev = 0 - ff.strip(filerev, striprev) + + files = filenodes.keys() + files.sort() + for name in files: + f = repo.file(name) + fnode = filenodes[name] + frev = 0 + if fnode is not None and fnode in f.nodemap: + frev = f.rev(fnode) + f.strip(frev, striprev) cl = repo.changelog # TODO delete the undo files, and handle undo of merge sets @@ -115,7 +115,8 @@ if saveheads: chgrpfile = bundle(repo, savebases.keys(), saveheads, node, 'temp') - stripall(striprev) + filenodes = collectfilenodes(repo, striprev) + stripall(repo, striprev, filenodes) change = cl.read(node) cl.strip(striprev, striprev)