1 # Copyright (C) 2005-2006 Jelmer Vernooij <jelmer@samba.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 Support for foreign branches (Subversion)
26 required_bzr_version = (0,13)
28 def check_bzrlib_version(desired):
29 """Check that bzrlib is compatible.
31 If version is < desired version, assume incompatible.
32 If version == desired version, assume completely compatible
33 If version == desired version + 1, assume compatible, with deprecations
34 Otherwise, assume incompatible.
36 desired_plus = (desired[0], desired[1]+1)
37 bzrlib_version = bzrlib.version_info[:2]
38 if bzrlib_version == desired:
41 from bzrlib.trace import warning
43 # get the message out any way we can
44 from warnings import warn as warning
45 if bzrlib_version < desired:
46 warning('Installed bzr version %s is too old to be used with bzr-svn'
47 ' %s.' % (bzrlib.__version__, __version__))
48 # Not using BzrNewError, because it may not exist.
49 raise Exception, ('Version mismatch', desired)
51 warning('bzr-svn is not up to date with installed bzr version %s.'
52 ' \nThere should be a newer version available, e.g. %i.%i.'
53 % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
54 if bzrlib_version != desired_plus:
55 raise Exception, 'Version mismatch'
57 check_bzrlib_version(required_bzr_version)
66 def convert_svn_exception(unbound):
67 """Decorator that catches particular Subversion exceptions and
68 converts them to Bazaar exceptions.
70 def convert(self, *args, **kwargs):
72 unbound(self, *args, **kwargs)
73 except SubversionException, (msg, num):
74 if num == svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED:
75 raise ConnectionReset(msg=msg)
79 convert.__doc__ = unbound.__doc__
80 convert.__name__ = unbound.__name__
83 from bzrlib.transport import register_transport
84 register_transport('svn:', transport.SvnRaTransport)
85 register_transport('svn+', transport.SvnRaTransport)
87 from bzrlib.bzrdir import BzrDirFormat
89 from bzrlib.repository import InterRepository
91 from fetch import InterSvnRepository
93 BzrDirFormat.register_control_format(format.SvnFormat)
95 BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
97 BzrDirFormat.register_control_format(dumpfile.SvnDumpFileFormat)
99 InterRepository.register_optimiser(InterSvnRepository)
101 from bzrlib.commands import Command, register_command, display_command, Option
103 class cmd_import_svn(Command):
104 """Convert a Subversion repository to a Bazaar repository.
107 takes_args = ['url', 'output_dir']
108 takes_options = [Option('trees', help='Create working trees'),
109 Option('shared', help='Create shared repository')]
112 def run(self, url, output_dir, trees=False, shared=False):
113 from convert import convert_repository
114 from scheme import TrunkBranchingScheme
115 # TODO: support non-trunk branching schemes
116 convert_repository(url, output_dir, TrunkBranchingScheme(), shared,
120 register_command(cmd_import_svn)
123 from unittest import TestSuite, TestLoader
128 suite.addTest(tests.test_suite())
132 if __name__ == '__main__':
133 print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
136 sys.path.append(os.path.dirname(__file__))