##// END OF EJS Templates
convert: mercurial_source: also search for copies in modified files...
Alexis S. L. Carvalho -
r5280:11e1e574 default
parent child Browse files
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 # 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 self.repo.dirstate.clear()
35 self.repo.dirstate.clear()
36
36
37 def after(self):
37 def after(self):
38 self.repo.dirstate.invalidate()
38 self.repo.dirstate.invalidate()
39 self.lock = None
39 self.lock = None
40 self.wlock = None
40 self.wlock = None
41
41
42 def revmapfile(self):
42 def revmapfile(self):
43 return os.path.join(self.path, ".hg", "shamap")
43 return os.path.join(self.path, ".hg", "shamap")
44
44
45 def authorfile(self):
45 def authorfile(self):
46 return os.path.join(self.path, ".hg", "authormap")
46 return os.path.join(self.path, ".hg", "authormap")
47
47
48 def getheads(self):
48 def getheads(self):
49 h = self.repo.changelog.heads()
49 h = self.repo.changelog.heads()
50 return [ hex(x) for x in h ]
50 return [ hex(x) for x in h ]
51
51
52 def putfile(self, f, e, data):
52 def putfile(self, f, e, data):
53 self.repo.wwrite(f, data, e)
53 self.repo.wwrite(f, data, e)
54 if f not in self.repo.dirstate:
54 if f not in self.repo.dirstate:
55 self.repo.dirstate.normallookup(f)
55 self.repo.dirstate.normallookup(f)
56
56
57 def copyfile(self, source, dest):
57 def copyfile(self, source, dest):
58 self.repo.copy(source, dest)
58 self.repo.copy(source, dest)
59
59
60 def delfile(self, f):
60 def delfile(self, f):
61 try:
61 try:
62 os.unlink(self.repo.wjoin(f))
62 os.unlink(self.repo.wjoin(f))
63 #self.repo.remove([f])
63 #self.repo.remove([f])
64 except:
64 except:
65 pass
65 pass
66
66
67 def setbranch(self, branch, pbranch, parents):
67 def setbranch(self, branch, pbranch, parents):
68 if (not self.clonebranches) or (branch == self.lastbranch):
68 if (not self.clonebranches) or (branch == self.lastbranch):
69 return
69 return
70
70
71 self.lastbranch = branch
71 self.lastbranch = branch
72 self.after()
72 self.after()
73 if not branch:
73 if not branch:
74 branch = 'default'
74 branch = 'default'
75 if not pbranch:
75 if not pbranch:
76 pbranch = 'default'
76 pbranch = 'default'
77
77
78 branchpath = os.path.join(self.path, branch)
78 branchpath = os.path.join(self.path, branch)
79 try:
79 try:
80 self.repo = hg.repository(self.ui, branchpath)
80 self.repo = hg.repository(self.ui, branchpath)
81 except:
81 except:
82 if not parents:
82 if not parents:
83 self.repo = hg.repository(self.ui, branchpath, create=True)
83 self.repo = hg.repository(self.ui, branchpath, create=True)
84 else:
84 else:
85 self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch))
85 self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch))
86 hg.clone(self.ui, os.path.join(self.path, pbranch),
86 hg.clone(self.ui, os.path.join(self.path, pbranch),
87 branchpath, rev=parents, update=False,
87 branchpath, rev=parents, update=False,
88 stream=True)
88 stream=True)
89 self.repo = hg.repository(self.ui, branchpath)
89 self.repo = hg.repository(self.ui, branchpath)
90
90
91 def putcommit(self, files, parents, commit):
91 def putcommit(self, files, parents, commit):
92 seen = {}
92 seen = {}
93 pl = []
93 pl = []
94 for p in parents:
94 for p in parents:
95 if p not in seen:
95 if p not in seen:
96 pl.append(p)
96 pl.append(p)
97 seen[p] = 1
97 seen[p] = 1
98 parents = pl
98 parents = pl
99
99
100 if len(parents) < 2: parents.append("0" * 40)
100 if len(parents) < 2: parents.append("0" * 40)
101 if len(parents) < 2: parents.append("0" * 40)
101 if len(parents) < 2: parents.append("0" * 40)
102 p2 = parents.pop(0)
102 p2 = parents.pop(0)
103
103
104 text = commit.desc
104 text = commit.desc
105 extra = {}
105 extra = {}
106 if self.branchnames and commit.branch:
106 if self.branchnames and commit.branch:
107 extra['branch'] = commit.branch
107 extra['branch'] = commit.branch
108 if commit.rev:
108 if commit.rev:
109 extra['convert_revision'] = commit.rev
109 extra['convert_revision'] = commit.rev
110
110
111 while parents:
111 while parents:
112 p1 = p2
112 p1 = p2
113 p2 = parents.pop(0)
113 p2 = parents.pop(0)
114 a = self.repo.rawcommit(files, text, commit.author, commit.date,
114 a = self.repo.rawcommit(files, text, commit.author, commit.date,
115 bin(p1), bin(p2), extra=extra)
115 bin(p1), bin(p2), extra=extra)
116 self.repo.dirstate.clear()
116 self.repo.dirstate.clear()
117 text = "(octopus merge fixup)\n"
117 text = "(octopus merge fixup)\n"
118 p2 = hg.hex(self.repo.changelog.tip())
118 p2 = hg.hex(self.repo.changelog.tip())
119
119
120 return p2
120 return p2
121
121
122 def puttags(self, tags):
122 def puttags(self, tags):
123 try:
123 try:
124 old = self.repo.wfile(".hgtags").read()
124 old = self.repo.wfile(".hgtags").read()
125 oldlines = old.splitlines(1)
125 oldlines = old.splitlines(1)
126 oldlines.sort()
126 oldlines.sort()
127 except:
127 except:
128 oldlines = []
128 oldlines = []
129
129
130 k = tags.keys()
130 k = tags.keys()
131 k.sort()
131 k.sort()
132 newlines = []
132 newlines = []
133 for tag in k:
133 for tag in k:
134 newlines.append("%s %s\n" % (tags[tag], tag))
134 newlines.append("%s %s\n" % (tags[tag], tag))
135
135
136 newlines.sort()
136 newlines.sort()
137
137
138 if newlines != oldlines:
138 if newlines != oldlines:
139 self.ui.status("updating tags\n")
139 self.ui.status("updating tags\n")
140 f = self.repo.wfile(".hgtags", "w")
140 f = self.repo.wfile(".hgtags", "w")
141 f.write("".join(newlines))
141 f.write("".join(newlines))
142 f.close()
142 f.close()
143 if not oldlines: self.repo.add([".hgtags"])
143 if not oldlines: self.repo.add([".hgtags"])
144 date = "%s 0" % int(time.mktime(time.gmtime()))
144 date = "%s 0" % int(time.mktime(time.gmtime()))
145 extra = {}
145 extra = {}
146 if self.tagsbranch != 'default':
146 if self.tagsbranch != 'default':
147 extra['branch'] = self.tagsbranch
147 extra['branch'] = self.tagsbranch
148 try:
148 try:
149 tagparent = self.repo.changectx(self.tagsbranch).node()
149 tagparent = self.repo.changectx(self.tagsbranch).node()
150 except hg.RepoError, inst:
150 except hg.RepoError, inst:
151 tagparent = nullid
151 tagparent = nullid
152 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
152 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
153 date, tagparent, nullid)
153 date, tagparent, nullid)
154 return hex(self.repo.changelog.tip())
154 return hex(self.repo.changelog.tip())
155
155
156 class mercurial_source(converter_source):
156 class mercurial_source(converter_source):
157 def __init__(self, ui, path, rev=None):
157 def __init__(self, ui, path, rev=None):
158 converter_source.__init__(self, ui, path, rev)
158 converter_source.__init__(self, ui, path, rev)
159 self.repo = hg.repository(self.ui, path)
159 self.repo = hg.repository(self.ui, path)
160 self.lastrev = None
160 self.lastrev = None
161 self.lastctx = None
161 self.lastctx = None
162
162
163 def changectx(self, rev):
163 def changectx(self, rev):
164 if self.lastrev != rev:
164 if self.lastrev != rev:
165 self.lastctx = self.repo.changectx(rev)
165 self.lastctx = self.repo.changectx(rev)
166 self.lastrev = rev
166 self.lastrev = rev
167 return self.lastctx
167 return self.lastctx
168
168
169 def getheads(self):
169 def getheads(self):
170 if self.rev:
170 if self.rev:
171 return [hex(self.repo.changectx(self.rev).node())]
171 return [hex(self.repo.changectx(self.rev).node())]
172 else:
172 else:
173 return [hex(node) for node in self.repo.heads()]
173 return [hex(node) for node in self.repo.heads()]
174
174
175 def getfile(self, name, rev):
175 def getfile(self, name, rev):
176 try:
176 try:
177 return self.changectx(rev).filectx(name).data()
177 return self.changectx(rev).filectx(name).data()
178 except revlog.LookupError, err:
178 except revlog.LookupError, err:
179 raise IOError(err)
179 raise IOError(err)
180
180
181 def getmode(self, name, rev):
181 def getmode(self, name, rev):
182 m = self.changectx(rev).manifest()
182 m = self.changectx(rev).manifest()
183 return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '')
183 return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '')
184
184
185 def getchanges(self, rev):
185 def getchanges(self, rev):
186 ctx = self.changectx(rev)
186 ctx = self.changectx(rev)
187 m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3]
187 m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3]
188 changes = [(name, rev) for name in m + a + r]
188 changes = [(name, rev) for name in m + a + r]
189 changes.sort()
189 changes.sort()
190 return (changes, self.getcopies(ctx))
190 return (changes, self.getcopies(ctx, m + a))
191
191
192 def getcopies(self, ctx):
192 def getcopies(self, ctx, files):
193 added = self.repo.status(ctx.parents()[0].node(), ctx.node())[1]
194 copies = {}
193 copies = {}
195 for name in added:
194 for name in files:
196 try:
195 try:
197 copies[name] = ctx.filectx(name).renamed()[0]
196 copies[name] = ctx.filectx(name).renamed()[0]
198 except TypeError:
197 except TypeError:
199 pass
198 pass
200 return copies
199 return copies
201
200
202 def getcommit(self, rev):
201 def getcommit(self, rev):
203 ctx = self.changectx(rev)
202 ctx = self.changectx(rev)
204 parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid]
203 parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid]
205 return commit(author=ctx.user(), date=util.datestr(ctx.date()),
204 return commit(author=ctx.user(), date=util.datestr(ctx.date()),
206 desc=ctx.description(), parents=parents,
205 desc=ctx.description(), parents=parents,
207 branch=ctx.branch())
206 branch=ctx.branch())
208
207
209 def gettags(self):
208 def gettags(self):
210 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
209 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
211 return dict([(name, hex(node)) for name, node in tags])
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