comparison hgfastimport/hgimport.py @ 58:c370e587f483

Handle commits commands that reference a tag better.
author Greg Ward <gward@intelerad.com>
date Mon, 01 Aug 2011 18:35:31 -0400
parents e827bffa5fc5
children c82b6a84884f
comparison
equal deleted inserted replaced
57:e827bffa5fc5 58:c370e587f483
126 processor.parseMany(self.sources, parser.ImportParser, self.processor) 126 processor.parseMany(self.sources, parser.ImportParser, self.processor)
127 self.parsed = True 127 self.parsed = True
128 128
129 class HgImportProcessor(processor.ImportProcessor): 129 class HgImportProcessor(processor.ImportProcessor):
130 130
131 tagprefix = "refs/tags/"
132
131 def __init__(self, ui, repo): 133 def __init__(self, ui, repo):
132 super(HgImportProcessor, self).__init__() 134 super(HgImportProcessor, self).__init__()
133 self.ui = ui 135 self.ui = ui
134 self.repo = repo 136 self.repo = repo
135 137
200 # This command means nothing to us 202 # This command means nothing to us
201 pass 203 pass
202 204
203 def _getcommit(self, commitref): 205 def _getcommit(self, commitref):
204 """Given a mark reference or a branch name, return the 206 """Given a mark reference or a branch name, return the
205 appropriate commit object. Return None if committish is a 207 appropriate commit object. Return None if commitref is a tag
206 branch with no commits. Raises KeyError if anything else is out 208 or a branch with no commits. Raises KeyError if anything else
207 of whack. 209 is out of whack.
208 """ 210 """
209 if commitref.startswith(":"): 211 if commitref.startswith(":"):
210 # KeyError here indicates the input stream is broken. 212 # KeyError here indicates the input stream is broken.
211 return self.commitmap[commitref] 213 return self.commitmap[commitref]
214 elif commitref.startswith(self.tagprefix):
215 return None
212 else: 216 else:
213 branch = self._getbranch(commitref) 217 branch = self._getbranch(commitref)
214 if branch is None: 218 if branch is None:
215 raise ValueError("invalid commit ref: %r" % commitref) 219 raise ValueError("invalid commit ref: %r" % commitref)
216 220
243 # refs/heads), and implies that it can be called whatever the 247 # refs/heads), and implies that it can be called whatever the
244 # creator of the fastimport dump wants to call it. So the name 248 # creator of the fastimport dump wants to call it. So the name
245 # of the fixup branch should be configurable! 249 # of the fixup branch should be configurable!
246 fixup = (cmd.ref == "refs/heads/TAG.FIXUP") 250 fixup = (cmd.ref == "refs/heads/TAG.FIXUP")
247 251
252 if cmd.ref.startswith(self.tagprefix) and cmd.mark:
253 tag = cmd.ref[len(self.tagprefix):]
254 self.tags.append((tag, ':' + cmd.mark))
255
248 if cmd.from_: 256 if cmd.from_:
249 first_parent = cmd.from_ 257 first_parent = cmd.from_
250 else: 258 else:
251 first_parent = self._getcommit(cmd.ref) # commit object 259 first_parent = self._getcommit(cmd.ref) # commit object
252 if first_parent is not None: 260 if first_parent is not None:
332 # print "go for it" 340 # print "go for it"
333 #return res 341 #return res
334 return "%d %d" % res 342 return "%d %d" % res
335 343
336 def reset_handler(self, cmd): 344 def reset_handler(self, cmd):
337 tagprefix = "refs/tags/"
338 branch = self._getbranch(cmd.ref) 345 branch = self._getbranch(cmd.ref)
339 if branch: 346 if branch:
340 # The usual case for 'reset': (re)create the named branch. 347 # The usual case for 'reset': (re)create the named branch.
341 # XXX what should we do if cmd.from_ is None? 348 # XXX what should we do if cmd.from_ is None?
342 if cmd.from_ is not None: 349 if cmd.from_ is not None:
348 except KeyError: 355 except KeyError:
349 pass 356 pass
350 #else: 357 #else:
351 # # XXX filename? line number? 358 # # XXX filename? line number?
352 # self.ui.warn("ignoring branch reset with no 'from'\n") 359 # self.ui.warn("ignoring branch reset with no 'from'\n")
353 elif cmd.ref.startswith(tagprefix): 360 elif cmd.ref.startswith(self.tagprefix):
354 # Create a "lightweight tag" in Git terms. As I understand 361 # Create a "lightweight tag" in Git terms. As I understand
355 # it, that's a tag with no description and no history -- 362 # it, that's a tag with no description and no history --
356 # rather like CVS tags. cvs2git turns CVS tags into Git 363 # rather like CVS tags. cvs2git turns CVS tags into Git
357 # lightweight tags, so we should make sure they become 364 # lightweight tags, so we should make sure they become
358 # Mercurial tags. But we don't have to fake a history for 365 # Mercurial tags. But we don't have to fake a history for
359 # them; save them up for the end. 366 # them; save them up for the end.
360 tag = cmd.ref[len(tagprefix):] 367 if cmd.from_ is not None:
361 self.tags.append((tag, cmd.from_)) 368 tag = cmd.ref[len(self.tagprefix):]
369 self.tags.append((tag, cmd.from_))
362 370
363 def tag_handler(self, cmd): 371 def tag_handler(self, cmd):
364 pass 372 pass
365 373
366 374