245
245
format = BzrDirFormat.get_default_format()
246
246
return format.initialize_on_transport(t)
249
def find_bzrdirs(transport, evaluate=None, list_current=None):
250
"""Find bzrdirs recursively from current location.
252
This is intended primarily as a building block for more sophisticated
253
functionality, like finding trees under a directory, or finding
254
branches that use a given repository.
255
:param evaluate: An optional callable that yields recurse, value,
256
where recurse controls whether this bzrdir is recursed into
257
and value is the value to yield. By default, all bzrdirs
258
are recursed into, and the return value is the bzrdir.
259
:param list_current: if supplied, use this function to list the current
260
directory, instead of Transport.list_dir
261
:return: a generator of found bzrdirs, or whatever evaluate returns.
263
if list_current is None:
264
def list_current(transport):
265
return transport.list_dir('')
267
def evaluate(bzrdir):
270
pending = [transport]
271
while len(pending) > 0:
272
current_transport = pending.pop()
275
bzrdir = BzrDir.open_from_transport(current_transport)
276
except errors.NotBranchError:
279
recurse, value = evaluate(bzrdir)
282
subdirs = list_current(current_transport)
283
except errors.NoSuchFile:
286
for subdir in sorted(subdirs, reverse=True):
287
pending.append(current_transport.clone(subdir))
290
def find_branches(transport):
291
"""Find all branches under a transport.
293
This will find all branches below the transport, including branches
294
inside other branches. Where possible, it will use
295
Repository.find_branches.
297
To list all the branches that use a particular Repository, see
298
Repository.find_branches
300
def evaluate(bzrdir):
302
repository = bzrdir.open_repository()
303
except errors.NoRepositoryPresent:
306
return False, (None, repository)
308
branch = bzrdir.open_branch()
309
except errors.NotBranchError:
310
return True, (None, None)
312
return True, (branch, None)
314
for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
316
branches.extend(repo.find_branches())
317
if branch is not None:
318
branches.append(branch)
322
248
def destroy_repository(self):
323
249
"""Destroy the repository in this BzrDir"""
324
250
raise NotImplementedError(self.destroy_repository)
455
381
format=format).bzrdir
456
382
return bzrdir.create_workingtree()
458
def create_workingtree(self, revision_id=None, from_branch=None,
459
accelerator_tree=None):
384
def create_workingtree(self, revision_id=None, from_branch=None):
460
385
"""Create a working tree at this BzrDir.
462
387
:param revision_id: create it as of this revision id.
463
388
:param from_branch: override bzrdir branch (for lightweight checkouts)
464
:param accelerator_tree: A tree which can be used for retrieving file
465
contents more quickly than the revision tree, i.e. a workingtree.
466
The revision tree will be used for cases where accelerator_tree's
467
content is different.
469
390
raise NotImplementedError(self.create_workingtree)
745
666
raise errors.NotBranchError(path=url)
746
667
a_transport = new_t
748
def _get_tree_branch(self):
749
"""Return the branch and tree, if any, for this bzrdir.
751
Return None for tree if not present.
752
Raise NotBranchError if no branch is present.
753
:return: (tree, branch)
756
tree = self.open_workingtree()
757
except (errors.NoWorkingTree, errors.NotLocalUrl):
759
branch = self.open_branch()
765
def open_tree_or_branch(klass, location):
766
"""Return the branch and working tree at a location.
768
If there is no tree at the location, tree will be None.
769
If there is no branch at the location, an exception will be
771
:return: (tree, branch)
773
bzrdir = klass.open(location)
774
return bzrdir._get_tree_branch()
777
670
def open_containing_tree_or_branch(klass, location):
778
671
"""Return the branch and working tree contained by a location.
784
677
relpath is the portion of the path that is contained by the branch.
786
679
bzrdir, relpath = klass.open_containing(location)
787
tree, branch = bzrdir._get_tree_branch()
681
tree = bzrdir.open_workingtree()
682
except (errors.NoWorkingTree, errors.NotLocalUrl):
684
branch = bzrdir.open_branch()
788
687
return tree, branch, relpath
790
689
def open_repository(self, _unsupported=False):
889
788
return self.cloning_metadir()
891
790
def sprout(self, url, revision_id=None, force_new_repo=False,
892
recurse='down', possible_transports=None,
893
accelerator_tree=None):
791
recurse='down', possible_transports=None):
894
792
"""Create a copy of this bzrdir prepared for use as a new line of
904
802
if revision_id is not None, then the clone operation may tune
905
803
itself to download less data.
906
:param accelerator_tree: A tree which can be used for retrieving file
907
contents more quickly than the revision tree, i.e. a workingtree.
908
The revision tree will be used for cases where accelerator_tree's
909
content is different.
911
805
target_transport = get_transport(url, possible_transports)
912
806
target_transport.ensure_base()
1045
939
"""See BzrDir.destroy_repository."""
1046
940
raise errors.UnsupportedOperation(self.destroy_repository, self)
1048
def create_workingtree(self, revision_id=None, from_branch=None,
1049
accelerator_tree=None):
942
def create_workingtree(self, revision_id=None, from_branch=None):
1050
943
"""See BzrDir.create_workingtree."""
1051
944
# this looks buggy but is not -really-
1052
945
# because this format creates the workingtree when the bzrdir is
1120
1013
return format.open(self, _found=True)
1122
1015
def sprout(self, url, revision_id=None, force_new_repo=False,
1123
possible_transports=None, accelerator_tree=None):
1016
possible_transports=None):
1124
1017
"""See BzrDir.sprout()."""
1125
1018
from bzrlib.workingtree import WorkingTreeFormat2
1126
1019
self._make_tail(url)
1229
1121
"""See BzrDir.destroy_repository."""
1230
1122
self.transport.delete_tree('repository')
1232
def create_workingtree(self, revision_id=None, from_branch=None,
1233
accelerator_tree=None):
1124
def create_workingtree(self, revision_id=None, from_branch=None):
1234
1125
"""See BzrDir.create_workingtree."""
1235
1126
return self._format.workingtree_format.initialize(
1236
self, revision_id, from_branch=from_branch,
1237
accelerator_tree=accelerator_tree)
1127
self, revision_id, from_branch=from_branch)
1239
1129
def destroy_workingtree(self):
1240
1130
"""See BzrDir.destroy_workingtree."""
2040
1930
def _load_updated_inventory(self, rev_id):
2041
1931
assert rev_id in self.converted_revs
2042
1932
inv_xml = self.inv_weave.get_text(rev_id)
2043
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
1933
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
2046
1936
def _convert_one_rev(self, rev_id):
2110
2000
assert getattr(ie, 'revision', None) is not None
2112
@symbol_versioning.deprecated_method(symbol_versioning.one_one)
2113
2002
def get_parents(self, revision_ids):
2114
2003
for revision_id in revision_ids:
2115
2004
yield self.revisions[revision_id].parent_ids
2117
def get_parent_map(self, revision_ids):
2118
"""See graph._StackedParentsProvider.get_parent_map"""
2119
return dict((revision_id, self.revisions[revision_id])
2120
for revision_id in revision_ids
2121
if revision_id in self.revisions)
2123
2006
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
2124
2007
# TODO: convert this logic, which is ~= snapshot to
2125
2008
# a call to:. This needs the path figured out. rather than a work_tree
2665
2548
format_registry.register_metadir('rich-root-pack',
2666
2549
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
2667
2550
help='New in 1.0: Pack-based format with data compatible with '
2668
'rich-root format repositories. Incompatible with'
2551
'rich-root format repositories. Interoperates with '
2552
'bzr repositories before 0.92 but cannot be read by bzr < 1.0. '
2553
'NOTE: This format is experimental. Before using it, please read '
2554
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2670
2555
branch_format='bzrlib.branch.BzrBranchFormat6',
2671
2556
tree_format='bzrlib.workingtree.WorkingTreeFormat4',