##// END OF EJS Templates
convert: split converter into convertsource and convertsink
Brendan Cully -
r4763:8e9d3fae default
parent child Browse files
Show More
@@ -5,7 +5,7 b''
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from common import NoRepo
8 from common import NoRepo, converter_source, converter_sink
9 9 from cvs import convert_cvs
10 10 from git import convert_git
11 11 from hg import convert_mercurial
@@ -17,18 +17,29 b' commands.norepo += " convert"'
17 17
18 18 converters = [convert_cvs, convert_git, convert_mercurial]
19 19
20 def converter(ui, path, rev=None):
20 def convertsource(ui, path, rev=None):
21 for c in converters:
22 try:
23 converter = c(ui, path, rev=rev)
24 if not isinstance(converter, converter_source):
25 raise util.Abort('%s: cannot read from this repository type' % path)
26 return converter
27 except NoRepo:
28 pass
29 raise util.Abort('%s: unknown repository type' % path)
30
31 def convertsink(ui, path):
21 32 if not os.path.isdir(path):
22 33 raise util.Abort("%s: not a directory" % path)
23 34 for c in converters:
24 35 try:
25 if rev:
26 return c(ui, path, rev=rev)
27 else:
28 return c(ui, path)
36 converter = c(ui, path)
37 if not isinstance(converter, converter_sink):
38 raise util.Abort('%s: cannot write to this repository type' % path)
39 return converter
29 40 except NoRepo:
30 41 pass
31 raise util.Abort("%s: unknown repository type" % path)
42 raise util.Abort('%s: unknown repository type' % path)
32 43
33 44 class convert(object):
34 45 def __init__(self, ui, source, dest, mapfile, opts):
@@ -302,14 +313,10 b' def _convert(ui, src, dest=None, mapfile'
302 313 hg.repository(ui, dest, create=True)
303 314 created = True
304 315
305 destc = converter(ui, dest)
306 if not hasattr(destc, "putcommit"):
307 raise util.Abort("%s: can't write to this repo type" % src)
316 destc = convertsink(ui, dest)
308 317
309 318 try:
310 srcc = converter(ui, src, rev=opts.get('rev'))
311 if not hasattr(srcc, "getcommit"):
312 raise util.Abort("%s: can't read from this repo type" % src)
319 srcc = convertsource(ui, src, rev=opts.get('rev'))
313 320 except Exception:
314 321 if created:
315 322 shutil.rmtree(dest, True)
@@ -6,7 +6,7 b' from mercurial import hg'
6 6 from common import NoRepo, converter_sink
7 7
8 8 class convert_mercurial(converter_sink):
9 def __init__(self, ui, path, rev=None):
9 def __init__(self, ui, path):
10 10 self.path = path
11 11 self.ui = ui
12 12 try:
General Comments 0
You need to be logged in to leave comments. Login now