comparison contrib/convert-repo @ 4447:af013ae3ca10

use documented convert-repo interface
author Daniel Holth <dholth@fastmail.fm>
date Wed, 16 May 2007 01:10:12 -0400
parents 1b75e0eff532
children
comparison
equal deleted inserted replaced
4446:1b75e0eff532 4447:af013ae3ca10
28 from mercurial import hg, ui, util, fancyopts 28 from mercurial import hg, ui, util, fancyopts
29 29
30 class Abort(Exception): pass 30 class Abort(Exception): pass
31 class NoRepo(Exception): pass 31 class NoRepo(Exception): pass
32 32
33 class commit: 33 class commit(object):
34 def __init__(self, **parts): 34 def __init__(self, **parts):
35 for x in "author date desc parents".split(): 35 for x in "author date desc parents".split():
36 if not x in parts: 36 if not x in parts:
37 abort("commit missing field %s\n" % x) 37 abort("commit missing field %s\n" % x)
38 self.__dict__.update(parts) 38 self.__dict__.update(parts)
54 try: 54 try:
55 return s.decode("latin-1").encode("utf-8") 55 return s.decode("latin-1").encode("utf-8")
56 except: 56 except:
57 return s.decode("utf-8", "replace").encode("utf-8") 57 return s.decode("utf-8", "replace").encode("utf-8")
58 58
59 class converter_source: 59 class converter_source(object):
60 """Conversion source interface""" 60 """Conversion source interface"""
61 61
62 def __init__(self, path): 62 def __init__(self, path):
63 """Initialize conversion source (or raise NoRepo("message") 63 """Initialize conversion source (or raise NoRepo("message")
64 exception if path is not a valid repository)""" 64 exception if path is not a valid repository)"""
89 89
90 def gettags(self): 90 def gettags(self):
91 """Return the tags as a dictionary of name: revision""" 91 """Return the tags as a dictionary of name: revision"""
92 raise NotImplementedError() 92 raise NotImplementedError()
93 93
94 class converter_sink: 94 class converter_sink(object):
95 """Conversion sink (target) interface""" 95 """Conversion sink (target) interface"""
96 96
97 def __init__(self, path): 97 def __init__(self, path):
98 """Initialize conversion sink (or raise NoRepo("message") 98 """Initialize conversion sink (or raise NoRepo("message")
99 exception if path is not a valid repository)""" 99 exception if path is not a valid repository)"""
136 tags: {tagname: sink_rev_id, ...}""" 136 tags: {tagname: sink_rev_id, ...}"""
137 raise NotImplementedError() 137 raise NotImplementedError()
138 138
139 139
140 # CVS conversion code inspired by hg-cvs-import and git-cvsimport 140 # CVS conversion code inspired by hg-cvs-import and git-cvsimport
141 class convert_cvs: 141 class convert_cvs(converter_source):
142 def __init__(self, path): 142 def __init__(self, path):
143 self.path = path 143 self.path = path
144 cvs = os.path.join(path, "CVS") 144 cvs = os.path.join(path, "CVS")
145 if not os.path.exists(cvs): 145 if not os.path.exists(cvs):
146 raise NoRepo("couldn't open CVS repo %s" % path) 146 raise NoRepo("couldn't open CVS repo %s" % path)
367 return self.changeset[rev] 367 return self.changeset[rev]
368 368
369 def gettags(self): 369 def gettags(self):
370 return self.tags 370 return self.tags
371 371
372 class convert_git: 372 class convert_git(converter_source):
373 def __init__(self, path): 373 def __init__(self, path):
374 if os.path.isdir(path + "/.git"): 374 if os.path.isdir(path + "/.git"):
375 path += "/.git" 375 path += "/.git"
376 self.path = path 376 self.path = path
377 if not os.path.exists(path + "/objects"): 377 if not os.path.exists(path + "/objects"):
453 tag = tag[len(prefix):-3] 453 tag = tag[len(prefix):-3]
454 tags[tag] = node 454 tags[tag] = node
455 455
456 return tags 456 return tags
457 457
458 class convert_mercurial: 458 class convert_mercurial(converter_sink):
459 def __init__(self, path): 459 def __init__(self, path):
460 self.path = path 460 self.path = path
461 u = ui.ui() 461 u = ui.ui()
462 try: 462 try:
463 self.repo = hg.repository(u, path) 463 self.repo = hg.repository(u, path)
550 return c(path) 550 return c(path)
551 except NoRepo: 551 except NoRepo:
552 pass 552 pass
553 abort("%s: unknown repository type\n" % path) 553 abort("%s: unknown repository type\n" % path)
554 554
555 class convert: 555 class convert(object):
556 def __init__(self, source, dest, mapfile, opts): 556 def __init__(self, source, dest, mapfile, opts):
557 557
558 self.source = source 558 self.source = source
559 self.dest = dest 559 self.dest = dest
560 self.mapfile = mapfile 560 self.mapfile = mapfile