compress.py
62 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
/ contrib / compress.py
Pradeepkumar Gayam
|
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. | ||||
Benoit Boissinot
|
r12019 | from mercurial import hg, localrepo | ||
Benoit Boissinot
|
r12018 | from mercurial.lock import release | ||
import weakref | ||||
Pradeepkumar Gayam
|
r11933 | |||
Benoit Boissinot
|
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) | ||||
Benoit Boissinot
|
r12015 | def compress(ui, repo, dest): | ||
Benoit Boissinot
|
r12022 | # activate parentdelta | ||
ui.setconfig('format', 'parentdelta', 'on') | ||||
Benoit Boissinot
|
r12017 | dest = hg.localpath(ui.expandpath(dest)) | ||
target = localrepo.instance(ui, dest, create=True) | ||||
Benoit Boissinot
|
r12018 | |||
tr = lock = tlock = None | ||||
try: | ||||
lock = repo.lock() | ||||
tlock = target.lock() | ||||
tr = target.transaction("compress") | ||||
trp = weakref.proxy(tr) | ||||
Pradeepkumar Gayam
|
r11933 | |||
Benoit Boissinot
|
r12020 | _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest') | ||
Pradeepkumar Gayam
|
r11933 | |||
Benoit Boissinot
|
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): | ||||
Benoit Boissinot
|
r12020 | _copyrevlog(ui, repo.file(f), target.file(f), trp) | ||
Benoit Boissinot
|
r12018 | ui.progress(('adding files'), cnt, item=f, unit=('file'), | ||
total=total) | ||||
Benoit Boissinot
|
r12020 | |||
Benoit Boissinot
|
r12021 | _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets') | ||
Benoit Boissinot
|
r12018 | tr.close() | ||
finally: | ||||
if tr: | ||||
tr.release() | ||||
release(tlock, lock) | ||||
Pradeepkumar Gayam
|
r11933 | |||
cmdtable = { | ||||
"compress" : (compress, [], "DEST") | ||||
} | ||||