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)
248
322
def destroy_repository(self):
249
323
"""Destroy the repository in this BzrDir"""
250
324
raise NotImplementedError(self.destroy_repository)
2378
2452
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2456
"""Create a BzrDirFormatRegistry."""
2457
self._aliases = set()
2458
super(BzrDirFormatRegistry, self).__init__()
2461
"""Return a set of the format names which are aliases."""
2462
return frozenset(self._aliases)
2381
2464
def register_metadir(self, key,
2382
2465
repository_format, help, native=True, deprecated=False,
2383
2466
branch_format=None,
2384
2467
tree_format=None,
2386
experimental=False):
2387
2471
"""Register a metadir subformat.
2389
2473
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2422
2506
bd.repository_format = _load(repository_format)
2424
2508
self.register(key, helper, help, native, deprecated, hidden,
2509
experimental, alias)
2427
2511
def register(self, key, factory, help, native=True, deprecated=False,
2428
hidden=False, experimental=False):
2512
hidden=False, experimental=False, alias=False):
2429
2513
"""Register a BzrDirFormat factory.
2431
2515
The factory must be a callable that takes one parameter: the key.
2434
2518
This function mainly exists to prevent the info object from being
2435
2519
supplied directly.
2437
registry.Registry.register(self, key, factory, help,
2521
registry.Registry.register(self, key, factory, help,
2438
2522
BzrDirFormatInfo(native, deprecated, hidden, experimental))
2524
self._aliases.add(key)
2440
2526
def register_lazy(self, key, module_name, member_name, help, native=True,
2441
deprecated=False, hidden=False, experimental=False):
2442
registry.Registry.register_lazy(self, key, module_name, member_name,
2527
deprecated=False, hidden=False, experimental=False, alias=False):
2528
registry.Registry.register_lazy(self, key, module_name, member_name,
2443
2529
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2531
self._aliases.add(key)
2445
2533
def set_default(self, key):
2446
2534
"""Set the 'default' key to be a clone of the supplied key.
2448
2536
This method must be called once and only once.
2450
registry.Registry.register(self, 'default', self.get(key),
2538
registry.Registry.register(self, 'default', self.get(key),
2451
2539
self.get_help(key), info=self.get_info(key))
2540
self._aliases.add('default')
2453
2542
def set_default_repository(self, key):
2454
2543
"""Set the FormatRegistry default and Repository default.
2596
2684
format_registry.register_metadir('rich-root-pack',
2597
2685
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
2598
2686
help='New in 1.0: Pack-based format with data compatible with '
2599
'rich-root format repositories. Interoperates with '
2600
'bzr repositories before 0.92 but cannot be read by bzr < 1.0. '
2601
'NOTE: This format is experimental. Before using it, please read '
2602
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2603
branch_format='bzrlib.branch.BzrBranchFormat6',
2604
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2687
'rich-root format repositories. Incompatible with'
2689
branch_format='bzrlib.branch.BzrBranchFormat6',
2690
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2692
# The following two formats should always just be aliases.
2693
format_registry.register_metadir('development',
2694
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2695
help='Current development format. Can convert data to and from pack-0.92 '
2696
'(and anything compatible with pack-0.92) format repositories. '
2697
'Repositories in this format can only be read by bzr.dev. '
2699
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2701
branch_format='bzrlib.branch.BzrBranchFormat6',
2702
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2706
format_registry.register_metadir('development-subtree',
2707
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2708
help='Current development format, subtree variant. Can convert data to and '
2709
'from pack-0.92 (and anything compatible with pack-0.92) format '
2710
'repositories. Repositories in this format can only be read by '
2711
'bzr.dev. Please read '
2712
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2714
branch_format='bzrlib.branch.BzrBranchFormat6',
2715
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2719
# And the development formats which the will have aliased one of follow:
2720
format_registry.register_metadir('development0',
2721
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2722
help='Trivial rename of pack-0.92 to provide a development format. '
2724
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2726
branch_format='bzrlib.branch.BzrBranchFormat6',
2727
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2731
format_registry.register_metadir('development0-subtree',
2732
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2733
help='Trivial rename of pack-0.92-subtree to provide a development format. '
2735
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2737
branch_format='bzrlib.branch.BzrBranchFormat6',
2738
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2606
2740
experimental=True,
2608
2742
format_registry.set_default('pack-0.92')