1 # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com> |
|
2 # |
|
3 # Author(s): |
|
4 # Pradeepkumar Gayam <in3xes@gmail.com> |
|
5 # |
|
6 # This software may be used and distributed according to the terms of the |
|
7 # GNU General Public License version 2 or any later version. |
|
8 |
|
9 |
|
10 from mercurial import hg, localrepo |
|
11 from mercurial.lock import release |
|
12 import weakref |
|
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 |
|
28 def compress(ui, repo, dest): |
|
29 # activate parentdelta |
|
30 ui.setconfig('format', 'parentdelta', 'on') |
|
31 dest = hg.localpath(ui.expandpath(dest)) |
|
32 target = localrepo.instance(ui, dest, create=True) |
|
33 |
|
34 tr = lock = tlock = None |
|
35 try: |
|
36 lock = repo.lock() |
|
37 tlock = target.lock() |
|
38 tr = target.transaction("compress") |
|
39 trp = weakref.proxy(tr) |
|
40 |
|
41 _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest') |
|
42 |
|
43 # only keep indexes and filter "data/" prefix and ".i" suffix |
|
44 datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles() |
|
45 if size and fn.endswith('.i')] |
|
46 total = len(datafiles) |
|
47 for cnt, f in enumerate(datafiles): |
|
48 _copyrevlog(ui, repo.file(f), target.file(f), trp) |
|
49 ui.progress(('adding files'), cnt, item=f, unit=('file'), |
|
50 total=total) |
|
51 |
|
52 _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets') |
|
53 |
|
54 tr.close() |
|
55 finally: |
|
56 if tr: |
|
57 tr.release() |
|
58 release(tlock, lock) |
|
59 |
|
60 cmdtable = { |
|
61 "compress" : (compress, [], "DEST") |
|
62 } |
|