##// END OF EJS Templates
convert: hg: optionally create branches as clones...
Brendan Cully -
r5173:6b4c332f default
parent child Browse files
Show More
@@ -194,6 +194,12 b' class convert(object):'
194 filenames = []
194 filenames = []
195
195
196 files, copies = self.source.getchanges(rev)
196 files, copies = self.source.getchanges(rev)
197 parents = [self.map[r] for r in commit.parents]
198 if commit.parents:
199 pbranch = self.commitcache[commit.parents[0]].branch
200 else:
201 pbranch = None
202 self.dest.setbranch(commit.branch, pbranch, parents)
197 for f, v in files:
203 for f, v in files:
198 newf = self.mapfile(f)
204 newf = self.mapfile(f)
199 if not newf:
205 if not newf:
@@ -213,7 +219,6 b' class convert(object):'
213 # Merely marks that a copy happened.
219 # Merely marks that a copy happened.
214 self.dest.copyfile(copyf, newf)
220 self.dest.copyfile(copyf, newf)
215
221
216 parents = [self.map[r] for r in commit.parents]
217 newnode = self.dest.putcommit(filenames, parents, commit)
222 newnode = self.dest.putcommit(filenames, parents, commit)
218 self.mapentry(rev, newnode)
223 self.mapentry(rev, newnode)
219
224
@@ -134,3 +134,10 b' class converter_sink(object):'
134 tags: {tagname: sink_rev_id, ...}"""
134 tags: {tagname: sink_rev_id, ...}"""
135 raise NotImplementedError()
135 raise NotImplementedError()
136
136
137 def setbranch(self, branch, pbranch, parents):
138 """Set the current branch name. Called before the first putfile
139 on the branch.
140 branch: branch name for subsequent commits
141 pbranch: branch name of parent commit
142 parents: destination revisions of parent"""
143 pass
@@ -18,13 +18,15 b' 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)
22 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
23 self.lastbranch = None
21 try:
24 try:
22 self.repo = hg.repository(self.ui, path)
25 self.repo = hg.repository(self.ui, path)
23 except:
26 except:
24 raise NoRepo("could not open hg repo %s as sink" % path)
27 raise NoRepo("could not open hg repo %s as sink" % path)
25 self.lock = None
28 self.lock = None
26 self.wlock = None
29 self.wlock = None
27 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
28
30
29 def before(self):
31 def before(self):
30 self.wlock = self.repo.wlock()
32 self.wlock = self.repo.wlock()
@@ -59,6 +61,30 b' class mercurial_sink(converter_sink):'
59 except:
61 except:
60 pass
62 pass
61
63
64 def setbranch(self, branch, pbranch, parents):
65 if (not self.clonebranches) or (branch == self.lastbranch):
66 return
67
68 self.lastbranch = branch
69 self.after()
70 if not branch:
71 branch = 'default'
72 if not pbranch:
73 pbranch = 'default'
74
75 branchpath = os.path.join(self.path, branch)
76 try:
77 self.repo = hg.repository(self.ui, branchpath)
78 except:
79 if not parents:
80 self.repo = hg.repository(self.ui, branchpath, create=True)
81 else:
82 self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch))
83 hg.clone(self.ui, os.path.join(self.path, pbranch),
84 branchpath, rev=parents, update=False,
85 stream=True)
86 self.repo = hg.repository(self.ui, branchpath)
87
62 def putcommit(self, files, parents, commit):
88 def putcommit(self, files, parents, commit):
63 if not files:
89 if not files:
64 return hex(self.repo.changelog.tip())
90 return hex(self.repo.changelog.tip())
General Comments 0
You need to be logged in to leave comments. Login now