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