1 # Copyright (C) 2005-2007 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)
25 from bzrlib.trace import warning
28 COMPATIBLE_BZR_VERSIONS = [(0, 15), (0, 16)]
30 def check_bzrlib_version(desired):
31 """Check that bzrlib is compatible.
33 If version is < all compatible version, assume incompatible.
34 If version is compatible version + 1, assume compatible, with deprecations
35 Otherwise, assume incompatible.
37 bzrlib_version = bzrlib.version_info[:2]
38 if bzrlib_version in desired:
40 if bzrlib_version < desired[0]:
41 warning('Installed bzr version %s is too old to be used with bzr-svn'
42 ' %s.' % (bzrlib.__version__, __version__))
43 # Not using BzrNewError, because it may not exist.
44 raise Exception, ('Version mismatch', desired)
46 warning('bzr-svn is not up to date with installed bzr version %s.'
47 ' \nThere should be a newer version of bzr-svn available.'
48 % (bzrlib.__version__))
49 if not (bzrlib_version[0], bzrlib_version[1]-1) in desired:
50 raise Exception, 'Version mismatch'
52 def check_subversion_version():
53 """Check that Subversion is compatible.
57 if not hasattr(svn.delta, 'svn_delta_invoke_txdelta_window_handler'):
58 warning('Installed Subversion version does not have updated Python '
59 'bindings. See the bzr-svn README for details.')
60 raise bzrlib.errors.BzrError("incompatible python subversion bindings")
62 def check_pysqlite_version():
63 """Check that sqlite library is compatible.
70 from pysqlite2 import dbapi2 as sqlite3
72 warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 '
74 raise bzrlib.errors.BzrError("missing sqlite library")
76 if (sqlite3.sqlite_version_info[0] < 3 or
77 (sqlite3.sqlite_version_info[0] == 3 and
78 sqlite3.sqlite_version_info[1] < 3)):
79 warning('Needs at least sqlite 3.3.x')
80 raise bzrlib.errors.BzrError("incompatible sqlite library")
82 check_bzrlib_version(COMPATIBLE_BZR_VERSIONS)
83 check_subversion_version()
84 check_pysqlite_version()
92 from bzrlib.transport import register_transport
93 register_transport('svn://', transport.SvnRaTransport)
94 register_transport('svn+', transport.SvnRaTransport)
96 from bzrlib.bzrdir import BzrDirFormat
98 from bzrlib.repository import InterRepository
100 from fetch import InterSvnRepository
102 BzrDirFormat.register_control_format(format.SvnFormat)
105 _subr_version = svn.core.svn_subr_version()
107 BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
109 InterRepository.register_optimiser(InterSvnRepository)
111 from bzrlib.branch import Branch
112 from bzrlib.commands import Command, register_command, display_command, Option
113 from bzrlib.errors import BzrCommandError
114 from bzrlib.repository import Repository
115 import bzrlib.urlutils as urlutils
118 def get_scheme(schemename):
119 """Parse scheme identifier and return a branching scheme."""
120 from scheme import BranchingScheme
122 ret = BranchingScheme.find_scheme(schemename)
124 raise BzrCommandError('No such branching scheme %r' % schemename)
128 class cmd_svn_import(Command):
129 """Convert a Subversion repository to a Bazaar repository.
132 takes_args = ['from_location', 'to_location?']
133 takes_options = [Option('trees', help='Create working trees'),
134 Option('shared', help='Create shared repository'),
136 help='Convert all revisions, even those not in '
137 'current branch history (implies --shared)'),
138 Option('scheme', type=get_scheme,
139 help='Branching scheme (none, trunk, or trunk-INT)')]
142 def run(self, from_location, to_location=None, trees=False,
143 shared=False, scheme=None, all=False):
144 from convert import convert_repository
145 from scheme import TrunkBranchingScheme
148 scheme = TrunkBranchingScheme()
150 if to_location is None:
151 to_location = os.path.basename(from_location.rstrip("/\\"))
155 convert_repository(from_location, to_location, scheme, shared, trees,
159 register_command(cmd_svn_import)
161 class cmd_svn_upgrade(Command):
162 """Upgrade the revisions mapped from Subversion in a Bazaar branch.
164 This will change the revision ids of revisions whose parents
165 were mapped from svn revisions.
167 takes_args = ['svn_repository?']
168 takes_options = [Option('allow-changes', help='Allow content changes')]
171 def run(self, svn_repository=None, allow_changes=False):
172 from upgrade import upgrade_branch
174 branch_to = Branch.open(".")
176 stored_loc = branch_to.get_parent()
177 if svn_repository is None:
178 if stored_loc is None:
179 raise BzrCommandError("No pull location known or"
182 display_url = urlutils.unescape_for_display(stored_loc,
184 self.outf.write("Using saved location: %s\n" % display_url)
185 svn_repository = stored_loc
187 upgrade_branch(branch_to, Repository.open(svn_repository),
190 register_command(cmd_svn_upgrade)
194 from unittest import TestSuite
197 suite.addTest(tests.test_suite())
200 if __name__ == '__main__':
201 print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
203 runner = unittest.TextTestRunner()
204 runner.run(test_suite())
206 sys.path.append(os.path.dirname(os.path.abspath(__file__)))