Show More
@@ -0,0 +1,27 b'' | |||||
|
1 | #!/bin/sh | |||
|
2 | ||||
|
3 | echo "[extensions]" >> $HGRCPATH | |||
|
4 | echo "hgext.convert=" >> $HGRCPATH | |||
|
5 | ||||
|
6 | hg init orig | |||
|
7 | cd orig | |||
|
8 | echo foo > foo | |||
|
9 | echo bar > bar | |||
|
10 | hg ci -qAm 'add foo and bar' -d '0 0' | |||
|
11 | ||||
|
12 | hg rm foo | |||
|
13 | hg ci -m 'remove foo' -d '0 0' | |||
|
14 | ||||
|
15 | mkdir foo | |||
|
16 | echo file > foo/file | |||
|
17 | hg ci -qAm 'add foo/file' -d '0 0' | |||
|
18 | ||||
|
19 | hg tag -d '0 0' some-tag | |||
|
20 | ||||
|
21 | hg log | |||
|
22 | cd .. | |||
|
23 | ||||
|
24 | hg convert orig new 2>&1 | grep -v 'subversion python bindings could not be loaded' | |||
|
25 | cd new | |||
|
26 | hg out ../orig | |||
|
27 | true |
@@ -0,0 +1,33 b'' | |||||
|
1 | changeset: 3:593cbf6fb2b4 | |||
|
2 | tag: tip | |||
|
3 | user: test | |||
|
4 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
5 | summary: Added tag some-tag for changeset ad681a868e44 | |||
|
6 | ||||
|
7 | changeset: 2:ad681a868e44 | |||
|
8 | tag: some-tag | |||
|
9 | user: test | |||
|
10 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
11 | summary: add foo/file | |||
|
12 | ||||
|
13 | changeset: 1:cbba8ecc03b7 | |||
|
14 | user: test | |||
|
15 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
16 | summary: remove foo | |||
|
17 | ||||
|
18 | changeset: 0:327daa9251fa | |||
|
19 | user: test | |||
|
20 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
21 | summary: add foo and bar | |||
|
22 | ||||
|
23 | initializing destination new repository | |||
|
24 | scanning source... | |||
|
25 | sorting... | |||
|
26 | converting... | |||
|
27 | 3 add foo and bar | |||
|
28 | 2 remove foo | |||
|
29 | 1 add foo/file | |||
|
30 | 0 Added tag some-tag for changeset ad681a868e44 | |||
|
31 | comparing with ../orig | |||
|
32 | searching for changes | |||
|
33 | no changes found |
@@ -1,209 +1,209 b'' | |||||
1 | # hg backend for convert extension |
|
1 | # hg backend for convert extension | |
2 |
|
2 | |||
3 | # Note for hg->hg conversion: Old versions of Mercurial didn't trim |
|
3 | # Note for hg->hg conversion: Old versions of Mercurial didn't trim | |
4 | # the whitespace from the ends of commit messages, but new versions |
|
4 | # the whitespace from the ends of commit messages, but new versions | |
5 | # do. Changesets created by those older versions, then converted, may |
|
5 | # do. Changesets created by those older versions, then converted, may | |
6 | # thus have different hashes for changesets that are otherwise |
|
6 | # thus have different hashes for changesets that are otherwise | |
7 | # identical. |
|
7 | # identical. | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | import os, time |
|
10 | import os, time | |
11 | from mercurial.i18n import _ |
|
11 | from mercurial.i18n import _ | |
12 | from mercurial.node import * |
|
12 | from mercurial.node import * | |
13 | from mercurial import hg, lock, revlog, util |
|
13 | from mercurial import hg, lock, revlog, util | |
14 |
|
14 | |||
15 | from common import NoRepo, commit, converter_source, converter_sink |
|
15 | from common import NoRepo, commit, converter_source, converter_sink | |
16 |
|
16 | |||
17 | class mercurial_sink(converter_sink): |
|
17 | class mercurial_sink(converter_sink): | |
18 | def __init__(self, ui, path): |
|
18 | def __init__(self, ui, path): | |
19 | self.path = path |
|
19 | self.path = path | |
20 | self.ui = ui |
|
20 | self.ui = ui | |
21 | self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True) |
|
21 | self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True) | |
22 | self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False) |
|
22 | self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False) | |
23 | self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default') |
|
23 | self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default') | |
24 | self.lastbranch = None |
|
24 | self.lastbranch = None | |
25 | try: |
|
25 | try: | |
26 | self.repo = hg.repository(self.ui, path) |
|
26 | self.repo = hg.repository(self.ui, path) | |
27 | except: |
|
27 | except: | |
28 | raise NoRepo("could not open hg repo %s as sink" % path) |
|
28 | raise NoRepo("could not open hg repo %s as sink" % path) | |
29 | self.lock = None |
|
29 | self.lock = None | |
30 | self.wlock = None |
|
30 | self.wlock = None | |
31 |
|
31 | |||
32 | def before(self): |
|
32 | def before(self): | |
33 | self.wlock = self.repo.wlock() |
|
33 | self.wlock = self.repo.wlock() | |
34 | self.lock = self.repo.lock() |
|
34 | self.lock = self.repo.lock() | |
35 |
|
35 | |||
36 | def after(self): |
|
36 | def after(self): | |
37 | self.lock = None |
|
37 | self.lock = None | |
38 | self.wlock = None |
|
38 | self.wlock = None | |
39 |
|
39 | |||
40 | def revmapfile(self): |
|
40 | def revmapfile(self): | |
41 | return os.path.join(self.path, ".hg", "shamap") |
|
41 | return os.path.join(self.path, ".hg", "shamap") | |
42 |
|
42 | |||
43 | def authorfile(self): |
|
43 | def authorfile(self): | |
44 | return os.path.join(self.path, ".hg", "authormap") |
|
44 | return os.path.join(self.path, ".hg", "authormap") | |
45 |
|
45 | |||
46 | def getheads(self): |
|
46 | def getheads(self): | |
47 | h = self.repo.changelog.heads() |
|
47 | h = self.repo.changelog.heads() | |
48 | return [ hex(x) for x in h ] |
|
48 | return [ hex(x) for x in h ] | |
49 |
|
49 | |||
50 | def putfile(self, f, e, data): |
|
50 | def putfile(self, f, e, data): | |
51 | self.repo.wwrite(f, data, e) |
|
51 | self.repo.wwrite(f, data, e) | |
52 | if f not in self.repo.dirstate: |
|
52 | if f not in self.repo.dirstate: | |
53 |
self.repo.dirstate. |
|
53 | self.repo.dirstate.normallookup(f) | |
54 |
|
54 | |||
55 | def copyfile(self, source, dest): |
|
55 | def copyfile(self, source, dest): | |
56 | self.repo.copy(source, dest) |
|
56 | self.repo.copy(source, dest) | |
57 |
|
57 | |||
58 | def delfile(self, f): |
|
58 | def delfile(self, f): | |
59 | try: |
|
59 | try: | |
60 | os.unlink(self.repo.wjoin(f)) |
|
60 | os.unlink(self.repo.wjoin(f)) | |
61 | #self.repo.remove([f]) |
|
61 | #self.repo.remove([f]) | |
62 | except: |
|
62 | except: | |
63 | pass |
|
63 | pass | |
64 |
|
64 | |||
65 | def setbranch(self, branch, pbranch, parents): |
|
65 | def setbranch(self, branch, pbranch, parents): | |
66 | if (not self.clonebranches) or (branch == self.lastbranch): |
|
66 | if (not self.clonebranches) or (branch == self.lastbranch): | |
67 | return |
|
67 | return | |
68 |
|
68 | |||
69 | self.lastbranch = branch |
|
69 | self.lastbranch = branch | |
70 | self.after() |
|
70 | self.after() | |
71 | if not branch: |
|
71 | if not branch: | |
72 | branch = 'default' |
|
72 | branch = 'default' | |
73 | if not pbranch: |
|
73 | if not pbranch: | |
74 | pbranch = 'default' |
|
74 | pbranch = 'default' | |
75 |
|
75 | |||
76 | branchpath = os.path.join(self.path, branch) |
|
76 | branchpath = os.path.join(self.path, branch) | |
77 | try: |
|
77 | try: | |
78 | self.repo = hg.repository(self.ui, branchpath) |
|
78 | self.repo = hg.repository(self.ui, branchpath) | |
79 | except: |
|
79 | except: | |
80 | if not parents: |
|
80 | if not parents: | |
81 | self.repo = hg.repository(self.ui, branchpath, create=True) |
|
81 | self.repo = hg.repository(self.ui, branchpath, create=True) | |
82 | else: |
|
82 | else: | |
83 | self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch)) |
|
83 | self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch)) | |
84 | hg.clone(self.ui, os.path.join(self.path, pbranch), |
|
84 | hg.clone(self.ui, os.path.join(self.path, pbranch), | |
85 | branchpath, rev=parents, update=False, |
|
85 | branchpath, rev=parents, update=False, | |
86 | stream=True) |
|
86 | stream=True) | |
87 | self.repo = hg.repository(self.ui, branchpath) |
|
87 | self.repo = hg.repository(self.ui, branchpath) | |
88 |
|
88 | |||
89 | def putcommit(self, files, parents, commit): |
|
89 | def putcommit(self, files, parents, commit): | |
90 | seen = {} |
|
90 | seen = {} | |
91 | pl = [] |
|
91 | pl = [] | |
92 | for p in parents: |
|
92 | for p in parents: | |
93 | if p not in seen: |
|
93 | if p not in seen: | |
94 | pl.append(p) |
|
94 | pl.append(p) | |
95 | seen[p] = 1 |
|
95 | seen[p] = 1 | |
96 | parents = pl |
|
96 | parents = pl | |
97 |
|
97 | |||
98 | if len(parents) < 2: parents.append("0" * 40) |
|
98 | if len(parents) < 2: parents.append("0" * 40) | |
99 | if len(parents) < 2: parents.append("0" * 40) |
|
99 | if len(parents) < 2: parents.append("0" * 40) | |
100 | p2 = parents.pop(0) |
|
100 | p2 = parents.pop(0) | |
101 |
|
101 | |||
102 | text = commit.desc |
|
102 | text = commit.desc | |
103 | extra = {} |
|
103 | extra = {} | |
104 | if self.branchnames and commit.branch: |
|
104 | if self.branchnames and commit.branch: | |
105 | extra['branch'] = commit.branch |
|
105 | extra['branch'] = commit.branch | |
106 | if commit.rev: |
|
106 | if commit.rev: | |
107 | extra['convert_revision'] = commit.rev |
|
107 | extra['convert_revision'] = commit.rev | |
108 |
|
108 | |||
109 | while parents: |
|
109 | while parents: | |
110 | p1 = p2 |
|
110 | p1 = p2 | |
111 | p2 = parents.pop(0) |
|
111 | p2 = parents.pop(0) | |
112 | a = self.repo.rawcommit(files, text, commit.author, commit.date, |
|
112 | a = self.repo.rawcommit(files, text, commit.author, commit.date, | |
113 | bin(p1), bin(p2), extra=extra) |
|
113 | bin(p1), bin(p2), extra=extra) | |
114 |
self.repo.dirstate. |
|
114 | self.repo.dirstate.clear() | |
115 | text = "(octopus merge fixup)\n" |
|
115 | text = "(octopus merge fixup)\n" | |
116 | p2 = hg.hex(self.repo.changelog.tip()) |
|
116 | p2 = hg.hex(self.repo.changelog.tip()) | |
117 |
|
117 | |||
118 | return p2 |
|
118 | return p2 | |
119 |
|
119 | |||
120 | def puttags(self, tags): |
|
120 | def puttags(self, tags): | |
121 | try: |
|
121 | try: | |
122 | old = self.repo.wfile(".hgtags").read() |
|
122 | old = self.repo.wfile(".hgtags").read() | |
123 | oldlines = old.splitlines(1) |
|
123 | oldlines = old.splitlines(1) | |
124 | oldlines.sort() |
|
124 | oldlines.sort() | |
125 | except: |
|
125 | except: | |
126 | oldlines = [] |
|
126 | oldlines = [] | |
127 |
|
127 | |||
128 | k = tags.keys() |
|
128 | k = tags.keys() | |
129 | k.sort() |
|
129 | k.sort() | |
130 | newlines = [] |
|
130 | newlines = [] | |
131 | for tag in k: |
|
131 | for tag in k: | |
132 | newlines.append("%s %s\n" % (tags[tag], tag)) |
|
132 | newlines.append("%s %s\n" % (tags[tag], tag)) | |
133 |
|
133 | |||
134 | newlines.sort() |
|
134 | newlines.sort() | |
135 |
|
135 | |||
136 | if newlines != oldlines: |
|
136 | if newlines != oldlines: | |
137 | self.ui.status("updating tags\n") |
|
137 | self.ui.status("updating tags\n") | |
138 | f = self.repo.wfile(".hgtags", "w") |
|
138 | f = self.repo.wfile(".hgtags", "w") | |
139 | f.write("".join(newlines)) |
|
139 | f.write("".join(newlines)) | |
140 | f.close() |
|
140 | f.close() | |
141 | if not oldlines: self.repo.add([".hgtags"]) |
|
141 | if not oldlines: self.repo.add([".hgtags"]) | |
142 | date = "%s 0" % int(time.mktime(time.gmtime())) |
|
142 | date = "%s 0" % int(time.mktime(time.gmtime())) | |
143 | extra = {} |
|
143 | extra = {} | |
144 | if self.tagsbranch != 'default': |
|
144 | if self.tagsbranch != 'default': | |
145 | extra['branch'] = self.tagsbranch |
|
145 | extra['branch'] = self.tagsbranch | |
146 | try: |
|
146 | try: | |
147 | tagparent = self.repo.changectx(self.tagsbranch).node() |
|
147 | tagparent = self.repo.changectx(self.tagsbranch).node() | |
148 | except hg.RepoError, inst: |
|
148 | except hg.RepoError, inst: | |
149 | tagparent = nullid |
|
149 | tagparent = nullid | |
150 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
|
150 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", | |
151 | date, tagparent, nullid) |
|
151 | date, tagparent, nullid) | |
152 | return hex(self.repo.changelog.tip()) |
|
152 | return hex(self.repo.changelog.tip()) | |
153 |
|
153 | |||
154 | class mercurial_source(converter_source): |
|
154 | class mercurial_source(converter_source): | |
155 | def __init__(self, ui, path, rev=None): |
|
155 | def __init__(self, ui, path, rev=None): | |
156 | converter_source.__init__(self, ui, path, rev) |
|
156 | converter_source.__init__(self, ui, path, rev) | |
157 | self.repo = hg.repository(self.ui, path) |
|
157 | self.repo = hg.repository(self.ui, path) | |
158 | self.lastrev = None |
|
158 | self.lastrev = None | |
159 | self.lastctx = None |
|
159 | self.lastctx = None | |
160 |
|
160 | |||
161 | def changectx(self, rev): |
|
161 | def changectx(self, rev): | |
162 | if self.lastrev != rev: |
|
162 | if self.lastrev != rev: | |
163 | self.lastctx = self.repo.changectx(rev) |
|
163 | self.lastctx = self.repo.changectx(rev) | |
164 | self.lastrev = rev |
|
164 | self.lastrev = rev | |
165 | return self.lastctx |
|
165 | return self.lastctx | |
166 |
|
166 | |||
167 | def getheads(self): |
|
167 | def getheads(self): | |
168 | if self.rev: |
|
168 | if self.rev: | |
169 | return [hex(self.repo.changectx(self.rev).node())] |
|
169 | return [hex(self.repo.changectx(self.rev).node())] | |
170 | else: |
|
170 | else: | |
171 | return [hex(node) for node in self.repo.heads()] |
|
171 | return [hex(node) for node in self.repo.heads()] | |
172 |
|
172 | |||
173 | def getfile(self, name, rev): |
|
173 | def getfile(self, name, rev): | |
174 | try: |
|
174 | try: | |
175 | return self.changectx(rev).filectx(name).data() |
|
175 | return self.changectx(rev).filectx(name).data() | |
176 | except revlog.LookupError, err: |
|
176 | except revlog.LookupError, err: | |
177 | raise IOError(err) |
|
177 | raise IOError(err) | |
178 |
|
178 | |||
179 | def getmode(self, name, rev): |
|
179 | def getmode(self, name, rev): | |
180 | m = self.changectx(rev).manifest() |
|
180 | m = self.changectx(rev).manifest() | |
181 | return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '') |
|
181 | return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '') | |
182 |
|
182 | |||
183 | def getchanges(self, rev): |
|
183 | def getchanges(self, rev): | |
184 | ctx = self.changectx(rev) |
|
184 | ctx = self.changectx(rev) | |
185 | m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3] |
|
185 | m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3] | |
186 | changes = [(name, rev) for name in m + a + r] |
|
186 | changes = [(name, rev) for name in m + a + r] | |
187 | changes.sort() |
|
187 | changes.sort() | |
188 | return (changes, self.getcopies(ctx)) |
|
188 | return (changes, self.getcopies(ctx)) | |
189 |
|
189 | |||
190 | def getcopies(self, ctx): |
|
190 | def getcopies(self, ctx): | |
191 | added = self.repo.status(ctx.parents()[0].node(), ctx.node())[1] |
|
191 | added = self.repo.status(ctx.parents()[0].node(), ctx.node())[1] | |
192 | copies = {} |
|
192 | copies = {} | |
193 | for name in added: |
|
193 | for name in added: | |
194 | try: |
|
194 | try: | |
195 | copies[name] = ctx.filectx(name).renamed()[0] |
|
195 | copies[name] = ctx.filectx(name).renamed()[0] | |
196 | except TypeError: |
|
196 | except TypeError: | |
197 | pass |
|
197 | pass | |
198 | return copies |
|
198 | return copies | |
199 |
|
199 | |||
200 | def getcommit(self, rev): |
|
200 | def getcommit(self, rev): | |
201 | ctx = self.changectx(rev) |
|
201 | ctx = self.changectx(rev) | |
202 | parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] |
|
202 | parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] | |
203 | return commit(author=ctx.user(), date=util.datestr(ctx.date()), |
|
203 | return commit(author=ctx.user(), date=util.datestr(ctx.date()), | |
204 | desc=ctx.description(), parents=parents, |
|
204 | desc=ctx.description(), parents=parents, | |
205 | branch=ctx.branch()) |
|
205 | branch=ctx.branch()) | |
206 |
|
206 | |||
207 | def gettags(self): |
|
207 | def gettags(self): | |
208 | tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
|
208 | tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] | |
209 | return dict([(name, hex(node)) for name, node in tags]) |
|
209 | return dict([(name, hex(node)) for name, node in tags]) |
General Comments 0
You need to be logged in to leave comments.
Login now