##// END OF EJS Templates
contrib/compress: use hg API to compute the destination path
Benoit Boissinot -
r12017:9182f434 default
parent child Browse files
Show More
@@ -1,55 +1,54 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 util, changegroup, localrepo
10 from mercurial import hg, changegroup, localrepo
11 import os
12
11
13 def compress(ui, repo, dest):
12 def compress(ui, repo, dest):
14 dest = os.path.realpath(util.expandpath(dest))
13 dest = hg.localpath(ui.expandpath(dest))
15 target = localrepo.instance(ui, dest, create=1)
14 target = localrepo.instance(ui, dest, create=True)
16 tr = target.transaction("compress")
15 tr = target.transaction("compress")
17 src_cl = repo.changelog
16 src_cl = repo.changelog
18 tar_cl = target.changelog
17 tar_cl = target.changelog
19 changedfiles = set()
18 changedfiles = set()
20 mmfs = {}
19 mmfs = {}
21 collect = changegroup.collector(src_cl, mmfs, changedfiles)
20 collect = changegroup.collector(src_cl, mmfs, changedfiles)
22 total = len(repo)
21 total = len(repo)
23
22
24 for r in src_cl:
23 for r in src_cl:
25 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
24 p = [src_cl.node(i) for i in src_cl.parentrevs(r)]
26 nd = tar_cl.addrevision(src_cl.revision(src_cl.node(r)), tr,
25 nd = tar_cl.addrevision(src_cl.revision(src_cl.node(r)), tr,
27 src_cl.linkrev(r), p[0], p[1])
26 src_cl.linkrev(r), p[0], p[1])
28 collect(nd)
27 collect(nd)
29 ui.progress(('adding changesets'), r, unit=('revisions'),
28 ui.progress(('adding changesets'), r, unit=('revisions'),
30 total=total)
29 total=total)
31
30
32 src_mnfst = repo.manifest
31 src_mnfst = repo.manifest
33 tar_mnfst = target.manifest
32 tar_mnfst = target.manifest
34 for r in src_mnfst:
33 for r in src_mnfst:
35 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
34 p = [src_mnfst.node(i) for i in src_mnfst.parentrevs(r)]
36 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), tr,
35 tar_mnfst.addrevision(src_mnfst.revision(src_mnfst.node(r)), tr,
37 src_mnfst.linkrev(r), p[0], p[1])
36 src_mnfst.linkrev(r), p[0], p[1])
38 ui.progress(('adding manifest'), r, unit=('revisions'),
37 ui.progress(('adding manifest'), r, unit=('revisions'),
39 total=total)
38 total=total)
40
39
41 total = len(changedfiles)
40 total = len(changedfiles)
42 for cnt, f in enumerate(changedfiles):
41 for cnt, f in enumerate(changedfiles):
43 sf = repo.file(f)
42 sf = repo.file(f)
44 tf = target.file(f)
43 tf = target.file(f)
45 for r in sf:
44 for r in sf:
46 p = [sf.node(i) for i in sf.parentrevs(r)]
45 p = [sf.node(i) for i in sf.parentrevs(r)]
47 tf.addrevision(sf.revision(sf.node(r)), tr, sf.linkrev(r),
46 tf.addrevision(sf.revision(sf.node(r)), tr, sf.linkrev(r),
48 p[0], p[1])
47 p[0], p[1])
49 ui.progress(('adding files'), cnt, item=f, unit=('file'), total=total)
48 ui.progress(('adding files'), cnt, item=f, unit=('file'), total=total)
50
49
51 tr.close()
50 tr.close()
52
51
53 cmdtable = {
52 cmdtable = {
54 "compress" : (compress, [], "DEST")
53 "compress" : (compress, [], "DEST")
55 }
54 }
General Comments 0
You need to be logged in to leave comments. Login now