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 if _subr_version.major == 1 and _subr_version.minor < 4:
108 warning('Subversion version too old for working tree support.')
110 BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
112 InterRepository.register_optimiser(InterSvnRepository)
114 from bzrlib.branch import Branch
115 from bzrlib.commands import Command, register_command, display_command, Option
116 from bzrlib.errors import BzrCommandError
117 from bzrlib.repository import Repository
118 import bzrlib.urlutils as urlutils
121 def get_scheme(schemename):
122 """Parse scheme identifier and return a branching scheme."""
123 from scheme import BranchingScheme
125 ret = BranchingScheme.find_scheme(schemename)
127 raise BzrCommandError('No such branching scheme %r' % schemename)
131 class cmd_svn_import(Command):
132 """Convert a Subversion repository to a Bazaar repository.
135 takes_args = ['from_location', 'to_location?']
136 takes_options = [Option('trees', help='Create working trees'),
137 Option('shared', help='Create shared repository'),
139 help='Convert all revisions, even those not in '
140 'current branch history (implies --shared)'),
141 Option('scheme', type=get_scheme,
142 help='Branching scheme (none, trunk, or trunk-INT)')]
145 def run(self, from_location, to_location=None, trees=False,
146 shared=False, scheme=None, all=False):
147 from convert import convert_repository
148 from scheme import TrunkBranchingScheme
151 scheme = TrunkBranchingScheme()
153 if to_location is None:
154 to_location = os.path.basename(from_location.rstrip("/\\"))
158 convert_repository(from_location, to_location, scheme, shared, trees,
162 register_command(cmd_svn_import)
164 class cmd_svn_upgrade(Command):
165 """Upgrade the revisions mapped from Subversion in a Bazaar branch.
167 This will change the revision ids of revisions whose parents
168 were mapped from svn revisions.
170 takes_args = ['svn_repository?']
171 takes_options = [Option('allow-changes', help='Allow content changes')]
174 def run(self, svn_repository=None, allow_changes=False):
175 from upgrade import upgrade_branch
177 branch_to = Branch.open(".")
179 stored_loc = branch_to.get_parent()
180 if svn_repository is None:
181 if stored_loc is None:
182 raise BzrCommandError("No pull location known or"
185 display_url = urlutils.unescape_for_display(stored_loc,
187 self.outf.write("Using saved location: %s\n" % display_url)
188 svn_repository = stored_loc
190 upgrade_branch(branch_to, Repository.open(svn_repository),
193 register_command(cmd_svn_upgrade)
197 from unittest import TestSuite
202 suite.addTest(tests.test_suite())
206 if __name__ == '__main__':
207 print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
210 sys.path.append(os.path.dirname(__file__))