78
84
_fmt = "This format does not support shelving changes."
81
class WorkingTree(mutabletree.MutableTree, controldir.ControlComponent):
87
class WorkingTree(mutabletree.MutableTree, ControlComponent):
82
88
"""Working copy tree.
84
90
:ivar basedir: The root of the tree on disk. This is a unicode path object
218
224
path = osutils.getcwd()
219
control, relpath = controldir.ControlDir.open_containing(path)
225
control, relpath = ControlDir.open_containing(path)
220
226
return control.open_workingtree(), relpath
295
301
return WorkingTree.open(path, _unsupported=True)
298
def find_trees(location):
299
def list_current(transport):
300
return [d for d in transport.list_dir('')
301
if not controldir.is_control_filename(d)]
303
def evaluate(controldir):
305
tree = controldir.open_workingtree()
306
except errors.NoWorkingTree:
310
t = transport.get_transport(location)
311
iterator = controldir.ControlDir.find_controldirs(t, evaluate=evaluate,
312
list_current=list_current)
313
return [tr for tr in iterator if tr is not None]
315
303
def __repr__(self):
316
304
return "<%s of %s>" % (self.__class__.__name__,
317
305
getattr(self, 'basedir', None))
729
717
def subsume(self, other_tree):
730
718
raise NotImplementedError(self.subsume)
732
def _setup_directory_is_tree_reference(self):
733
if self._branch.repository._format.supports_tree_reference:
734
self._directory_is_tree_reference = \
735
self._directory_may_be_tree_reference
737
self._directory_is_tree_reference = \
738
self._directory_is_never_tree_reference
740
def _directory_is_never_tree_reference(self, relpath):
743
def _directory_may_be_tree_reference(self, relpath):
744
# as a special case, if a directory contains control files then
745
# it's a tree reference, except that the root of the tree is not
746
return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
747
# TODO: We could ask all the control formats whether they
748
# recognize this directory, but at the moment there's no cheap api
749
# to do that. Since we probably can only nest bzr checkouts and
750
# they always use this name it's ok for now. -- mbp 20060306
752
# FIXME: There is an unhandled case here of a subdirectory
753
# containing .bzr but not a branch; that will probably blow up
754
# when you try to commit it. It might happen if there is a
755
# checkout in a subdirectory. This can be avoided by not adding
720
def _directory_is_tree_reference(self, relpath):
721
raise NotImplementedError(self._directory_is_tree_reference)
758
723
def extract(self, path, format=None):
759
724
"""Extract a subtree from this tree.
1373
1338
return next(self.get_canonical_paths([path]))
1376
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
1341
class WorkingTreeFormatRegistry(ControlComponentFormatRegistry):
1377
1342
"""Registry for working tree formats."""
1379
1344
def __init__(self, other_registry=None):
1402
1367
format_registry = WorkingTreeFormatRegistry()
1405
class WorkingTreeFormat(controldir.ControlComponentFormat):
1370
class WorkingTreeFormat(ControlComponentFormat):
1406
1371
"""An encapsulation of the initialization and open routines for a format.
1408
1373
Formats provide three things: