bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5557.1.7
by John Arbash Meinel
Merge in the bzr.dev 5582 |
1 |
# Copyright (C) 2010, 2011 Canonical Ltd
|
|
5363.2.1
by Jelmer Vernooij
Add controldir file. |
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
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
17 |
"""ControlDir is the basic control directory class.
|
|
5363.2.1
by Jelmer Vernooij
Add controldir file. |
18 |
|
19 |
The ControlDir class is the base for the control directory used
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
20 |
by all bzr and foreign formats. For the ".bzr" implementation,
|
|
5363.2.1
by Jelmer Vernooij
Add controldir file. |
21 |
see bzrlib.bzrdir.BzrDir.
|
|
5363.2.21
by Jelmer Vernooij
Update comments. |
22 |
|
|
5363.2.1
by Jelmer Vernooij
Add controldir file. |
23 |
"""
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
24 |
|
25 |
from bzrlib.lazy_import import lazy_import |
|
26 |
lazy_import(globals(), """ |
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
27 |
import textwrap
|
28 |
||
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
29 |
from bzrlib import (
|
30 |
errors,
|
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
31 |
hooks,
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
32 |
revision as _mod_revision,
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
33 |
transport as _mod_transport,
|
|
6207.3.7
by Jelmer Vernooij
Fix import of trace.note and gettext. |
34 |
trace,
|
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
35 |
ui,
|
|
5268.7.26
by Jelmer Vernooij
Unescape branch name. |
36 |
urlutils,
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
37 |
)
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
38 |
from bzrlib.transport import local
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
39 |
from bzrlib.push import (
|
40 |
PushResult,
|
|
41 |
)
|
|
42 |
||
|
6207.3.7
by Jelmer Vernooij
Fix import of trace.note and gettext. |
43 |
from bzrlib.i18n import gettext
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
44 |
""") |
45 |
||
|
5536.1.8
by Andrew Bennetts
Garden the imports in controldir.py. |
46 |
from bzrlib import registry |
47 |
||
|
5363.2.10
by Jelmer Vernooij
base ControlDir on ControlComponent. |
48 |
|
49 |
class ControlComponent(object): |
|
50 |
"""Abstract base class for control directory components. |
|
51 |
||
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
52 |
This provides interfaces that are common across controldirs,
|
|
5363.2.10
by Jelmer Vernooij
base ControlDir on ControlComponent. |
53 |
repositories, branches, and workingtree control directories.
|
54 |
||
55 |
They all expose two urls and transports: the *user* URL is the
|
|
56 |
one that stops above the control directory (eg .bzr) and that
|
|
57 |
should normally be used in messages, and the *control* URL is
|
|
58 |
under that in eg .bzr/checkout and is used to read the control
|
|
59 |
files.
|
|
60 |
||
61 |
This can be used as a mixin and is intended to fit with
|
|
62 |
foreign formats.
|
|
63 |
"""
|
|
64 |
||
65 |
@property
|
|
66 |
def control_transport(self): |
|
67 |
raise NotImplementedError |
|
68 |
||
69 |
@property
|
|
70 |
def control_url(self): |
|
71 |
return self.control_transport.base |
|
72 |
||
73 |
@property
|
|
74 |
def user_transport(self): |
|
75 |
raise NotImplementedError |
|
76 |
||
77 |
@property
|
|
78 |
def user_url(self): |
|
79 |
return self.user_transport.base |
|
80 |
||
81 |
||
82 |
class ControlDir(ControlComponent): |
|
|
5363.2.21
by Jelmer Vernooij
Update comments. |
83 |
"""A control directory. |
84 |
||
85 |
While this represents a generic control directory, there are a few
|
|
86 |
features that are present in this interface that are currently only
|
|
87 |
supported by one of its implementations, BzrDir.
|
|
88 |
||
89 |
These features (bound branches, stacked branches) are currently only
|
|
90 |
supported by Bazaar, but could be supported by other version control
|
|
91 |
systems as well. Implementations are required to raise the appropriate
|
|
92 |
exceptions when an operation is requested that is not supported.
|
|
93 |
||
94 |
This also makes life easier for API users who can rely on the
|
|
95 |
implementation always allowing a particular feature to be requested but
|
|
96 |
raising an exception when it is not supported, rather than requiring the
|
|
97 |
API users to check for magic attributes to see what features are supported.
|
|
98 |
"""
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
99 |
|
100 |
def can_convert_format(self): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
101 |
"""Return true if this controldir is one whose format we can convert |
102 |
from."""
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
103 |
return True |
104 |
||
105 |
def list_branches(self): |
|
106 |
"""Return a sequence of all branches local to this control directory. |
|
107 |
||
108 |
"""
|
|
109 |
try: |
|
110 |
return [self.open_branch()] |
|
111 |
except (errors.NotBranchError, errors.NoRepositoryPresent): |
|
112 |
return [] |
|
113 |
||
114 |
def is_control_filename(self, filename): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
115 |
"""True if filename is the name of a path which is reserved for |
116 |
controldirs.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
117 |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
118 |
:param filename: A filename within the root transport of this
|
119 |
controldir.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
120 |
|
121 |
This is true IF and ONLY IF the filename is part of the namespace reserved
|
|
122 |
for bzr control dirs. Currently this is the '.bzr' directory in the root
|
|
123 |
of the root_transport. it is expected that plugins will need to extend
|
|
124 |
this in the future - for instance to make bzr talk with svn working
|
|
125 |
trees.
|
|
126 |
"""
|
|
127 |
raise NotImplementedError(self.is_control_filename) |
|
128 |
||
129 |
def needs_format_conversion(self, format=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
130 |
"""Return true if this controldir needs convert_format run on it. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
131 |
|
132 |
For instance, if the repository format is out of date but the
|
|
133 |
branch and working tree are not, this should return True.
|
|
134 |
||
135 |
:param format: Optional parameter indicating a specific desired
|
|
136 |
format we plan to arrive at.
|
|
137 |
"""
|
|
138 |
raise NotImplementedError(self.needs_format_conversion) |
|
139 |
||
|
5688.1.1
by Jelmer Vernooij
Add a stub for ControlDir.create_repository. |
140 |
def create_repository(self, shared=False): |
141 |
"""Create a new repository in this control directory. |
|
142 |
||
143 |
:param shared: If a shared repository should be created
|
|
144 |
:return: The newly created repository
|
|
145 |
"""
|
|
146 |
raise NotImplementedError(self.create_repository) |
|
147 |
||
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
148 |
def destroy_repository(self): |
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
149 |
"""Destroy the repository in this ControlDir.""" |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
150 |
raise NotImplementedError(self.destroy_repository) |
151 |
||
|
6123.9.12
by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize. |
152 |
def create_branch(self, name=None, repository=None, |
153 |
append_revisions_only=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
154 |
"""Create a branch in this ControlDir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
155 |
|
156 |
:param name: Name of the colocated branch to create, None for
|
|
157 |
the default branch.
|
|
|
6123.9.12
by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize. |
158 |
:param append_revisions_only: Whether this branch should only allow
|
159 |
appending new revisions to its history.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
160 |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
161 |
The controldirs format will control what branch format is created.
|
162 |
For more control see BranchFormatXX.create(a_controldir).
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
163 |
"""
|
164 |
raise NotImplementedError(self.create_branch) |
|
165 |
||
166 |
def destroy_branch(self, name=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
167 |
"""Destroy a branch in this ControlDir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
168 |
|
169 |
:param name: Name of the branch to destroy, None for the default
|
|
170 |
branch.
|
|
171 |
"""
|
|
172 |
raise NotImplementedError(self.destroy_branch) |
|
173 |
||
174 |
def create_workingtree(self, revision_id=None, from_branch=None, |
|
175 |
accelerator_tree=None, hardlink=False): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
176 |
"""Create a working tree at this ControlDir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
177 |
|
178 |
:param revision_id: create it as of this revision id.
|
|
|
5363.2.17
by Jelmer Vernooij
merge bzr.dev. |
179 |
:param from_branch: override controldir branch
|
180 |
(for lightweight checkouts)
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
181 |
:param accelerator_tree: A tree which can be used for retrieving file
|
182 |
contents more quickly than the revision tree, i.e. a workingtree.
|
|
183 |
The revision tree will be used for cases where accelerator_tree's
|
|
184 |
content is different.
|
|
185 |
"""
|
|
186 |
raise NotImplementedError(self.create_workingtree) |
|
187 |
||
188 |
def destroy_workingtree(self): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
189 |
"""Destroy the working tree at this ControlDir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
190 |
|
191 |
Formats that do not support this may raise UnsupportedOperation.
|
|
192 |
"""
|
|
193 |
raise NotImplementedError(self.destroy_workingtree) |
|
194 |
||
195 |
def destroy_workingtree_metadata(self): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
196 |
"""Destroy the control files for the working tree at this ControlDir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
197 |
|
198 |
The contents of working tree files are not affected.
|
|
199 |
Formats that do not support this may raise UnsupportedOperation.
|
|
200 |
"""
|
|
201 |
raise NotImplementedError(self.destroy_workingtree_metadata) |
|
202 |
||
|
5268.7.27
by Jelmer Vernooij
Add stub for ControlDir.find_branch_format. |
203 |
def find_branch_format(self, name=None): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
204 |
"""Find the branch 'format' for this controldir. |
|
5268.7.27
by Jelmer Vernooij
Add stub for ControlDir.find_branch_format. |
205 |
|
206 |
This might be a synthetic object for e.g. RemoteBranch and SVN.
|
|
207 |
"""
|
|
208 |
raise NotImplementedError(self.find_branch_format) |
|
209 |
||
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
210 |
def get_branch_reference(self, name=None): |
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
211 |
"""Return the referenced URL for the branch in this controldir. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
212 |
|
213 |
:param name: Optional colocated branch name
|
|
214 |
:raises NotBranchError: If there is no Branch.
|
|
215 |
:raises NoColocatedBranchSupport: If a branch name was specified
|
|
216 |
but colocated branches are not supported.
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
217 |
:return: The URL the branch in this controldir references if it is a
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
218 |
reference branch, or None for regular branches.
|
219 |
"""
|
|
220 |
if name is not None: |
|
221 |
raise errors.NoColocatedBranchSupport(self) |
|
222 |
return None |
|
223 |
||
224 |
def open_branch(self, name=None, unsupported=False, |
|
|
6305.3.2
by Jelmer Vernooij
Only make a single connection. |
225 |
ignore_fallbacks=False, possible_transports=None): |
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
226 |
"""Open the branch object at this ControlDir if one is present. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
227 |
|
|
6305.3.2
by Jelmer Vernooij
Only make a single connection. |
228 |
:param unsupported: if True, then no longer supported branch formats can
|
229 |
still be opened.
|
|
230 |
:param ignore_fallbacks: Whether to open fallback repositories
|
|
231 |
:param possible_transports: Transports to use for opening e.g.
|
|
232 |
fallback repositories.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
233 |
"""
|
234 |
raise NotImplementedError(self.open_branch) |
|
235 |
||
236 |
def open_repository(self, _unsupported=False): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
237 |
"""Open the repository object at this ControlDir if one is present. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
238 |
|
239 |
This will not follow the Branch object pointer - it's strictly a direct
|
|
240 |
open facility. Most client code should use open_branch().repository to
|
|
241 |
get at a repository.
|
|
242 |
||
243 |
:param _unsupported: a private parameter, not part of the api.
|
|
244 |
"""
|
|
245 |
raise NotImplementedError(self.open_repository) |
|
246 |
||
247 |
def find_repository(self): |
|
248 |
"""Find the repository that should be used. |
|
249 |
||
250 |
This does not require a branch as we use it to find the repo for
|
|
251 |
new branches as well as to hook existing branches up to their
|
|
252 |
repository.
|
|
253 |
"""
|
|
254 |
raise NotImplementedError(self.find_repository) |
|
255 |
||
256 |
def open_workingtree(self, _unsupported=False, |
|
257 |
recommend_upgrade=True, from_branch=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
258 |
"""Open the workingtree object at this ControlDir if one is present. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
259 |
|
260 |
:param recommend_upgrade: Optional keyword parameter, when True (the
|
|
261 |
default), emit through the ui module a recommendation that the user
|
|
262 |
upgrade the working tree when the workingtree being opened is old
|
|
263 |
(but still fully supported).
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
264 |
:param from_branch: override controldir branch (for lightweight
|
265 |
checkouts)
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
266 |
"""
|
267 |
raise NotImplementedError(self.open_workingtree) |
|
268 |
||
269 |
def has_branch(self, name=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
270 |
"""Tell if this controldir contains a branch. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
271 |
|
272 |
Note: if you're going to open the branch, you should just go ahead
|
|
273 |
and try, and not ask permission first. (This method just opens the
|
|
274 |
branch and discards it, and that's somewhat expensive.)
|
|
275 |
"""
|
|
276 |
try: |
|
|
6305.3.2
by Jelmer Vernooij
Only make a single connection. |
277 |
self.open_branch(name, ignore_fallbacks=True) |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
278 |
return True |
279 |
except errors.NotBranchError: |
|
280 |
return False |
|
281 |
||
|
5268.7.22
by Jelmer Vernooij
Add ControlDir._get_selected_branch. |
282 |
def _get_selected_branch(self): |
283 |
"""Return the name of the branch selected by the user. |
|
284 |
||
285 |
:return: Name of the branch selected by the user, or None.
|
|
286 |
"""
|
|
|
5268.7.26
by Jelmer Vernooij
Unescape branch name. |
287 |
branch = self.root_transport.get_segment_parameters().get("branch") |
288 |
if branch is not None: |
|
289 |
branch = urlutils.unescape(branch) |
|
290 |
return branch |
|
|
5268.7.22
by Jelmer Vernooij
Add ControlDir._get_selected_branch. |
291 |
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
292 |
def has_workingtree(self): |
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
293 |
"""Tell if this controldir contains a working tree. |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
294 |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
295 |
This will still raise an exception if the controldir has a workingtree
|
296 |
that is remote & inaccessible.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
297 |
|
298 |
Note: if you're going to open the working tree, you should just go ahead
|
|
299 |
and try, and not ask permission first. (This method just opens the
|
|
300 |
workingtree and discards it, and that's somewhat expensive.)
|
|
301 |
"""
|
|
302 |
try: |
|
303 |
self.open_workingtree(recommend_upgrade=False) |
|
304 |
return True |
|
305 |
except errors.NoWorkingTree: |
|
306 |
return False |
|
307 |
||
308 |
def cloning_metadir(self, require_stacking=False): |
|
309 |
"""Produce a metadir suitable for cloning or sprouting with. |
|
310 |
||
311 |
These operations may produce workingtrees (yes, even though they're
|
|
312 |
"cloning" something that doesn't have a tree), so a viable workingtree
|
|
313 |
format must be selected.
|
|
314 |
||
315 |
:require_stacking: If True, non-stackable formats will be upgraded
|
|
316 |
to similar stackable formats.
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
317 |
:returns: a ControlDirFormat with all component formats either set
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
318 |
appropriately or set to None if that component should not be
|
319 |
created.
|
|
320 |
"""
|
|
321 |
raise NotImplementedError(self.cloning_metadir) |
|
322 |
||
323 |
def checkout_metadir(self): |
|
324 |
"""Produce a metadir suitable for checkouts of this controldir.""" |
|
325 |
return self.cloning_metadir() |
|
326 |
||
327 |
def sprout(self, url, revision_id=None, force_new_repo=False, |
|
328 |
recurse='down', possible_transports=None, |
|
329 |
accelerator_tree=None, hardlink=False, stacked=False, |
|
330 |
source_branch=None, create_tree_if_local=True): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
331 |
"""Create a copy of this controldir prepared for use as a new line of |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
332 |
development.
|
333 |
||
334 |
If url's last component does not exist, it will be created.
|
|
335 |
||
336 |
Attributes related to the identity of the source branch like
|
|
337 |
branch nickname will be cleaned, a working tree is created
|
|
338 |
whether one existed before or not; and a local branch is always
|
|
339 |
created.
|
|
340 |
||
|
5891.1.3
by Andrew Bennetts
Move docstring formatting fixes. |
341 |
:param revision_id: if revision_id is not None, then the clone
|
342 |
operation may tune itself to download less data.
|
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
343 |
:param accelerator_tree: A tree which can be used for retrieving file
|
344 |
contents more quickly than the revision tree, i.e. a workingtree.
|
|
345 |
The revision tree will be used for cases where accelerator_tree's
|
|
346 |
content is different.
|
|
347 |
:param hardlink: If true, hard-link files from accelerator_tree,
|
|
348 |
where possible.
|
|
349 |
:param stacked: If true, create a stacked branch referring to the
|
|
350 |
location of this control directory.
|
|
351 |
:param create_tree_if_local: If true, a working-tree will be created
|
|
352 |
when working locally.
|
|
353 |
"""
|
|
|
5735.1.1
by Jelmer Vernooij
Move ControlDir.sprout to BzrDir. |
354 |
raise NotImplementedError(self.sprout) |
|
5535.3.12
by Andrew Bennetts
Shift more complexity out of sprout. |
355 |
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
356 |
def push_branch(self, source, revision_id=None, overwrite=False, |
357 |
remember=False, create_prefix=False): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
358 |
"""Push the source branch into this ControlDir.""" |
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
359 |
br_to = None |
360 |
# If we can open a branch, use its direct repository, otherwise see
|
|
361 |
# if there is a repository without a branch.
|
|
362 |
try: |
|
363 |
br_to = self.open_branch() |
|
364 |
except errors.NotBranchError: |
|
365 |
# Didn't find a branch, can we find a repository?
|
|
366 |
repository_to = self.find_repository() |
|
367 |
else: |
|
368 |
# Found a branch, so we must have found a repository
|
|
369 |
repository_to = br_to.repository |
|
370 |
||
371 |
push_result = PushResult() |
|
372 |
push_result.source_branch = source |
|
373 |
if br_to is None: |
|
374 |
# We have a repository but no branch, copy the revisions, and then
|
|
375 |
# create a branch.
|
|
|
5609.26.1
by John Arbash Meinel
Fix bug #465517, 'bzr push' to a target with a repo but no branch |
376 |
if revision_id is None: |
377 |
# No revision supplied by the user, default to the branch
|
|
378 |
# revision
|
|
379 |
revision_id = source.last_revision() |
|
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
380 |
repository_to.fetch(source.repository, revision_id=revision_id) |
381 |
br_to = source.clone(self, revision_id=revision_id) |
|
382 |
if source.get_push_location() is None or remember: |
|
383 |
source.set_push_location(br_to.base) |
|
384 |
push_result.stacked_on = None |
|
385 |
push_result.branch_push_result = None |
|
386 |
push_result.old_revno = None |
|
387 |
push_result.old_revid = _mod_revision.NULL_REVISION |
|
388 |
push_result.target_branch = br_to |
|
389 |
push_result.master_branch = None |
|
390 |
push_result.workingtree_updated = False |
|
391 |
else: |
|
392 |
# We have successfully opened the branch, remember if necessary:
|
|
393 |
if source.get_push_location() is None or remember: |
|
394 |
source.set_push_location(br_to.base) |
|
395 |
try: |
|
396 |
tree_to = self.open_workingtree() |
|
397 |
except errors.NotLocalUrl: |
|
398 |
push_result.branch_push_result = source.push(br_to, |
|
399 |
overwrite, stop_revision=revision_id) |
|
400 |
push_result.workingtree_updated = False |
|
401 |
except errors.NoWorkingTree: |
|
402 |
push_result.branch_push_result = source.push(br_to, |
|
403 |
overwrite, stop_revision=revision_id) |
|
404 |
push_result.workingtree_updated = None # Not applicable |
|
405 |
else: |
|
406 |
tree_to.lock_write() |
|
407 |
try: |
|
408 |
push_result.branch_push_result = source.push( |
|
409 |
tree_to.branch, overwrite, stop_revision=revision_id) |
|
410 |
tree_to.update() |
|
411 |
finally: |
|
412 |
tree_to.unlock() |
|
413 |
push_result.workingtree_updated = True |
|
414 |
push_result.old_revno = push_result.branch_push_result.old_revno |
|
415 |
push_result.old_revid = push_result.branch_push_result.old_revid |
|
416 |
push_result.target_branch = \ |
|
417 |
push_result.branch_push_result.target_branch |
|
418 |
return push_result |
|
419 |
||
|
5363.2.19
by Jelmer Vernooij
Put _get_tree_branch onto ControlDir. |
420 |
def _get_tree_branch(self, name=None): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
421 |
"""Return the branch and tree, if any, for this controldir. |
|
5363.2.19
by Jelmer Vernooij
Put _get_tree_branch onto ControlDir. |
422 |
|
423 |
:param name: Name of colocated branch to open.
|
|
424 |
||
425 |
Return None for tree if not present or inaccessible.
|
|
426 |
Raise NotBranchError if no branch is present.
|
|
427 |
:return: (tree, branch)
|
|
428 |
"""
|
|
429 |
try: |
|
430 |
tree = self.open_workingtree() |
|
431 |
except (errors.NoWorkingTree, errors.NotLocalUrl): |
|
432 |
tree = None |
|
433 |
branch = self.open_branch(name=name) |
|
434 |
else: |
|
435 |
if name is not None: |
|
436 |
branch = self.open_branch(name=name) |
|
437 |
else: |
|
438 |
branch = tree.branch |
|
439 |
return tree, branch |
|
440 |
||
|
5363.2.24
by Jelmer Vernooij
Move get_config to ControlDir. |
441 |
def get_config(self): |
442 |
"""Get configuration for this ControlDir.""" |
|
443 |
raise NotImplementedError(self.get_config) |
|
|
5363.2.19
by Jelmer Vernooij
Put _get_tree_branch onto ControlDir. |
444 |
|
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
445 |
def check_conversion_target(self, target_format): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
446 |
"""Check that a controldir as a whole can be converted to a new format.""" |
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
447 |
raise NotImplementedError(self.check_conversion_target) |
448 |
||
449 |
def clone(self, url, revision_id=None, force_new_repo=False, |
|
450 |
preserve_stacking=False): |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
451 |
"""Clone this controldir and its contents to url verbatim. |
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
452 |
|
453 |
:param url: The url create the clone at. If url's last component does
|
|
454 |
not exist, it will be created.
|
|
455 |
:param revision_id: The tip revision-id to use for any branch or
|
|
456 |
working tree. If not None, then the clone operation may tune
|
|
457 |
itself to download less data.
|
|
458 |
:param force_new_repo: Do not use a shared repository for the target
|
|
459 |
even if one is available.
|
|
460 |
:param preserve_stacking: When cloning a stacked branch, stack the
|
|
461 |
new branch on top of the other branch's stacked-on branch.
|
|
462 |
"""
|
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
463 |
return self.clone_on_transport(_mod_transport.get_transport(url), |
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
464 |
revision_id=revision_id, |
465 |
force_new_repo=force_new_repo, |
|
466 |
preserve_stacking=preserve_stacking) |
|
467 |
||
468 |
def clone_on_transport(self, transport, revision_id=None, |
|
469 |
force_new_repo=False, preserve_stacking=False, stacked_on=None, |
|
|
5664.1.1
by Jelmer Vernooij
Document no_tree option to ControlDir.clone_on_transport. |
470 |
create_prefix=False, use_existing_dir=True, no_tree=False): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
471 |
"""Clone this controldir and its contents to transport verbatim. |
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
472 |
|
473 |
:param transport: The transport for the location to produce the clone
|
|
474 |
at. If the target directory does not exist, it will be created.
|
|
475 |
:param revision_id: The tip revision-id to use for any branch or
|
|
476 |
working tree. If not None, then the clone operation may tune
|
|
477 |
itself to download less data.
|
|
478 |
:param force_new_repo: Do not use a shared repository for the target,
|
|
479 |
even if one is available.
|
|
480 |
:param preserve_stacking: When cloning a stacked branch, stack the
|
|
481 |
new branch on top of the other branch's stacked-on branch.
|
|
482 |
:param create_prefix: Create any missing directories leading up to
|
|
483 |
to_transport.
|
|
484 |
:param use_existing_dir: Use an existing directory if one exists.
|
|
|
5664.1.1
by Jelmer Vernooij
Document no_tree option to ControlDir.clone_on_transport. |
485 |
:param no_tree: If set to true prevents creation of a working tree.
|
|
5363.2.28
by Jelmer Vernooij
Move clone() onto ControlDir.clone(), add ControlDir.clone_on_transport() stub. |
486 |
"""
|
487 |
raise NotImplementedError(self.clone_on_transport) |
|
488 |
||
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
489 |
@classmethod
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
490 |
def find_bzrdirs(klass, transport, evaluate=None, list_current=None): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
491 |
"""Find control dirs recursively from current location. |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
492 |
|
493 |
This is intended primarily as a building block for more sophisticated
|
|
494 |
functionality, like finding trees under a directory, or finding
|
|
495 |
branches that use a given repository.
|
|
496 |
||
497 |
:param evaluate: An optional callable that yields recurse, value,
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
498 |
where recurse controls whether this controldir is recursed into
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
499 |
and value is the value to yield. By default, all bzrdirs
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
500 |
are recursed into, and the return value is the controldir.
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
501 |
:param list_current: if supplied, use this function to list the current
|
502 |
directory, instead of Transport.list_dir
|
|
503 |
:return: a generator of found bzrdirs, or whatever evaluate returns.
|
|
504 |
"""
|
|
505 |
if list_current is None: |
|
506 |
def list_current(transport): |
|
507 |
return transport.list_dir('') |
|
508 |
if evaluate is None: |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
509 |
def evaluate(controldir): |
510 |
return True, controldir |
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
511 |
|
512 |
pending = [transport] |
|
513 |
while len(pending) > 0: |
|
514 |
current_transport = pending.pop() |
|
515 |
recurse = True |
|
516 |
try: |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
517 |
controldir = klass.open_from_transport(current_transport) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
518 |
except (errors.NotBranchError, errors.PermissionDenied): |
519 |
pass
|
|
520 |
else: |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
521 |
recurse, value = evaluate(controldir) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
522 |
yield value |
523 |
try: |
|
524 |
subdirs = list_current(current_transport) |
|
525 |
except (errors.NoSuchFile, errors.PermissionDenied): |
|
526 |
continue
|
|
527 |
if recurse: |
|
528 |
for subdir in sorted(subdirs, reverse=True): |
|
529 |
pending.append(current_transport.clone(subdir)) |
|
530 |
||
531 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
532 |
def find_branches(klass, transport): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
533 |
"""Find all branches under a transport. |
534 |
||
535 |
This will find all branches below the transport, including branches
|
|
536 |
inside other branches. Where possible, it will use
|
|
537 |
Repository.find_branches.
|
|
538 |
||
539 |
To list all the branches that use a particular Repository, see
|
|
540 |
Repository.find_branches
|
|
541 |
"""
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
542 |
def evaluate(controldir): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
543 |
try: |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
544 |
repository = controldir.open_repository() |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
545 |
except errors.NoRepositoryPresent: |
546 |
pass
|
|
547 |
else: |
|
548 |
return False, ([], repository) |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
549 |
return True, (controldir.list_branches(), None) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
550 |
ret = [] |
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
551 |
for branches, repo in klass.find_bzrdirs( |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
552 |
transport, evaluate=evaluate): |
553 |
if repo is not None: |
|
554 |
ret.extend(repo.find_branches()) |
|
555 |
if branches is not None: |
|
556 |
ret.extend(branches) |
|
557 |
return ret |
|
558 |
||
559 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
560 |
def create_branch_and_repo(klass, base, force_new_repo=False, format=None): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
561 |
"""Create a new ControlDir, Branch and Repository at the url 'base'. |
562 |
||
563 |
This will use the current default ControlDirFormat unless one is
|
|
564 |
specified, and use whatever
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
565 |
repository format that that uses via controldir.create_branch and
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
566 |
create_repository. If a shared repository is available that is used
|
567 |
preferentially.
|
|
568 |
||
569 |
The created Branch object is returned.
|
|
570 |
||
571 |
:param base: The URL to create the branch at.
|
|
572 |
:param force_new_repo: If True a new repository is always created.
|
|
573 |
:param format: If supplied, the format of branch to create. If not
|
|
574 |
supplied, the default is used.
|
|
575 |
"""
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
576 |
controldir = klass.create(base, format) |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
577 |
controldir._find_or_create_repository(force_new_repo) |
578 |
return controldir.create_branch() |
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
579 |
|
580 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
581 |
def create_branch_convenience(klass, base, force_new_repo=False, |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
582 |
force_new_tree=None, format=None, |
583 |
possible_transports=None): |
|
584 |
"""Create a new ControlDir, Branch and Repository at the url 'base'. |
|
585 |
||
586 |
This is a convenience function - it will use an existing repository
|
|
587 |
if possible, can be told explicitly whether to create a working tree or
|
|
588 |
not.
|
|
589 |
||
590 |
This will use the current default ControlDirFormat unless one is
|
|
591 |
specified, and use whatever
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
592 |
repository format that that uses via ControlDir.create_branch and
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
593 |
create_repository. If a shared repository is available that is used
|
594 |
preferentially. Whatever repository is used, its tree creation policy
|
|
595 |
is followed.
|
|
596 |
||
597 |
The created Branch object is returned.
|
|
598 |
If a working tree cannot be made due to base not being a file:// url,
|
|
599 |
no error is raised unless force_new_tree is True, in which case no
|
|
600 |
data is created on disk and NotLocalUrl is raised.
|
|
601 |
||
602 |
:param base: The URL to create the branch at.
|
|
603 |
:param force_new_repo: If True a new repository is always created.
|
|
604 |
:param force_new_tree: If True or False force creation of a tree or
|
|
605 |
prevent such creation respectively.
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
606 |
:param format: Override for the controldir format to create.
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
607 |
:param possible_transports: An optional reusable transports list.
|
608 |
"""
|
|
609 |
if force_new_tree: |
|
610 |
# check for non local urls
|
|
611 |
t = _mod_transport.get_transport(base, possible_transports) |
|
612 |
if not isinstance(t, local.LocalTransport): |
|
613 |
raise errors.NotLocalUrl(base) |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
614 |
controldir = klass.create(base, format, possible_transports) |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
615 |
repo = controldir._find_or_create_repository(force_new_repo) |
616 |
result = controldir.create_branch() |
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
617 |
if force_new_tree or (repo.make_working_trees() and |
618 |
force_new_tree is None): |
|
619 |
try: |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
620 |
controldir.create_workingtree() |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
621 |
except errors.NotLocalUrl: |
622 |
pass
|
|
623 |
return result |
|
624 |
||
625 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
626 |
def create_standalone_workingtree(klass, base, format=None): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
627 |
"""Create a new ControlDir, WorkingTree, Branch and Repository at 'base'. |
628 |
||
629 |
'base' must be a local path or a file:// url.
|
|
630 |
||
631 |
This will use the current default ControlDirFormat unless one is
|
|
632 |
specified, and use whatever
|
|
633 |
repository format that that uses for bzrdirformat.create_workingtree,
|
|
634 |
create_branch and create_repository.
|
|
635 |
||
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
636 |
:param format: Override for the controldir format to create.
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
637 |
:return: The WorkingTree object.
|
638 |
"""
|
|
639 |
t = _mod_transport.get_transport(base) |
|
640 |
if not isinstance(t, local.LocalTransport): |
|
641 |
raise errors.NotLocalUrl(base) |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
642 |
controldir = klass.create_branch_and_repo(base, |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
643 |
force_new_repo=True, |
644 |
format=format).bzrdir |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
645 |
return controldir.create_workingtree() |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
646 |
|
647 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
648 |
def open_unsupported(klass, base): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
649 |
"""Open a branch which is not supported.""" |
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
650 |
return klass.open(base, _unsupported=True) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
651 |
|
652 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
653 |
def open(klass, base, _unsupported=False, possible_transports=None): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
654 |
"""Open an existing controldir, rooted at 'base' (url). |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
655 |
|
656 |
:param _unsupported: a private parameter to the ControlDir class.
|
|
657 |
"""
|
|
658 |
t = _mod_transport.get_transport(base, possible_transports) |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
659 |
return klass.open_from_transport(t, _unsupported=_unsupported) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
660 |
|
661 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
662 |
def open_from_transport(klass, transport, _unsupported=False, |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
663 |
_server_formats=True): |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
664 |
"""Open a controldir within a particular directory. |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
665 |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
666 |
:param transport: Transport containing the controldir.
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
667 |
:param _unsupported: private.
|
668 |
"""
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
669 |
for hook in klass.hooks['pre_open']: |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
670 |
hook(transport) |
671 |
# Keep initial base since 'transport' may be modified while following
|
|
672 |
# the redirections.
|
|
673 |
base = transport.base |
|
674 |
def find_format(transport): |
|
675 |
return transport, ControlDirFormat.find_format( |
|
676 |
transport, _server_formats=_server_formats) |
|
677 |
||
678 |
def redirected(transport, e, redirection_notice): |
|
679 |
redirected_transport = transport._redirected_to(e.source, e.target) |
|
680 |
if redirected_transport is None: |
|
681 |
raise errors.NotBranchError(base) |
|
|
6207.3.7
by Jelmer Vernooij
Fix import of trace.note and gettext. |
682 |
trace.note(gettext('{0} is{1} redirected to {2}').format( |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
683 |
transport.base, e.permanently, redirected_transport.base)) |
684 |
return redirected_transport |
|
685 |
||
686 |
try: |
|
687 |
transport, format = _mod_transport.do_catching_redirections( |
|
688 |
find_format, transport, redirected) |
|
689 |
except errors.TooManyRedirections: |
|
690 |
raise errors.NotBranchError(base) |
|
691 |
||
692 |
format.check_support_status(_unsupported) |
|
693 |
return format.open(transport, _found=True) |
|
694 |
||
695 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
696 |
def open_containing(klass, url, possible_transports=None): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
697 |
"""Open an existing branch which contains url. |
698 |
||
699 |
:param url: url to search from.
|
|
700 |
||
701 |
See open_containing_from_transport for more detail.
|
|
702 |
"""
|
|
703 |
transport = _mod_transport.get_transport(url, possible_transports) |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
704 |
return klass.open_containing_from_transport(transport) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
705 |
|
706 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
707 |
def open_containing_from_transport(klass, a_transport): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
708 |
"""Open an existing branch which contains a_transport.base. |
709 |
||
710 |
This probes for a branch at a_transport, and searches upwards from there.
|
|
711 |
||
712 |
Basically we keep looking up until we find the control directory or
|
|
713 |
run into the root. If there isn't one, raises NotBranchError.
|
|
714 |
If there is one and it is either an unrecognised format or an unsupported
|
|
715 |
format, UnknownFormatError or UnsupportedFormatError are raised.
|
|
716 |
If there is one, it is returned, along with the unused portion of url.
|
|
717 |
||
718 |
:return: The ControlDir that contains the path, and a Unicode path
|
|
719 |
for the rest of the URL.
|
|
720 |
"""
|
|
721 |
# this gets the normalised url back. I.e. '.' -> the full path.
|
|
722 |
url = a_transport.base |
|
723 |
while True: |
|
724 |
try: |
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
725 |
result = klass.open_from_transport(a_transport) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
726 |
return result, urlutils.unescape(a_transport.relpath(url)) |
727 |
except errors.NotBranchError, e: |
|
728 |
pass
|
|
729 |
try: |
|
730 |
new_t = a_transport.clone('..') |
|
731 |
except errors.InvalidURLJoin: |
|
732 |
# reached the root, whatever that may be
|
|
733 |
raise errors.NotBranchError(path=url) |
|
734 |
if new_t.base == a_transport.base: |
|
735 |
# reached the root, whatever that may be
|
|
736 |
raise errors.NotBranchError(path=url) |
|
737 |
a_transport = new_t |
|
738 |
||
739 |
@classmethod
|
|
740 |
def open_tree_or_branch(klass, location): |
|
741 |
"""Return the branch and working tree at a location. |
|
742 |
||
743 |
If there is no tree at the location, tree will be None.
|
|
744 |
If there is no branch at the location, an exception will be
|
|
745 |
raised
|
|
746 |
:return: (tree, branch)
|
|
747 |
"""
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
748 |
controldir = klass.open(location) |
749 |
return controldir._get_tree_branch() |
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
750 |
|
751 |
@classmethod
|
|
752 |
def open_containing_tree_or_branch(klass, location): |
|
753 |
"""Return the branch and working tree contained by a location. |
|
754 |
||
755 |
Returns (tree, branch, relpath).
|
|
756 |
If there is no tree at containing the location, tree will be None.
|
|
757 |
If there is no branch containing the location, an exception will be
|
|
758 |
raised
|
|
759 |
relpath is the portion of the path that is contained by the branch.
|
|
760 |
"""
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
761 |
controldir, relpath = klass.open_containing(location) |
762 |
tree, branch = controldir._get_tree_branch() |
|
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
763 |
return tree, branch, relpath |
764 |
||
765 |
@classmethod
|
|
766 |
def open_containing_tree_branch_or_repository(klass, location): |
|
767 |
"""Return the working tree, branch and repo contained by a location. |
|
768 |
||
769 |
Returns (tree, branch, repository, relpath).
|
|
770 |
If there is no tree containing the location, tree will be None.
|
|
771 |
If there is no branch containing the location, branch will be None.
|
|
772 |
If there is no repository containing the location, repository will be
|
|
773 |
None.
|
|
774 |
relpath is the portion of the path that is contained by the innermost
|
|
775 |
ControlDir.
|
|
776 |
||
777 |
If no tree, branch or repository is found, a NotBranchError is raised.
|
|
778 |
"""
|
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
779 |
controldir, relpath = klass.open_containing(location) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
780 |
try: |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
781 |
tree, branch = controldir._get_tree_branch() |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
782 |
except errors.NotBranchError: |
783 |
try: |
|
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
784 |
repo = controldir.find_repository() |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
785 |
return None, None, repo, relpath |
786 |
except (errors.NoRepositoryPresent): |
|
787 |
raise errors.NotBranchError(location) |
|
788 |
return tree, branch, branch.repository, relpath |
|
789 |
||
790 |
@classmethod
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
791 |
def create(klass, base, format=None, possible_transports=None): |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
792 |
"""Create a new ControlDir at the url 'base'. |
793 |
||
794 |
:param format: If supplied, the format of branch to create. If not
|
|
795 |
supplied, the default is used.
|
|
796 |
:param possible_transports: If supplied, a list of transports that
|
|
797 |
can be reused to share a remote connection.
|
|
798 |
"""
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
799 |
if klass is not ControlDir: |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
800 |
raise AssertionError("ControlDir.create always creates the" |
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
801 |
"default format, not one of %r" % klass) |
|
6207.3.2
by jelmer at samba
Move convenience methods to ControlDir. |
802 |
t = _mod_transport.get_transport(base, possible_transports) |
803 |
t.ensure_base() |
|
804 |
if format is None: |
|
805 |
format = ControlDirFormat.get_default_format() |
|
806 |
return format.initialize_on_transport(t) |
|
807 |
||
808 |
||
809 |
class ControlDirHooks(hooks.Hooks): |
|
810 |
"""Hooks for ControlDir operations.""" |
|
811 |
||
812 |
def __init__(self): |
|
813 |
"""Create the default hooks.""" |
|
814 |
hooks.Hooks.__init__(self, "bzrlib.controldir", "ControlDir.hooks") |
|
815 |
self.add_hook('pre_open', |
|
816 |
"Invoked before attempting to open a ControlDir with the transport "
|
|
817 |
"that the open will use.", (1, 14)) |
|
818 |
self.add_hook('post_repo_init', |
|
819 |
"Invoked after a repository has been initialized. "
|
|
820 |
"post_repo_init is called with a "
|
|
821 |
"bzrlib.controldir.RepoInitHookParams.", |
|
822 |
(2, 2)) |
|
823 |
||
824 |
# install the default hooks
|
|
825 |
ControlDir.hooks = ControlDirHooks() |
|
826 |
||
|
5363.2.2
by Jelmer Vernooij
Rename per_bzrdir => per_controldir. |
827 |
|
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
828 |
class ControlComponentFormat(object): |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
829 |
"""A component that can live inside of a .bzr meta directory.""" |
830 |
||
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
831 |
upgrade_recommended = False |
832 |
||
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
833 |
def get_format_string(self): |
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
834 |
"""Return the format of this format, if usable in meta directories.""" |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
835 |
raise NotImplementedError(self.get_format_string) |
836 |
||
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
837 |
def get_format_description(self): |
838 |
"""Return the short description for this format.""" |
|
839 |
raise NotImplementedError(self.get_format_description) |
|
840 |
||
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
841 |
def is_supported(self): |
842 |
"""Is this format supported? |
|
843 |
||
844 |
Supported formats must be initializable and openable.
|
|
845 |
Unsupported formats may not support initialization or committing or
|
|
846 |
some other features depending on the reason for not being supported.
|
|
847 |
"""
|
|
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
848 |
return True |
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
849 |
|
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
850 |
def check_support_status(self, allow_unsupported, recommend_upgrade=True, |
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
851 |
basedir=None): |
852 |
"""Give an error or warning on old formats. |
|
853 |
||
854 |
:param allow_unsupported: If true, allow opening
|
|
855 |
formats that are strongly deprecated, and which may
|
|
856 |
have limited functionality.
|
|
857 |
||
858 |
:param recommend_upgrade: If true (default), warn
|
|
859 |
the user through the ui object that they may wish
|
|
860 |
to upgrade the object.
|
|
861 |
"""
|
|
862 |
if not allow_unsupported and not self.is_supported(): |
|
863 |
# see open_downlevel to open legacy branches.
|
|
|
5717.1.11
by Jelmer Vernooij
Fix format in exception. |
864 |
raise errors.UnsupportedFormatError(format=self) |
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
865 |
if recommend_upgrade and self.upgrade_recommended: |
866 |
ui.ui_factory.recommend_upgrade( |
|
867 |
self.get_format_description(), basedir) |
|
868 |
||
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
869 |
|
870 |
class ControlComponentFormatRegistry(registry.FormatRegistry): |
|
871 |
"""A registry for control components (branch, workingtree, repository).""" |
|
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
872 |
|
873 |
def __init__(self, other_registry=None): |
|
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
874 |
super(ControlComponentFormatRegistry, self).__init__(other_registry) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
875 |
self._extra_formats = [] |
876 |
||
877 |
def register(self, format): |
|
878 |
"""Register a new format.""" |
|
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
879 |
super(ControlComponentFormatRegistry, self).register( |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
880 |
format.get_format_string(), format) |
881 |
||
882 |
def remove(self, format): |
|
883 |
"""Remove a registered format.""" |
|
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
884 |
super(ControlComponentFormatRegistry, self).remove( |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
885 |
format.get_format_string()) |
886 |
||
887 |
def register_extra(self, format): |
|
888 |
"""Register a format that can not be used in a metadir. |
|
889 |
||
890 |
This is mainly useful to allow custom repository formats, such as older
|
|
891 |
Bazaar formats and foreign formats, to be tested.
|
|
892 |
"""
|
|
893 |
self._extra_formats.append(registry._ObjectGetter(format)) |
|
894 |
||
895 |
def remove_extra(self, format): |
|
896 |
"""Remove an extra format. |
|
897 |
"""
|
|
898 |
self._extra_formats.remove(registry._ObjectGetter(format)) |
|
899 |
||
900 |
def register_extra_lazy(self, module_name, member_name): |
|
901 |
"""Register a format lazily. |
|
902 |
"""
|
|
903 |
self._extra_formats.append( |
|
904 |
registry._LazyObjectGetter(module_name, member_name)) |
|
905 |
||
906 |
def _get_extra(self): |
|
907 |
"""Return all "extra" formats, not usable in meta directories.""" |
|
908 |
result = [] |
|
909 |
for getter in self._extra_formats: |
|
910 |
f = getter.get_obj() |
|
911 |
if callable(f): |
|
912 |
f = f() |
|
913 |
result.append(f) |
|
914 |
return result |
|
915 |
||
916 |
def _get_all(self): |
|
917 |
"""Return all formats, even those not usable in metadirs. |
|
918 |
"""
|
|
919 |
result = [] |
|
920 |
for name in self.keys(): |
|
921 |
fmt = self.get(name) |
|
922 |
if callable(fmt): |
|
923 |
fmt = fmt() |
|
924 |
result.append(fmt) |
|
925 |
return result + self._get_extra() |
|
926 |
||
|
5676.1.6
by Jelmer Vernooij
Add _ObjGetter.get_module. |
927 |
def _get_all_modules(self): |
928 |
"""Return a set of the modules providing objects.""" |
|
929 |
modules = set() |
|
930 |
for name in self.keys(): |
|
931 |
modules.add(self._get_module(name)) |
|
932 |
for getter in self._extra_formats: |
|
933 |
modules.add(getter.get_module()) |
|
934 |
return modules |
|
935 |
||
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
936 |
|
|
5692.1.1
by Jelmer Vernooij
Move Converter (which is generic) from bzrlib.bzrdir to bzrlib.controldir. |
937 |
class Converter(object): |
938 |
"""Converts a disk format object from one format to another.""" |
|
939 |
||
940 |
def convert(self, to_convert, pb): |
|
941 |
"""Perform the conversion of to_convert, giving feedback via pb. |
|
942 |
||
943 |
:param to_convert: The disk object to convert.
|
|
944 |
:param pb: a progress bar to use for progress information.
|
|
945 |
"""
|
|
946 |
||
947 |
def step(self, message): |
|
948 |
"""Update the pb by a step.""" |
|
949 |
self.count +=1 |
|
950 |
self.pb.update(message, self.count, self.total) |
|
951 |
||
952 |
||
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
953 |
class ControlDirFormat(object): |
954 |
"""An encapsulation of the initialization and open routines for a format. |
|
955 |
||
956 |
Formats provide three things:
|
|
957 |
* An initialization routine,
|
|
958 |
* a format string,
|
|
959 |
* an open routine.
|
|
960 |
||
961 |
Formats are placed in a dict by their format string for reference
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
962 |
during controldir opening. These should be subclasses of ControlDirFormat
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
963 |
for consistency.
|
964 |
||
965 |
Once a format is deprecated, just deprecate the initialize and open
|
|
966 |
methods on the format class. Do not deprecate the object, as the
|
|
967 |
object will be created every system load.
|
|
968 |
||
969 |
:cvar colocated_branches: Whether this formats supports colocated branches.
|
|
|
5393.4.3
by Jelmer Vernooij
Consistent spelling. |
970 |
:cvar supports_workingtrees: This control directory can co-exist with a
|
|
5393.4.2
by Jelmer Vernooij
Use cvar. |
971 |
working tree.
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
972 |
"""
|
973 |
||
974 |
_default_format = None |
|
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
975 |
"""The default format used for new control directories.""" |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
976 |
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
977 |
_server_probers = [] |
978 |
"""The registered server format probers, e.g. RemoteBzrProber. |
|
979 |
||
980 |
This is a list of Prober-derived classes.
|
|
981 |
"""
|
|
982 |
||
983 |
_probers = [] |
|
984 |
"""The registered format probers, e.g. BzrProber. |
|
985 |
||
986 |
This is a list of Prober-derived classes.
|
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
987 |
"""
|
988 |
||
989 |
colocated_branches = False |
|
990 |
"""Whether co-located branches are supported for this control dir format. |
|
991 |
"""
|
|
992 |
||
|
5393.4.3
by Jelmer Vernooij
Consistent spelling. |
993 |
supports_workingtrees = True |
|
5669.1.1
by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir. |
994 |
"""Whether working trees can exist in control directories of this format. |
995 |
"""
|
|
|
5393.4.1
by Jelmer Vernooij
Add ControlDirFormat.supports_workingtrees. |
996 |
|
|
5673.1.3
by Jelmer Vernooij
Change flexible_components to fixed_components. |
997 |
fixed_components = False |
998 |
"""Whether components can not change format independent of the control dir. |
|
|
5673.1.1
by Jelmer Vernooij
Add flexible_components boolean to ControlDir if the |
999 |
"""
|
1000 |
||
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
1001 |
upgrade_recommended = False |
1002 |
"""Whether an upgrade from this format is recommended.""" |
|
1003 |
||
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1004 |
def get_format_description(self): |
1005 |
"""Return the short description for this format.""" |
|
1006 |
raise NotImplementedError(self.get_format_description) |
|
1007 |
||
1008 |
def get_converter(self, format=None): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1009 |
"""Return the converter to use to convert controldirs needing converts. |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1010 |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1011 |
This returns a bzrlib.controldir.Converter object.
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1012 |
|
1013 |
This should return the best upgrader to step this format towards the
|
|
1014 |
current default format. In the case of plugins we can/should provide
|
|
1015 |
some means for them to extend the range of returnable converters.
|
|
1016 |
||
1017 |
:param format: Optional format to override the default format of the
|
|
1018 |
library.
|
|
1019 |
"""
|
|
1020 |
raise NotImplementedError(self.get_converter) |
|
1021 |
||
1022 |
def is_supported(self): |
|
1023 |
"""Is this format supported? |
|
1024 |
||
|
6162.3.4
by Jelmer Vernooij
Use TestNotApplicable rather than returning directly. |
1025 |
Supported formats must be openable.
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1026 |
Unsupported formats may not support initialization or committing or
|
1027 |
some other features depending on the reason for not being supported.
|
|
1028 |
"""
|
|
1029 |
return True |
|
1030 |
||
|
6162.3.4
by Jelmer Vernooij
Use TestNotApplicable rather than returning directly. |
1031 |
def is_initializable(self): |
1032 |
"""Whether new control directories of this format can be initialized. |
|
1033 |
"""
|
|
1034 |
return self.is_supported() |
|
1035 |
||
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
1036 |
def check_support_status(self, allow_unsupported, recommend_upgrade=True, |
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
1037 |
basedir=None): |
1038 |
"""Give an error or warning on old formats. |
|
1039 |
||
1040 |
:param allow_unsupported: If true, allow opening
|
|
1041 |
formats that are strongly deprecated, and which may
|
|
1042 |
have limited functionality.
|
|
1043 |
||
1044 |
:param recommend_upgrade: If true (default), warn
|
|
1045 |
the user through the ui object that they may wish
|
|
1046 |
to upgrade the object.
|
|
1047 |
"""
|
|
1048 |
if not allow_unsupported and not self.is_supported(): |
|
1049 |
# see open_downlevel to open legacy branches.
|
|
|
5717.1.11
by Jelmer Vernooij
Fix format in exception. |
1050 |
raise errors.UnsupportedFormatError(format=self) |
|
5717.1.1
by Jelmer Vernooij
Support overriding check_supported. |
1051 |
if recommend_upgrade and self.upgrade_recommended: |
1052 |
ui.ui_factory.recommend_upgrade( |
|
1053 |
self.get_format_description(), basedir) |
|
1054 |
||
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1055 |
def same_model(self, target_format): |
1056 |
return (self.repository_format.rich_root_data == |
|
1057 |
target_format.rich_root_data) |
|
1058 |
||
1059 |
@classmethod
|
|
|
5712.3.19
by Jelmer Vernooij
Raise exception from ControlDirFormat.register_format. |
1060 |
def register_format(klass, format): |
1061 |
"""Register a format that does not use '.bzr' for its control dir. |
|
1062 |
||
1063 |
"""
|
|
1064 |
raise errors.BzrError("ControlDirFormat.register_format() has been " |
|
1065 |
"removed in Bazaar 2.4. Please upgrade your plugins.") |
|
1066 |
||
1067 |
@classmethod
|
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1068 |
def register_prober(klass, prober): |
1069 |
"""Register a prober that can look for a control dir. |
|
1070 |
||
1071 |
"""
|
|
1072 |
klass._probers.append(prober) |
|
1073 |
||
1074 |
@classmethod
|
|
1075 |
def unregister_prober(klass, prober): |
|
1076 |
"""Unregister a prober. |
|
1077 |
||
1078 |
"""
|
|
1079 |
klass._probers.remove(prober) |
|
1080 |
||
1081 |
@classmethod
|
|
1082 |
def register_server_prober(klass, prober): |
|
1083 |
"""Register a control format prober for client-server environments. |
|
1084 |
||
1085 |
These probers will be used before ones registered with
|
|
1086 |
register_prober. This gives implementations that decide to the
|
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1087 |
chance to grab it before anything looks at the contents of the format
|
1088 |
file.
|
|
1089 |
"""
|
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1090 |
klass._server_probers.append(prober) |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1091 |
|
1092 |
def __str__(self): |
|
1093 |
# Trim the newline
|
|
1094 |
return self.get_format_description().rstrip() |
|
1095 |
||
1096 |
@classmethod
|
|
1097 |
def known_formats(klass): |
|
1098 |
"""Return all the known formats. |
|
1099 |
"""
|
|
|
5712.3.14
by Jelmer Vernooij
Add Prober.known_formats. |
1100 |
result = set() |
|
5712.3.15
by Jelmer Vernooij
Remove unused register format functions. |
1101 |
for prober_kls in klass._probers + klass._server_probers: |
1102 |
result.update(prober_kls.known_formats()) |
|
|
5712.3.14
by Jelmer Vernooij
Add Prober.known_formats. |
1103 |
return result |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1104 |
|
1105 |
@classmethod
|
|
1106 |
def find_format(klass, transport, _server_formats=True): |
|
1107 |
"""Return the format present at transport.""" |
|
1108 |
if _server_formats: |
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1109 |
_probers = klass._server_probers + klass._probers |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1110 |
else: |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1111 |
_probers = klass._probers |
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1112 |
for prober_kls in _probers: |
1113 |
prober = prober_kls() |
|
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1114 |
try: |
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1115 |
return prober.probe_transport(transport) |
|
5363.2.3
by Jelmer Vernooij
Add ControlDirFormat. |
1116 |
except errors.NotBranchError: |
1117 |
# this format does not find a control dir here.
|
|
1118 |
pass
|
|
1119 |
raise errors.NotBranchError(path=transport.base) |
|
1120 |
||
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1121 |
def initialize(self, url, possible_transports=None): |
1122 |
"""Create a control dir at this url and return an opened copy. |
|
1123 |
||
1124 |
While not deprecated, this method is very specific and its use will
|
|
1125 |
lead to many round trips to setup a working environment. See
|
|
1126 |
initialize_on_transport_ex for a [nearly] all-in-one method.
|
|
1127 |
||
1128 |
Subclasses should typically override initialize_on_transport
|
|
1129 |
instead of this method.
|
|
1130 |
"""
|
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
1131 |
return self.initialize_on_transport( |
1132 |
_mod_transport.get_transport(url, possible_transports)) |
|
1133 |
||
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1134 |
def initialize_on_transport(self, transport): |
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1135 |
"""Initialize a new controldir in the base directory of a Transport.""" |
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1136 |
raise NotImplementedError(self.initialize_on_transport) |
1137 |
||
1138 |
def initialize_on_transport_ex(self, transport, use_existing_dir=False, |
|
1139 |
create_prefix=False, force_new_repo=False, stacked_on=None, |
|
1140 |
stack_on_pwd=None, repo_format_name=None, make_working_trees=None, |
|
1141 |
shared_repo=False, vfs_only=False): |
|
1142 |
"""Create this format on transport. |
|
1143 |
||
1144 |
The directory to initialize will be created.
|
|
1145 |
||
1146 |
:param force_new_repo: Do not use a shared repository for the target,
|
|
1147 |
even if one is available.
|
|
1148 |
:param create_prefix: Create any missing directories leading up to
|
|
1149 |
to_transport.
|
|
1150 |
:param use_existing_dir: Use an existing directory if one exists.
|
|
1151 |
:param stacked_on: A url to stack any created branch on, None to follow
|
|
1152 |
any target stacking policy.
|
|
1153 |
:param stack_on_pwd: If stack_on is relative, the location it is
|
|
1154 |
relative to.
|
|
1155 |
:param repo_format_name: If non-None, a repository will be
|
|
1156 |
made-or-found. Should none be found, or if force_new_repo is True
|
|
1157 |
the repo_format_name is used to select the format of repository to
|
|
1158 |
create.
|
|
1159 |
:param make_working_trees: Control the setting of make_working_trees
|
|
1160 |
for a new shared repository when one is made. None to use whatever
|
|
1161 |
default the format has.
|
|
1162 |
:param shared_repo: Control whether made repositories are shared or
|
|
1163 |
not.
|
|
1164 |
:param vfs_only: If True do not attempt to use a smart server
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1165 |
:return: repo, controldir, require_stacking, repository_policy. repo is
|
1166 |
None if none was created or found, controldir is always valid.
|
|
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1167 |
require_stacking is the result of examining the stacked_on
|
1168 |
parameter and any stacking policy found for the target.
|
|
1169 |
"""
|
|
1170 |
raise NotImplementedError(self.initialize_on_transport_ex) |
|
1171 |
||
1172 |
def network_name(self): |
|
1173 |
"""A simple byte string uniquely identifying this format for RPC calls. |
|
1174 |
||
1175 |
Bzr control formats use this disk format string to identify the format
|
|
1176 |
over the wire. Its possible that other control formats have more
|
|
1177 |
complex detection requirements, so we permit them to use any unique and
|
|
1178 |
immutable string they desire.
|
|
1179 |
"""
|
|
1180 |
raise NotImplementedError(self.network_name) |
|
1181 |
||
1182 |
def open(self, transport, _found=False): |
|
1183 |
"""Return an instance of this format for the dir transport points at. |
|
1184 |
"""
|
|
1185 |
raise NotImplementedError(self.open) |
|
1186 |
||
1187 |
@classmethod
|
|
1188 |
def _set_default_format(klass, format): |
|
1189 |
"""Set default format (for testing behavior of defaults only)""" |
|
1190 |
klass._default_format = format |
|
1191 |
||
1192 |
@classmethod
|
|
1193 |
def get_default_format(klass): |
|
1194 |
"""Return the current default format.""" |
|
1195 |
return klass._default_format |
|
1196 |
||
|
6205.3.1
by Jelmer Vernooij
Add ControlDirFormat.supports_transport. |
1197 |
def supports_transport(self, transport): |
1198 |
"""Check if this format can be opened over a particular transport. |
|
1199 |
"""
|
|
1200 |
raise NotImplementedError(self.supports_transport) |
|
1201 |
||
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1202 |
|
1203 |
class Prober(object): |
|
|
5712.3.22
by Jelmer Vernooij
Add some notes about probers. |
1204 |
"""Abstract class that can be used to detect a particular kind of |
|
5363.2.8
by Jelmer Vernooij
Docstrings. |
1205 |
control directory.
|
1206 |
||
|
5712.3.22
by Jelmer Vernooij
Add some notes about probers. |
1207 |
At the moment this just contains a single method to probe a particular
|
1208 |
transport, but it may be extended in the future to e.g. avoid
|
|
|
5363.2.8
by Jelmer Vernooij
Docstrings. |
1209 |
multiple levels of probing for Subversion repositories.
|
|
5712.3.22
by Jelmer Vernooij
Add some notes about probers. |
1210 |
|
1211 |
See BzrProber and RemoteBzrProber in bzrlib.bzrdir for the
|
|
1212 |
probers that detect .bzr/ directories and Bazaar smart servers,
|
|
1213 |
respectively.
|
|
1214 |
||
1215 |
Probers should be registered using the register_server_prober or
|
|
1216 |
register_prober methods on ControlDirFormat.
|
|
|
5363.2.8
by Jelmer Vernooij
Docstrings. |
1217 |
"""
|
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1218 |
|
1219 |
def probe_transport(self, transport): |
|
|
5363.2.8
by Jelmer Vernooij
Docstrings. |
1220 |
"""Return the controldir style format present in a directory. |
1221 |
||
1222 |
:raise UnknownFormatError: If a control dir was found but is
|
|
1223 |
in an unknown format.
|
|
1224 |
:raise NotBranchError: If no control directory was found.
|
|
1225 |
:return: A ControlDirFormat instance.
|
|
1226 |
"""
|
|
|
5363.2.5
by Jelmer Vernooij
Add dummy foreign prober. |
1227 |
raise NotImplementedError(self.probe_transport) |
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1228 |
|
|
5712.3.15
by Jelmer Vernooij
Remove unused register format functions. |
1229 |
@classmethod
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
1230 |
def known_formats(klass): |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
1231 |
"""Return the control dir formats known by this prober. |
1232 |
||
|
5712.3.21
by Jelmer Vernooij
Add note about sets. |
1233 |
Multiple probers can return the same formats, so this should
|
1234 |
return a set.
|
|
1235 |
||
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
1236 |
:return: A set of known formats.
|
1237 |
"""
|
|
|
6207.3.6
by Jelmer Vernooij
use klass rather than cls everywhere for consistency |
1238 |
raise NotImplementedError(klass.known_formats) |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
1239 |
|
|
5363.2.4
by Jelmer Vernooij
Introduce probers, use controldir in a couple more places. |
1240 |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1241 |
class ControlDirFormatInfo(object): |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1242 |
|
1243 |
def __init__(self, native, deprecated, hidden, experimental): |
|
1244 |
self.deprecated = deprecated |
|
1245 |
self.native = native |
|
1246 |
self.hidden = hidden |
|
1247 |
self.experimental = experimental |
|
1248 |
||
1249 |
||
1250 |
class ControlDirFormatRegistry(registry.Registry): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1251 |
"""Registry of user-selectable ControlDir subformats. |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1252 |
|
1253 |
Differs from ControlDirFormat._formats in that it provides sub-formats,
|
|
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
1254 |
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1255 |
"""
|
1256 |
||
1257 |
def __init__(self): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1258 |
"""Create a ControlDirFormatRegistry.""" |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1259 |
self._aliases = set() |
1260 |
self._registration_order = list() |
|
1261 |
super(ControlDirFormatRegistry, self).__init__() |
|
1262 |
||
1263 |
def aliases(self): |
|
1264 |
"""Return a set of the format names which are aliases.""" |
|
1265 |
return frozenset(self._aliases) |
|
1266 |
||
1267 |
def register(self, key, factory, help, native=True, deprecated=False, |
|
1268 |
hidden=False, experimental=False, alias=False): |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1269 |
"""Register a ControlDirFormat factory. |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1270 |
|
1271 |
The factory must be a callable that takes one parameter: the key.
|
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1272 |
It must produce an instance of the ControlDirFormat when called.
|
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1273 |
|
1274 |
This function mainly exists to prevent the info object from being
|
|
1275 |
supplied directly.
|
|
1276 |
"""
|
|
1277 |
registry.Registry.register(self, key, factory, help, |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1278 |
ControlDirFormatInfo(native, deprecated, hidden, experimental)) |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1279 |
if alias: |
1280 |
self._aliases.add(key) |
|
1281 |
self._registration_order.append(key) |
|
1282 |
||
1283 |
def register_lazy(self, key, module_name, member_name, help, native=True, |
|
1284 |
deprecated=False, hidden=False, experimental=False, alias=False): |
|
1285 |
registry.Registry.register_lazy(self, key, module_name, member_name, |
|
|
5363.2.16
by Jelmer Vernooij
Switch naming in a couple more places. |
1286 |
help, ControlDirFormatInfo(native, deprecated, hidden, experimental)) |
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1287 |
if alias: |
1288 |
self._aliases.add(key) |
|
1289 |
self._registration_order.append(key) |
|
1290 |
||
1291 |
def set_default(self, key): |
|
1292 |
"""Set the 'default' key to be a clone of the supplied key. |
|
1293 |
||
1294 |
This method must be called once and only once.
|
|
1295 |
"""
|
|
1296 |
registry.Registry.register(self, 'default', self.get(key), |
|
1297 |
self.get_help(key), info=self.get_info(key)) |
|
1298 |
self._aliases.add('default') |
|
1299 |
||
1300 |
def set_default_repository(self, key): |
|
1301 |
"""Set the FormatRegistry default and Repository default. |
|
1302 |
||
1303 |
This is a transitional method while Repository.set_default_format
|
|
1304 |
is deprecated.
|
|
1305 |
"""
|
|
1306 |
if 'default' in self: |
|
1307 |
self.remove('default') |
|
1308 |
self.set_default(key) |
|
1309 |
format = self.get('default')() |
|
1310 |
||
1311 |
def make_bzrdir(self, key): |
|
1312 |
return self.get(key)() |
|
1313 |
||
1314 |
def help_topic(self, topic): |
|
1315 |
output = "" |
|
1316 |
default_realkey = None |
|
1317 |
default_help = self.get_help('default') |
|
1318 |
help_pairs = [] |
|
1319 |
for key in self._registration_order: |
|
1320 |
if key == 'default': |
|
1321 |
continue
|
|
1322 |
help = self.get_help(key) |
|
1323 |
if help == default_help: |
|
1324 |
default_realkey = key |
|
1325 |
else: |
|
1326 |
help_pairs.append((key, help)) |
|
1327 |
||
1328 |
def wrapped(key, help, info): |
|
1329 |
if info.native: |
|
1330 |
help = '(native) ' + help |
|
1331 |
return ':%s:\n%s\n\n' % (key, |
|
1332 |
textwrap.fill(help, initial_indent=' ', |
|
1333 |
subsequent_indent=' ', |
|
1334 |
break_long_words=False)) |
|
1335 |
if default_realkey is not None: |
|
1336 |
output += wrapped(default_realkey, '(default) %s' % default_help, |
|
1337 |
self.get_info('default')) |
|
1338 |
deprecated_pairs = [] |
|
1339 |
experimental_pairs = [] |
|
1340 |
for key, help in help_pairs: |
|
1341 |
info = self.get_info(key) |
|
1342 |
if info.hidden: |
|
1343 |
continue
|
|
1344 |
elif info.deprecated: |
|
1345 |
deprecated_pairs.append((key, help)) |
|
1346 |
elif info.experimental: |
|
1347 |
experimental_pairs.append((key, help)) |
|
1348 |
else: |
|
1349 |
output += wrapped(key, help, info) |
|
1350 |
output += "\nSee :doc:`formats-help` for more about storage formats." |
|
1351 |
other_output = "" |
|
1352 |
if len(experimental_pairs) > 0: |
|
1353 |
other_output += "Experimental formats are shown below.\n\n" |
|
1354 |
for key, help in experimental_pairs: |
|
1355 |
info = self.get_info(key) |
|
1356 |
other_output += wrapped(key, help, info) |
|
1357 |
else: |
|
1358 |
other_output += \ |
|
1359 |
"No experimental formats are available.\n\n" |
|
1360 |
if len(deprecated_pairs) > 0: |
|
1361 |
other_output += "\nDeprecated formats are shown below.\n\n" |
|
1362 |
for key, help in deprecated_pairs: |
|
1363 |
info = self.get_info(key) |
|
1364 |
other_output += wrapped(key, help, info) |
|
1365 |
else: |
|
1366 |
other_output += \ |
|
1367 |
"\nNo deprecated formats are available.\n\n" |
|
1368 |
other_output += \ |
|
1369 |
"\nSee :doc:`formats-help` for more about storage formats." |
|
1370 |
||
1371 |
if topic == 'other-formats': |
|
1372 |
return other_output |
|
1373 |
else: |
|
1374 |
return output |
|
1375 |
||
1376 |
||
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
1377 |
class RepoInitHookParams(object): |
1378 |
"""Object holding parameters passed to `*_repo_init` hooks. |
|
1379 |
||
1380 |
There are 4 fields that hooks may wish to access:
|
|
1381 |
||
1382 |
:ivar repository: Repository created
|
|
1383 |
:ivar format: Repository format
|
|
1384 |
:ivar bzrdir: The controldir for the repository
|
|
1385 |
:ivar shared: The repository is shared
|
|
1386 |
"""
|
|
1387 |
||
1388 |
def __init__(self, repository, format, controldir, shared): |
|
1389 |
"""Create a group of RepoInitHook parameters. |
|
1390 |
||
1391 |
:param repository: Repository created
|
|
1392 |
:param format: Repository format
|
|
1393 |
:param controldir: The controldir for the repository
|
|
1394 |
:param shared: The repository is shared
|
|
1395 |
"""
|
|
1396 |
self.repository = repository |
|
1397 |
self.format = format |
|
1398 |
self.bzrdir = controldir |
|
1399 |
self.shared = shared |
|
1400 |
||
1401 |
def __eq__(self, other): |
|
1402 |
return self.__dict__ == other.__dict__ |
|
1403 |
||
1404 |
def __repr__(self): |
|
1405 |
if self.repository: |
|
1406 |
return "<%s for %s>" % (self.__class__.__name__, |
|
1407 |
self.repository) |
|
1408 |
else: |
|
1409 |
return "<%s for %s>" % (self.__class__.__name__, |
|
1410 |
self.bzrdir) |
|
1411 |
||
1412 |
||
|
5363.2.6
by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober. |
1413 |
# Please register new formats after old formats so that formats
|
1414 |
# appear in chronological order and format descriptions can build
|
|
1415 |
# on previous ones.
|
|
1416 |
format_registry = ControlDirFormatRegistry() |
|
|
5363.2.23
by Jelmer Vernooij
Move network_format_registry to bzrlib.controldir. |
1417 |
|
1418 |
network_format_registry = registry.FormatRegistry() |
|
1419 |
"""Registry of formats indexed by their network name.
|
|
1420 |
||
1421 |
The network name for a ControlDirFormat is an identifier that can be used when
|
|
1422 |
referring to formats with smart server operations. See
|
|
1423 |
ControlDirFormat.network_name() for more detail.
|
|
1424 |
"""
|