579.1.33
by Jelmer Vernooij
Fix formatting and update revspecs spec. |
1 |
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
|
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
2 |
|
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
|
|
1022
by Jelmer Vernooij
Switch license to GPLv3 or later. |
5 |
# the Free Software Foundation; either version 3 of the License, or
|
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
6 |
# (at your option) any later version.
|
7 |
||
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.
|
|
12 |
||
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
|
|
16 |
"""Subversion BzrDir formats."""
|
|
17 |
||
18 |
from bzrlib.bzrdir import BzrDirFormat, BzrDir, format_registry |
|
764
by Jelmer Vernooij
Hide subversion-wc as it's uninitializable. |
19 |
from bzrlib.errors import UninitializableFormat |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
20 |
from bzrlib.lazy_import import lazy_import |
21 |
from bzrlib.lockable_files import TransportLock |
|
22 |
||
768
by Jelmer Vernooij
Implement find_ghosts parameter, speeds up fetching significantly. |
23 |
import os |
24 |
||
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
25 |
lazy_import(globals(), """ |
26 |
import errors
|
|
27 |
import remote
|
|
28 |
||
29 |
from bzrlib import errors as bzr_errors
|
|
30 |
""") |
|
31 |
||
32 |
def get_rich_root_format(): |
|
33 |
format = BzrDirFormat.get_default_format() |
|
34 |
if format.repository_format.rich_root_data: |
|
35 |
return format |
|
36 |
# Default format does not support rich root data,
|
|
795
by Jelmer Vernooij
Switch to new rich-roots format. |
37 |
# fall back to rich-root
|
866
by Jelmer Vernooij
Change default to rich-root-pack. |
38 |
format = format_registry.make_bzrdir('rich-root-pack') |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
39 |
assert format.repository_format.rich_root_data |
40 |
return format |
|
41 |
||
42 |
||
43 |
class SvnRemoteFormat(BzrDirFormat): |
|
44 |
"""Format for the Subversion smart server."""
|
|
45 |
_lock_class = TransportLock |
|
46 |
||
47 |
def __init__(self): |
|
48 |
super(SvnRemoteFormat, self).__init__() |
|
49 |
from repository import SvnRepositoryFormat |
|
50 |
self.repository_format = SvnRepositoryFormat() |
|
51 |
||
52 |
@classmethod
|
|
53 |
def probe_transport(klass, transport): |
|
54 |
from transport import get_svn_ra_transport |
|
706
by Jelmer Vernooij
Update news, remove some more imports. |
55 |
import svn.core |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
56 |
format = klass() |
57 |
||
58 |
try: |
|
59 |
transport = get_svn_ra_transport(transport) |
|
60 |
except svn.core.SubversionException, (_, num): |
|
61 |
if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, \ |
|
62 |
svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, \ |
|
63 |
svn.core.SVN_ERR_BAD_URL): |
|
64 |
raise bzr_errors.NotBranchError(path=transport.base) |
|
65 |
||
66 |
return format |
|
67 |
||
68 |
def _open(self, transport): |
|
706
by Jelmer Vernooij
Update news, remove some more imports. |
69 |
import svn.core |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
70 |
try: |
71 |
return remote.SvnRemoteAccess(transport, self) |
|
72 |
except svn.core.SubversionException, (_, num): |
|
73 |
if num == svn.core.SVN_ERR_RA_DAV_REQUEST_FAILED: |
|
74 |
raise bzr_errors.NotBranchError(transport.base) |
|
75 |
raise
|
|
76 |
||
77 |
def get_format_string(self): |
|
78 |
return 'Subversion Smart Server' |
|
79 |
||
80 |
def get_format_description(self): |
|
81 |
return 'Subversion Smart Server' |
|
82 |
||
83 |
def initialize_on_transport(self, transport): |
|
84 |
"""See BzrDir.initialize_on_transport()."""
|
|
85 |
from transport import get_svn_ra_transport |
|
86 |
from bzrlib.transport.local import LocalTransport |
|
709
by Jelmer Vernooij
fix import |
87 |
import svn.repos |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
88 |
|
89 |
if not isinstance(transport, LocalTransport): |
|
90 |
raise NotImplementedError(self.initialize, |
|
91 |
"Can't create Subversion Repositories/branches on "
|
|
92 |
"non-local transports") |
|
93 |
||
94 |
local_path = transport._local_base.rstrip("/") |
|
95 |
svn.repos.create(local_path, '', '', None, None) |
|
768
by Jelmer Vernooij
Implement find_ghosts parameter, speeds up fetching significantly. |
96 |
# All revision property changes
|
97 |
revprop_hook = os.path.join(local_path, "hooks", "pre-revprop-change") |
|
98 |
open(revprop_hook, 'w').write("#!/bin/sh") |
|
99 |
os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111) |
|
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
100 |
return self.open(get_svn_ra_transport(transport), _found=True) |
101 |
||
102 |
def is_supported(self): |
|
103 |
"""See BzrDir.is_supported()."""
|
|
104 |
return True |
|
105 |
||
106 |
||
107 |
class SvnWorkingTreeDirFormat(BzrDirFormat): |
|
108 |
"""Working Tree implementation that uses Subversion working copies."""
|
|
109 |
_lock_class = TransportLock |
|
110 |
||
111 |
def __init__(self): |
|
112 |
super(SvnWorkingTreeDirFormat, self).__init__() |
|
113 |
from repository import SvnRepositoryFormat |
|
114 |
self.repository_format = SvnRepositoryFormat() |
|
115 |
||
116 |
@classmethod
|
|
117 |
def probe_transport(klass, transport): |
|
706
by Jelmer Vernooij
Update news, remove some more imports. |
118 |
import svn |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
119 |
from bzrlib.transport.local import LocalTransport |
120 |
format = klass() |
|
121 |
||
122 |
if isinstance(transport, LocalTransport) and \ |
|
123 |
transport.has(svn.wc.get_adm_dir()): |
|
124 |
return format |
|
125 |
||
126 |
raise bzr_errors.NotBranchError(path=transport.base) |
|
127 |
||
128 |
def _open(self, transport): |
|
706
by Jelmer Vernooij
Update news, remove some more imports. |
129 |
import svn.core |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
130 |
from workingtree import SvnCheckout |
131 |
subr_version = svn.core.svn_subr_version() |
|
132 |
if subr_version.major == 1 and subr_version.minor < 4: |
|
133 |
raise errors.NoCheckoutSupport() |
|
134 |
try: |
|
135 |
return SvnCheckout(transport, self) |
|
136 |
except svn.core.SubversionException, (_, num): |
|
137 |
if num in (svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED,): |
|
138 |
raise errors.NoSvnRepositoryPresent(transport.base) |
|
139 |
raise
|
|
140 |
||
141 |
def get_format_string(self): |
|
142 |
return 'Subversion Local Checkout' |
|
143 |
||
144 |
def get_format_description(self): |
|
145 |
return 'Subversion Local Checkout' |
|
146 |
||
147 |
def initialize_on_transport(self, transport): |
|
148 |
raise UninitializableFormat(self) |
|
149 |
||
150 |
def get_converter(self, format=None): |
|
151 |
"""See BzrDirFormat.get_converter()."""
|
|
152 |
if format is None: |
|
153 |
format = get_rich_root_format() |
|
154 |
raise NotImplementedError(self.get_converter) |