243
245
format = BzrDirFormat.get_default_format()
244
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
def destroy_repository(self):
323
"""Destroy the repository in this BzrDir"""
324
raise NotImplementedError(self.destroy_repository)
246
326
def create_branch(self):
247
327
"""Create a branch in this BzrDir.
375
455
format=format).bzrdir
376
456
return bzrdir.create_workingtree()
378
def create_workingtree(self, revision_id=None, from_branch=None):
458
def create_workingtree(self, revision_id=None, from_branch=None,
459
accelerator_tree=None):
379
460
"""Create a working tree at this BzrDir.
381
462
:param revision_id: create it as of this revision id.
382
463
: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.
384
469
raise NotImplementedError(self.create_workingtree)
660
745
raise errors.NotBranchError(path=url)
661
746
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 or inaccessible.
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()
664
777
def open_containing_tree_or_branch(klass, location):
665
778
"""Return the branch and working tree contained by a location.
671
784
relpath is the portion of the path that is contained by the branch.
673
786
bzrdir, relpath = klass.open_containing(location)
675
tree = bzrdir.open_workingtree()
676
except (errors.NoWorkingTree, errors.NotLocalUrl):
678
branch = bzrdir.open_branch()
787
tree, branch = bzrdir._get_tree_branch()
681
788
return tree, branch, relpath
683
790
def open_repository(self, _unsupported=False):
782
889
return self.cloning_metadir()
784
891
def sprout(self, url, revision_id=None, force_new_repo=False,
785
recurse='down', possible_transports=None):
892
recurse='down', possible_transports=None,
893
accelerator_tree=None):
786
894
"""Create a copy of this bzrdir prepared for use as a new line of
796
904
if revision_id is not None, then the clone operation may tune
797
905
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.
799
911
target_transport = get_transport(url, possible_transports)
800
912
target_transport.ensure_base()
929
1041
raise errors.IncompatibleFormat('shared repository', self._format)
930
1042
return self.open_repository()
932
def create_workingtree(self, revision_id=None, from_branch=None):
1044
def destroy_repository(self):
1045
"""See BzrDir.destroy_repository."""
1046
raise errors.UnsupportedOperation(self.destroy_repository, self)
1048
def create_workingtree(self, revision_id=None, from_branch=None,
1049
accelerator_tree=None):
933
1050
"""See BzrDir.create_workingtree."""
934
1051
# this looks buggy but is not -really-
935
1052
# because this format creates the workingtree when the bzrdir is
1003
1120
return format.open(self, _found=True)
1005
1122
def sprout(self, url, revision_id=None, force_new_repo=False,
1006
possible_transports=None):
1123
possible_transports=None, accelerator_tree=None):
1007
1124
"""See BzrDir.sprout()."""
1008
1125
from bzrlib.workingtree import WorkingTreeFormat2
1009
1126
self._make_tail(url)
1107
1225
"""See BzrDir.create_repository."""
1108
1226
return self._format.repository_format.initialize(self, shared)
1110
def create_workingtree(self, revision_id=None, from_branch=None):
1228
def destroy_repository(self):
1229
"""See BzrDir.destroy_repository."""
1230
self.transport.delete_tree('repository')
1232
def create_workingtree(self, revision_id=None, from_branch=None,
1233
accelerator_tree=None):
1111
1234
"""See BzrDir.create_workingtree."""
1112
1235
return self._format.workingtree_format.initialize(
1113
self, revision_id, from_branch=from_branch)
1236
self, revision_id, from_branch=from_branch,
1237
accelerator_tree=accelerator_tree)
1115
1239
def destroy_workingtree(self):
1116
1240
"""See BzrDir.destroy_workingtree."""
1914
2040
def _load_updated_inventory(self, rev_id):
1915
2041
assert rev_id in self.converted_revs
1916
2042
inv_xml = self.inv_weave.get_text(rev_id)
1917
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
2043
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
1920
2046
def _convert_one_rev(self, rev_id):
1984
2110
assert getattr(ie, 'revision', None) is not None
2112
@symbol_versioning.deprecated_method(symbol_versioning.one_one)
1986
2113
def get_parents(self, revision_ids):
1987
2114
for revision_id in revision_ids:
1988
2115
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)
1990
2123
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
1991
2124
# TODO: convert this logic, which is ~= snapshot to
1992
2125
# a call to:. This needs the path figured out. rather than a work_tree
2487
2620
branch_format='bzrlib.branch.BzrBranchFormat6',
2488
2621
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2623
format_registry.register_metadir('rich-root',
2624
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2625
help='New in 1.0. Better handling of tree roots. Incompatible with'
2627
branch_format='bzrlib.branch.BzrBranchFormat6',
2628
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2490
2630
format_registry.register_metadir('dirstate-with-subtree',
2491
2631
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2492
2632
help='New in 0.15: Fast local operations and improved scaling for '
2494
2634
'bzr branches. Incompatible with bzr < 0.15.',
2495
2635
branch_format='bzrlib.branch.BzrBranchFormat6',
2496
2636
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2499
format_registry.register_metadir('knitpack-experimental',
2640
format_registry.register_metadir('pack-0.92',
2500
2641
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
2501
2642
help='New in 0.92: Pack-based format with data compatible with '
2502
2643
'dirstate-tags format repositories. Interoperates with '
2503
2644
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2504
'NOTE: This format is experimental. Before using it, please read '
2505
'http://doc.bazaar-vcs.org/latest/developers/knitpack.html.',
2645
'Previously called knitpack-experimental. '
2646
'For more information, see '
2647
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2506
2648
branch_format='bzrlib.branch.BzrBranchFormat6',
2507
2649
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2510
format_registry.register_metadir('knitpack-subtree-experimental',
2651
format_registry.register_metadir('pack-0.92-subtree',
2511
2652
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
2512
2653
help='New in 0.92: Pack-based format with data compatible with '
2513
2654
'dirstate-with-subtree format repositories. Interoperates with '
2514
2655
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2515
'NOTE: This format is experimental. Before using it, please read '
2516
'http://doc.bazaar-vcs.org/latest/developers/knitpack.html.',
2656
'Previously called knitpack-experimental. '
2657
'For more information, see '
2658
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2517
2659
branch_format='bzrlib.branch.BzrBranchFormat6',
2518
2660
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2520
2662
experimental=True,
2522
format_registry.set_default('dirstate-tags')
2664
format_registry.register_metadir('rich-root-pack',
2665
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
2666
help='New in 1.0: Pack-based format with data compatible with '
2667
'rich-root format repositories. Incompatible with'
2669
branch_format='bzrlib.branch.BzrBranchFormat6',
2670
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2672
format_registry.set_default('pack-0.92')