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)
26 from bzrlib.trace import warning
28 # get the message out any way we can
29 from warnings import warn as warning
32 required_bzr_version = (0,16)
34 def check_bzrlib_version(desired):
35 """Check that bzrlib is compatible.
37 If version is < desired version, assume incompatible.
38 If version == desired version, assume completely compatible
39 If version == desired version + 1, assume compatible, with deprecations
40 Otherwise, assume incompatible.
42 desired_plus = (desired[0], desired[1]+1)
43 bzrlib_version = bzrlib.version_info[:2]
44 if bzrlib_version == desired:
46 if bzrlib_version < desired:
47 warning('Installed bzr version %s is too old to be used with bzr-svn'
48 ' %s.' % (bzrlib.__version__, __version__))
49 # Not using BzrNewError, because it may not exist.
50 raise Exception, ('Version mismatch', desired)
52 warning('bzr-svn is not up to date with installed bzr version %s.'
53 ' \nThere should be a newer version of bzr-svn available.'
54 % (bzrlib.__version__))
55 if bzrlib_version != desired_plus:
56 raise Exception, 'Version mismatch'
58 def check_subversion_version():
59 """Check that Subversion is compatible.
63 from svn.delta import svn_delta_invoke_txdelta_window_handler
65 warning('Installed Subversion version does not have updated Python bindings. See the bzr-svn README for details.')
66 raise bzrlib.errors.BzrError("incompatible python subversion bindings")
68 def check_pysqlite_version():
69 """Check that sqlite library is compatible.
76 from pysqlite2 import dbapi2 as sqlite3
78 warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 module')
79 raise bzrlib.errors.BzrError("missing sqlite library")
81 if (sqlite3.sqlite_version_info[0] < 3 or
82 (sqlite3.sqlite_version_info[0] == 3 and
83 sqlite3.sqlite_version_info[1] < 3)):
84 warning('Needs at least sqlite 3.3.x')
85 raise bzrlib.errors.BzrError("incompatible sqlite library")
87 check_bzrlib_version(required_bzr_version)
89 def check_workingtree_format():
91 from bzrlib.workingtree import WorkingTreeFormat4
93 warning('this version of bzr-svn requires WorkingTreeFormat4 to be available to work properly')
94 check_workingtree_format()
95 check_subversion_version()
96 check_pysqlite_version()
104 from bzrlib.transport import register_transport
105 register_transport('svn://', transport.SvnRaTransport)
106 register_transport('svn+', transport.SvnRaTransport)
108 from bzrlib.bzrdir import BzrDirFormat
110 from bzrlib.repository import InterRepository
112 from fetch import InterSvnRepository
114 BzrDirFormat.register_control_format(format.SvnFormat)
117 subr_version = svn.core.svn_subr_version()
119 BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
121 InterRepository.register_optimiser(InterSvnRepository)
123 from bzrlib.branch import Branch
124 from bzrlib.commands import Command, register_command, display_command, Option
125 from bzrlib.errors import BzrCommandError
126 from bzrlib.repository import Repository
127 import bzrlib.urlutils as urlutils
130 def get_scheme(schemename):
131 """Parse scheme identifier and return a branching scheme."""
132 from scheme import BranchingScheme
134 ret = BranchingScheme.find_scheme(schemename)
136 raise BzrCommandError('No such branching scheme %r' % schemename)
140 class cmd_svn_import(Command):
141 """Convert a Subversion repository to a Bazaar repository.
144 takes_args = ['from_location', 'to_location?']
145 takes_options = [Option('trees', help='Create working trees'),
146 Option('shared', help='Create shared repository'),
147 Option('all', help='Convert all revisions, even those not in current branch history (implies --shared)'),
148 Option('scheme', type=get_scheme,
149 help='Branching scheme (none, trunk, or trunk-INT)')]
152 def run(self, from_location, to_location=None, trees=False,
153 shared=False, scheme=None, all=False):
154 from convert import convert_repository
155 from scheme import TrunkBranchingScheme
158 scheme = TrunkBranchingScheme()
160 if to_location is None:
161 to_location = os.path.basename(from_location.rstrip("/\\"))
165 convert_repository(from_location, to_location, scheme, shared, trees,
169 register_command(cmd_svn_import)
171 class cmd_svn_upgrade(Command):
172 """Upgrade the revisions mapped from Subversion in a Bazaar branch.
174 This will change the revision ids of revisions whose parents
175 were mapped from svn revisions.
177 takes_args = ['svn_repository?']
178 takes_options = [Option('allow-changes', help='Allow content changes')]
181 def run(self, svn_repository=None, allow_changes=False):
182 from upgrade import upgrade_branch
184 branch_to = Branch.open(".")
186 stored_loc = branch_to.get_parent()
187 if svn_repository is None:
188 if stored_loc is None:
189 raise BzrCommandError("No pull location known or"
192 display_url = urlutils.unescape_for_display(stored_loc,
194 self.outf.write("Using saved location: %s\n" % display_url)
195 svn_repository = stored_loc
197 upgrade_branch(branch_to, Repository.open(svn_repository),
200 register_command(cmd_svn_upgrade)
204 from unittest import TestSuite, TestLoader
207 suite.addTest(tests.test_suite())
210 if __name__ == '__main__':
211 print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
213 runner = unittest.TextTestRunner()
214 runner.run(test_suite())
216 sys.path.append(os.path.dirname(os.path.abspath(__file__)))