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