Mercurial > hg-stable
changeset 12020:69498b1b552b
contrib/compress: refactor revlog copying
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 22 Aug 2010 19:26:07 +0200 |
parents | 456f0fed8f17 |
children | 42253a4d2be5 |
files | contrib/compress.py |
diffstat | 1 files changed, 18 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/compress.py Sun Aug 22 19:13:30 2010 +0200 +++ b/contrib/compress.py Sun Aug 22 19:26:07 2010 +0200 @@ -11,6 +11,20 @@ from mercurial.lock import release import weakref +def _copyrevlog(ui, src, dst, tr, progress=None): + if progress: + desc = 'adding %s' % progress + total = len(src) + def progress(count): + ui.progress(desc, count, unit=('revisions'), total=total) + else: + progress = lambda x: None + for r in src: + p = [src.node(i) for i in src.parentrevs(r)] + dst.addrevision(src.revision(src.node(r)), tr, src.linkrev(r), + p[0], p[1]) + progress(r) + def compress(ui, repo, dest): dest = hg.localpath(ui.expandpath(dest)) target = localrepo.instance(ui, dest, create=True) @@ -22,39 +36,18 @@ tr = target.transaction("compress") trp = weakref.proxy(tr) - src_cl = repo.changelog - tar_cl = target.changelog - total = len(repo) - - for r in src_cl: - p = [src_cl.node(i) for i in src_cl.parentrevs(r)] - tar_cl.addrevision(src_cl.revision(src_cl.node(r)), trp, - src_cl.linkrev(r), p[0], p[1]) - ui.progress(('adding changesets'), r, unit=('revisions'), - total=total) - - src_mnfst = repo.manifest - tar_mnfst = target.manifest - for r in src_mnfst: - p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)] - tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), trp, - src_mnfst.linkrev(r), p[0], p[1]) - ui.progress(('adding manifest'), r, unit=('revisions'), - total=total) + _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets') + _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest') # only keep indexes and filter "data/" prefix and ".i" suffix datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles() if size and fn.endswith('.i')] total = len(datafiles) for cnt, f in enumerate(datafiles): - sf = repo.file(f) - tf = target.file(f) - for r in sf: - p = [sf.node(i) for i in sf.parentrevs(r)] - tf.addrevision(sf.revision(sf.node(r)), trp, sf.linkrev(r), - p[0], p[1]) + _copyrevlog(ui, repo.file(f), target.file(f), trp) ui.progress(('adding files'), cnt, item=f, unit=('file'), total=total) + tr.close() finally: if tr: