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), (0, 17)]
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 check_bzrlib_version(COMPATIBLE_BZR_VERSIONS)
63 check_subversion_version()
71 from bzrlib.transport import register_transport
72 register_transport('svn://', transport.SvnRaTransport)
73 register_transport('svn+', transport.SvnRaTransport)
75 from bzrlib.bzrdir import BzrDirFormat
77 from bzrlib.repository import InterRepository
79 from fetch import InterSvnRepository
81 BzrDirFormat.register_control_format(format.SvnFormat)
84 _subr_version = svn.core.svn_subr_version()
86 if _subr_version.major == 1 and _subr_version.minor < 4:
87 warning('Subversion version too old for working tree support.')
89 BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
91 InterRepository.register_optimiser(InterSvnRepository)
93 from bzrlib.branch import Branch
94 from bzrlib.commands import Command, register_command, display_command, Option
95 from bzrlib.errors import BzrCommandError
96 from bzrlib.repository import Repository
97 import bzrlib.urlutils as urlutils
100 def get_scheme(schemename):
101 """Parse scheme identifier and return a branching scheme."""
102 from scheme import BranchingScheme
104 ret = BranchingScheme.find_scheme(schemename)
106 raise BzrCommandError('No such branching scheme %r' % schemename)
110 class cmd_svn_import(Command):
111 """Convert a Subversion repository to a Bazaar repository.
114 takes_args = ['from_location', 'to_location?']
115 takes_options = [Option('trees', help='Create working trees'),
116 Option('shared', help='Create shared repository'),
118 help='Convert all revisions, even those not in '
119 'current branch history (implies --shared)'),
120 Option('scheme', type=get_scheme,
121 help='Branching scheme (none, trunk, or trunk-INT)')]
124 def run(self, from_location, to_location=None, trees=False,
125 shared=False, scheme=None, all=False):
126 from convert import convert_repository
127 from scheme import TrunkBranchingScheme
130 scheme = TrunkBranchingScheme()
132 if to_location is None:
133 to_location = os.path.basename(from_location.rstrip("/\\"))
137 convert_repository(from_location, to_location, scheme, shared, trees,
141 register_command(cmd_svn_import)
143 class cmd_svn_upgrade(Command):
144 """Upgrade the revisions mapped from Subversion in a Bazaar branch.
146 This will change the revision ids of revisions whose parents
147 were mapped from svn revisions.
149 takes_args = ['svn_repository?']
150 takes_options = [Option('allow-changes', help='Allow content changes')]
153 def run(self, svn_repository=None, allow_changes=False):
154 from upgrade import upgrade_branch
156 branch_to = Branch.open(".")
158 stored_loc = branch_to.get_parent()
159 if svn_repository is None:
160 if stored_loc is None:
161 raise BzrCommandError("No pull location known or"
164 display_url = urlutils.unescape_for_display(stored_loc,
166 self.outf.write("Using saved location: %s\n" % display_url)
167 svn_repository = stored_loc
169 upgrade_branch(branch_to, Repository.open(svn_repository),
172 register_command(cmd_svn_upgrade)
176 from unittest import TestSuite
181 suite.addTest(tests.test_suite())
185 if __name__ == '__main__':
186 print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
189 sys.path.append(os.path.dirname(__file__))