annotate contrib/compress.py @ 12019:456f0fed8f17

contrib/compress: use store API instead of a collector
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 22 Aug 2010 19:13:30 +0200
parents fd206fabc14f
children 69498b1b552b
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
12015
73940fe84cbf contrib/compress: remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11933
diff changeset
14 def compress(ui, repo, dest):
12017
9182f434ec58 contrib/compress: use hg API to compute the destination path
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12016
diff changeset
15 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
16 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
17
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
18 tr = lock = tlock = None
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
19 try:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
20 lock = repo.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
21 tlock = target.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
22 tr = target.transaction("compress")
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
23 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
24
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
25 src_cl = repo.changelog
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
26 tar_cl = target.changelog
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
27 total = len(repo)
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
28
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
29 for r in src_cl:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
30 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
31 tar_cl.addrevision(src_cl.revision(src_cl.node(r)), trp,
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
32 src_cl.linkrev(r), p[0], p[1])
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
33 ui.progress(('adding changesets'), r, unit=('revisions'),
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
34 total=total)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
35
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
36 src_mnfst = repo.manifest
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
37 tar_mnfst = target.manifest
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
38 for r in src_mnfst:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
39 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
40 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), trp,
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
41 src_mnfst.linkrev(r), p[0], p[1])
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
42 ui.progress(('adding manifest'), r, unit=('revisions'),
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
43 total=total)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
44
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
45 # 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
46 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
47 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
48 total = len(datafiles)
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
49 for cnt, f in enumerate(datafiles):
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
50 sf = repo.file(f)
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
51 tf = target.file(f)
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
52 for r in sf:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
53 p = [sf.node(i) for i in sf.parentrevs(r)]
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
54 tf.addrevision(sf.revision(sf.node(r)), trp, sf.linkrev(r),
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
55 p[0], p[1])
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
56 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
57 total=total)
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
58 tr.close()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
59 finally:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
60 if tr:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
61 tr.release()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
62 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
63
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
64 cmdtable = {
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
65 "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
66 }