compress.py
60 lines
| 1.8 KiB
| text/x-python
|
PythonLexer
/ contrib / compress.py
|
r11933 | # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com> | ||
# | ||||
# Author(s): | ||||
# Pradeepkumar Gayam <in3xes@gmail.com> | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
|
r12019 | from mercurial import hg, localrepo | ||
|
r12018 | from mercurial.lock import release | ||
import weakref | ||||
|
r11933 | |||
|
r12020 | 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) | ||||
|
r12015 | def compress(ui, repo, dest): | ||
|
r12017 | dest = hg.localpath(ui.expandpath(dest)) | ||
target = localrepo.instance(ui, dest, create=True) | ||||
|
r12018 | |||
tr = lock = tlock = None | ||||
try: | ||||
lock = repo.lock() | ||||
tlock = target.lock() | ||||
tr = target.transaction("compress") | ||||
trp = weakref.proxy(tr) | ||||
|
r11933 | |||
|
r12020 | _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest') | ||
|
r11933 | |||
|
r12019 | # 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): | ||||
|
r12020 | _copyrevlog(ui, repo.file(f), target.file(f), trp) | ||
|
r12018 | ui.progress(('adding files'), cnt, item=f, unit=('file'), | ||
total=total) | ||||
|
r12020 | |||
|
r12021 | _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets') | ||
|
r12018 | tr.close() | ||
finally: | ||||
if tr: | ||||
tr.release() | ||||
release(tlock, lock) | ||||
|
r11933 | |||
cmdtable = { | ||||
"compress" : (compress, [], "DEST") | ||||
} | ||||