##// END OF EJS Templates
contrib/compress: proper lock handling...
Benoit Boissinot -
r12018:fd206fab default
parent child Browse files
Show More
@@ -1,54 +1,67 b''
1 # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com>
1 # Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com>
2 #
2 #
3 # Author(s):
3 # Author(s):
4 # Pradeepkumar Gayam <in3xes@gmail.com>
4 # Pradeepkumar Gayam <in3xes@gmail.com>
5 #
5 #
6 # This software may be used and distributed according to the terms of the
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.
7 # GNU General Public License version 2 or any later version.
8
8
9
9
10 from mercurial import hg, changegroup, localrepo
10 from mercurial import hg, changegroup, localrepo
11 from mercurial.lock import release
12 import weakref
11
13
12 def compress(ui, repo, dest):
14 def compress(ui, repo, dest):
13 dest = hg.localpath(ui.expandpath(dest))
15 dest = hg.localpath(ui.expandpath(dest))
14 target = localrepo.instance(ui, dest, create=True)
16 target = localrepo.instance(ui, dest, create=True)
17
18 tr = lock = tlock = None
19 try:
20 lock = repo.lock()
21 tlock = target.lock()
15 tr = target.transaction("compress")
22 tr = target.transaction("compress")
23 trp = weakref.proxy(tr)
24
16 src_cl = repo.changelog
25 src_cl = repo.changelog
17 tar_cl = target.changelog
26 tar_cl = target.changelog
18 changedfiles = set()
27 changedfiles = set()
19 mmfs = {}
28 mmfs = {}
20 collect = changegroup.collector(src_cl, mmfs, changedfiles)
29 collect = changegroup.collector(src_cl, mmfs, changedfiles)
21 total = len(repo)
30 total = len(repo)
22
31
23 for r in src_cl:
32 for r in src_cl:
24 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
33 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
25 nd = tar_cl.addrevision(src_cl.revision(src_cl.node(r)), tr,
34 nd = tar_cl.addrevision(src_cl.revision(src_cl.node(r)), trp,
26 src_cl.linkrev(r), p[0], p[1])
35 src_cl.linkrev(r), p[0], p[1])
27 collect(nd)
36 collect(nd)
28 ui.progress(('adding changesets'), r, unit=('revisions'),
37 ui.progress(('adding changesets'), r, unit=('revisions'),
29 total=total)
38 total=total)
30
39
31 src_mnfst = repo.manifest
40 src_mnfst = repo.manifest
32 tar_mnfst = target.manifest
41 tar_mnfst = target.manifest
33 for r in src_mnfst:
42 for r in src_mnfst:
34 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
43 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
35 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), tr,
44 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), trp,
36 src_mnfst.linkrev(r), p[0], p[1])
45 src_mnfst.linkrev(r), p[0], p[1])
37 ui.progress(('adding manifest'), r, unit=('revisions'),
46 ui.progress(('adding manifest'), r, unit=('revisions'),
38 total=total)
47 total=total)
39
48
40 total = len(changedfiles)
49 total = len(changedfiles)
41 for cnt, f in enumerate(changedfiles):
50 for cnt, f in enumerate(changedfiles):
42 sf = repo.file(f)
51 sf = repo.file(f)
43 tf = target.file(f)
52 tf = target.file(f)
44 for r in sf:
53 for r in sf:
45 p = [sf.node(i) for i in sf.parentrevs(r)]
54 p = [sf.node(i) for i in sf.parentrevs(r)]
46 tf.addrevision(sf.revision(sf.node(r)), tr, sf.linkrev(r),
55 tf.addrevision(sf.revision(sf.node(r)), trp, sf.linkrev(r),
47 p[0], p[1])
56 p[0], p[1])
48 ui.progress(('adding files'), cnt, item=f, unit=('file'), total=total)
57 ui.progress(('adding files'), cnt, item=f, unit=('file'),
49
58 total=total)
50 tr.close()
59 tr.close()
60 finally:
61 if tr:
62 tr.release()
63 release(tlock, lock)
51
64
52 cmdtable = {
65 cmdtable = {
53 "compress" : (compress, [], "DEST")
66 "compress" : (compress, [], "DEST")
54 }
67 }
General Comments 0
You need to be logged in to leave comments. Login now