annotate contrib/compress.py @ 12629:c623752b1af5

test-keyword: remove remaining sed calls
author Christian Ebert <blacktrash@gmx.net>
date Fri, 08 Oct 2010 18:39:46 +0100
parents 6b04f1e1aa8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
1 # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com>
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
2 #
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
3 # Author(s):
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
4 # Pradeepkumar Gayam <in3xes@gmail.com>
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
5 #
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
8
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
9
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
10 from mercurial import hg, localrepo
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
11 from mercurial.lock import release
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
12 import weakref
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
13
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
14 def _copyrevlog(ui, src, dst, tr, progress=None):
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
15 if progress:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
16 desc = 'adding %s' % progress
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
17 total = len(src)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
18 def progress(count):
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
19 ui.progress(desc, count, unit=('revisions'), total=total)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
20 else:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
21 progress = lambda x: None
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
22 for r in src:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
23 p = [src.node(i) for i in src.parentrevs(r)]
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
24 dst.addrevision(src.revision(src.node(r)), tr, src.linkrev(r),
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
25 p[0], p[1])
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
26 progress(r)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
27
12015
73940fe84cbf contrib/compress: remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11933
diff changeset
28 def compress(ui, repo, dest):
12022
6b04f1e1aa8a contrib/compress: compress should activate parentdelta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12021
diff changeset
29 # activate parentdelta
6b04f1e1aa8a contrib/compress: compress should activate parentdelta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12021
diff changeset
30 ui.setconfig('format', 'parentdelta', 'on')
12017
9182f434ec58 contrib/compress: use hg API to compute the destination path
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12016
diff changeset
31 dest = hg.localpath(ui.expandpath(dest))
9182f434ec58 contrib/compress: use hg API to compute the destination path
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12016
diff changeset
32 target = localrepo.instance(ui, dest, create=True)
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
33
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
34 tr = lock = tlock = None
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
35 try:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
36 lock = repo.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
37 tlock = target.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
38 tr = target.transaction("compress")
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
39 trp = weakref.proxy(tr)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
40
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
41 _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest')
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
42
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
43 # only keep indexes and filter "data/" prefix and ".i" suffix
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
44 datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles()
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
45 if size and fn.endswith('.i')]
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
46 total = len(datafiles)
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
47 for cnt, f in enumerate(datafiles):
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
48 _copyrevlog(ui, repo.file(f), target.file(f), trp)
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
49 ui.progress(('adding files'), cnt, item=f, unit=('file'),
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
50 total=total)
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
51
12021
42253a4d2be5 contrib/compress: correct ordering of copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12020
diff changeset
52 _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets')
42253a4d2be5 contrib/compress: correct ordering of copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12020
diff changeset
53
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
54 tr.close()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
55 finally:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
56 if tr:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
57 tr.release()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
58 release(tlock, lock)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
59
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
60 cmdtable = {
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
61 "compress" : (compress, [], "DEST")
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
62 }