##// END OF EJS Templates
contrib/compress: refactor revlog copying
Benoit Boissinot -
r12020:69498b1b default
parent child Browse files
Show More
@@ -11,6 +11,20 b' from mercurial import hg, localrepo'
11 from mercurial.lock import release
11 from mercurial.lock import release
12 import weakref
12 import weakref
13
13
14 def _copyrevlog(ui, src, dst, tr, progress=None):
15 if progress:
16 desc = 'adding %s' % progress
17 total = len(src)
18 def progress(count):
19 ui.progress(desc, count, unit=('revisions'), total=total)
20 else:
21 progress = lambda x: None
22 for r in src:
23 p = [src.node(i) for i in src.parentrevs(r)]
24 dst.addrevision(src.revision(src.node(r)), tr, src.linkrev(r),
25 p[0], p[1])
26 progress(r)
27
14 def compress(ui, repo, dest):
28 def compress(ui, repo, dest):
15 dest = hg.localpath(ui.expandpath(dest))
29 dest = hg.localpath(ui.expandpath(dest))
16 target = localrepo.instance(ui, dest, create=True)
30 target = localrepo.instance(ui, dest, create=True)
@@ -22,39 +36,18 b' def compress(ui, repo, dest):'
22 tr = target.transaction("compress")
36 tr = target.transaction("compress")
23 trp = weakref.proxy(tr)
37 trp = weakref.proxy(tr)
24
38
25 src_cl = repo.changelog
39 _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets')
26 tar_cl = target.changelog
40 _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest')
27 total = len(repo)
28
29 for r in src_cl:
30 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
31 tar_cl.addrevision(src_cl.revision(src_cl.node(r)), trp,
32 src_cl.linkrev(r), p[0], p[1])
33 ui.progress(('adding changesets'), r, unit=('revisions'),
34 total=total)
35
36 src_mnfst = repo.manifest
37 tar_mnfst = target.manifest
38 for r in src_mnfst:
39 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
40 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), trp,
41 src_mnfst.linkrev(r), p[0], p[1])
42 ui.progress(('adding manifest'), r, unit=('revisions'),
43 total=total)
44
41
45 # only keep indexes and filter "data/" prefix and ".i" suffix
42 # only keep indexes and filter "data/" prefix and ".i" suffix
46 datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles()
43 datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles()
47 if size and fn.endswith('.i')]
44 if size and fn.endswith('.i')]
48 total = len(datafiles)
45 total = len(datafiles)
49 for cnt, f in enumerate(datafiles):
46 for cnt, f in enumerate(datafiles):
50 sf = repo.file(f)
47 _copyrevlog(ui, repo.file(f), target.file(f), trp)
51 tf = target.file(f)
52 for r in sf:
53 p = [sf.node(i) for i in sf.parentrevs(r)]
54 tf.addrevision(sf.revision(sf.node(r)), trp, sf.linkrev(r),
55 p[0], p[1])
56 ui.progress(('adding files'), cnt, item=f, unit=('file'),
48 ui.progress(('adding files'), cnt, item=f, unit=('file'),
57 total=total)
49 total=total)
50
58 tr.close()
51 tr.close()
59 finally:
52 finally:
60 if tr:
53 if tr:
General Comments 0
You need to be logged in to leave comments. Login now