130
130
return list(self.get_branches().values())
132
def branch_names(self):
133
"""List all branch names in this control directory.
135
:return: List of branch names
138
self.get_branch_reference()
139
except (errors.NotBranchError, errors.NoRepositoryPresent):
144
132
def get_branches(self):
145
133
"""Get all branches in this control directory, as a dictionary.
164
152
this in the future - for instance to make bzr talk with svn working
167
return self._format.is_control_filename(filename)
155
raise NotImplementedError(self.is_control_filename)
169
157
def needs_format_conversion(self, format=None):
170
158
"""Return true if this controldir needs convert_format run on it.
412
400
raise NotImplementedError(self.sprout)
414
402
def push_branch(self, source, revision_id=None, overwrite=False,
415
remember=False, create_prefix=False, lossy=False,
403
remember=False, create_prefix=False, lossy=False):
417
404
"""Push the source branch into this ControlDir."""
419
406
# If we can open a branch, use its direct repository, otherwise see
438
425
revision_id = source.last_revision()
439
426
repository_to.fetch(source.repository, revision_id=revision_id)
440
br_to = source.sprout(
441
self, revision_id=revision_id, lossy=lossy,
442
tag_selector=tag_selector)
427
br_to = source.sprout(self, revision_id=revision_id, lossy=lossy)
443
428
if source.get_push_location() is None or remember:
444
429
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
445
430
source.set_push_location(br_to.base)
459
444
tree_to = self.open_workingtree()
460
445
except errors.NotLocalUrl:
461
push_result.branch_push_result = source.push(
462
br_to, overwrite, stop_revision=revision_id, lossy=lossy,
463
tag_selector=tag_selector)
446
push_result.branch_push_result = source.push(br_to,
447
overwrite, stop_revision=revision_id, lossy=lossy)
464
448
push_result.workingtree_updated = False
465
449
except errors.NoWorkingTree:
466
push_result.branch_push_result = source.push(
467
br_to, overwrite, stop_revision=revision_id, lossy=lossy,
468
tag_selector=tag_selector)
450
push_result.branch_push_result = source.push(br_to,
451
overwrite, stop_revision=revision_id, lossy=lossy)
469
452
push_result.workingtree_updated = None # Not applicable
471
454
with tree_to.lock_write():
472
455
push_result.branch_push_result = source.push(
473
456
tree_to.branch, overwrite, stop_revision=revision_id,
474
lossy=lossy, tag_selector=tag_selector)
476
459
push_result.workingtree_updated = True
477
460
push_result.old_revno = push_result.branch_push_result.old_revno
510
493
raise NotImplementedError(self.check_conversion_target)
512
495
def clone(self, url, revision_id=None, force_new_repo=False,
513
preserve_stacking=False, tag_selector=None):
496
preserve_stacking=False):
514
497
"""Clone this controldir and its contents to url verbatim.
516
499
:param url: The url create the clone at. If url's last component does
526
509
return self.clone_on_transport(_mod_transport.get_transport(url),
527
510
revision_id=revision_id,
528
511
force_new_repo=force_new_repo,
529
preserve_stacking=preserve_stacking,
530
tag_selector=tag_selector)
512
preserve_stacking=preserve_stacking)
532
514
def clone_on_transport(self, transport, revision_id=None,
533
515
force_new_repo=False, preserve_stacking=False, stacked_on=None,
534
create_prefix=False, use_existing_dir=True, no_tree=False,
516
create_prefix=False, use_existing_dir=True, no_tree=False):
536
517
"""Clone this controldir and its contents to transport verbatim.
538
519
:param transport: The transport for the location to produce the clone
582
563
controldir = klass.open_from_transport(current_transport)
583
except (errors.NotBranchError, errors.PermissionDenied,
584
errors.UnknownFormatError):
564
except (errors.NotBranchError, errors.PermissionDenied):
587
567
recurse, value = evaluate(controldir)
808
788
a_transport = new_t
811
def open_tree_or_branch(klass, location, name=None):
791
def open_tree_or_branch(klass, location):
812
792
"""Return the branch and working tree at a location.
814
794
If there is no tree at the location, tree will be None.
817
797
:return: (tree, branch)
819
799
controldir = klass.open(location)
820
return controldir._get_tree_branch(name=name)
800
return controldir._get_tree_branch()
823
803
def open_containing_tree_or_branch(klass, location,
1047
1027
_default_format = None
1048
1028
"""The default format used for new control directories."""
1030
_server_probers = []
1031
"""The registered server format probers, e.g. RemoteBzrProber.
1033
This is a list of Prober-derived classes.
1051
1037
"""The registered format probers, e.g. BzrProber.
1138
1124
klass._probers.remove(prober)
1127
def register_server_prober(klass, prober):
1128
"""Register a control format prober for client-server environments.
1130
These probers will be used before ones registered with
1131
register_prober. This gives implementations that decide to the
1132
chance to grab it before anything looks at the contents of the format
1135
klass._server_probers.append(prober)
1140
1137
def __str__(self):
1141
1138
# Trim the newline
1142
1139
return self.get_format_description().rstrip()
1145
1142
def all_probers(klass):
1146
return klass._probers
1143
return klass._server_probers + klass._probers
1149
1146
def known_formats(klass):
1158
1155
def find_format(klass, transport, probers=None):
1159
1156
"""Return the format present at transport."""
1160
1157
if probers is None:
1162
klass.all_probers(),
1163
key=lambda prober: prober.priority(transport))
1158
probers = klass.all_probers()
1164
1159
for prober_kls in probers:
1165
1160
prober = prober_kls()
1252
1247
raise NotImplementedError(self.supports_transport)
1255
def is_control_filename(klass, filename):
1256
"""True if filename is the name of a path which is reserved for
1259
:param filename: A filename within the root transport of this
1262
This is true IF and ONLY IF the filename is part of the namespace reserved
1263
for bzr control dirs. Currently this is the '.bzr' directory in the root
1264
of the root_transport. it is expected that plugins will need to extend
1265
this in the future - for instance to make bzr talk with svn working
1268
raise NotImplementedError(self.is_control_filename)
1271
1250
class Prober(object):
1272
1251
"""Abstract class that can be used to detect a particular kind of
1280
1259
probers that detect .bzr/ directories and Bazaar smart servers,
1283
Probers should be registered using the register_prober methods on
1262
Probers should be registered using the register_server_prober or
1263
register_prober methods on ControlDirFormat.
1287
1266
def probe_transport(self, transport):
1306
1285
raise NotImplementedError(klass.known_formats)
1309
def priority(klass, transport):
1310
"""Priority of this prober.
1312
A lower value means the prober gets checked first.
1316
-10: This is a "server" prober
1318
10: This is a regular file-based prober
1319
100: This is a prober for an unsupported format
1324
1288
class ControlDirFormatInfo(object):
1498
1462
def is_control_filename(filename):
1499
1463
"""Check if filename is used for control directories."""
1500
# TODO(jelmer): Instead, have a function that returns all control
1502
for key, format in format_registry.items():
1503
if format().is_control_filename(filename):
1464
# TODO(jelmer): Allow registration by other VCSes
1465
return filename == '.bzr'
1509
1468
class RepositoryAcquisitionPolicy(object):