Show More
@@ -1,60 +1,62 b'' | |||
|
1 | 1 | # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com> |
|
2 | 2 | # |
|
3 | 3 | # Author(s): |
|
4 | 4 | # Pradeepkumar Gayam <in3xes@gmail.com> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | from mercurial import hg, localrepo |
|
11 | 11 | from mercurial.lock import release |
|
12 | 12 | import weakref |
|
13 | 13 | |
|
14 | 14 | def _copyrevlog(ui, src, dst, tr, progress=None): |
|
15 | 15 | if progress: |
|
16 | 16 | desc = 'adding %s' % progress |
|
17 | 17 | total = len(src) |
|
18 | 18 | def progress(count): |
|
19 | 19 | ui.progress(desc, count, unit=('revisions'), total=total) |
|
20 | 20 | else: |
|
21 | 21 | progress = lambda x: None |
|
22 | 22 | for r in src: |
|
23 | 23 | p = [src.node(i) for i in src.parentrevs(r)] |
|
24 | 24 | dst.addrevision(src.revision(src.node(r)), tr, src.linkrev(r), |
|
25 | 25 | p[0], p[1]) |
|
26 | 26 | progress(r) |
|
27 | 27 | |
|
28 | 28 | def compress(ui, repo, dest): |
|
29 | # activate parentdelta | |
|
30 | ui.setconfig('format', 'parentdelta', 'on') | |
|
29 | 31 | dest = hg.localpath(ui.expandpath(dest)) |
|
30 | 32 | target = localrepo.instance(ui, dest, create=True) |
|
31 | 33 | |
|
32 | 34 | tr = lock = tlock = None |
|
33 | 35 | try: |
|
34 | 36 | lock = repo.lock() |
|
35 | 37 | tlock = target.lock() |
|
36 | 38 | tr = target.transaction("compress") |
|
37 | 39 | trp = weakref.proxy(tr) |
|
38 | 40 | |
|
39 | 41 | _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest') |
|
40 | 42 | |
|
41 | 43 | # only keep indexes and filter "data/" prefix and ".i" suffix |
|
42 | 44 | datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles() |
|
43 | 45 | if size and fn.endswith('.i')] |
|
44 | 46 | total = len(datafiles) |
|
45 | 47 | for cnt, f in enumerate(datafiles): |
|
46 | 48 | _copyrevlog(ui, repo.file(f), target.file(f), trp) |
|
47 | 49 | ui.progress(('adding files'), cnt, item=f, unit=('file'), |
|
48 | 50 | total=total) |
|
49 | 51 | |
|
50 | 52 | _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets') |
|
51 | 53 | |
|
52 | 54 | tr.close() |
|
53 | 55 | finally: |
|
54 | 56 | if tr: |
|
55 | 57 | tr.release() |
|
56 | 58 | release(tlock, lock) |
|
57 | 59 | |
|
58 | 60 | cmdtable = { |
|
59 | 61 | "compress" : (compress, [], "DEST") |
|
60 | 62 | } |
General Comments 0
You need to be logged in to leave comments.
Login now