/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Aaron Bentley
  • Date: 2008-02-24 16:42:13 UTC
  • mfrom: (3234 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: aaron@aaronbentley.com-20080224164213-eza1lzru5bwuwmmj
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
245
245
            format = BzrDirFormat.get_default_format()
246
246
        return format.initialize_on_transport(t)
247
247
 
 
248
    @staticmethod
 
249
    def find_bzrdirs(transport, evaluate=None, list_current=None):
 
250
        """Find bzrdirs recursively from current location.
 
251
 
 
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.
 
262
        """
 
263
        if list_current is None:
 
264
            def list_current(transport):
 
265
                return transport.list_dir('')
 
266
        if evaluate is None:
 
267
            def evaluate(bzrdir):
 
268
                return True, bzrdir
 
269
 
 
270
        pending = [transport]
 
271
        while len(pending) > 0:
 
272
            current_transport = pending.pop()
 
273
            recurse = True
 
274
            try:
 
275
                bzrdir = BzrDir.open_from_transport(current_transport)
 
276
            except errors.NotBranchError:
 
277
                pass
 
278
            else:
 
279
                recurse, value = evaluate(bzrdir)
 
280
                yield value
 
281
            try:
 
282
                subdirs = list_current(current_transport)
 
283
            except errors.NoSuchFile:
 
284
                continue
 
285
            if recurse:
 
286
                for subdir in sorted(subdirs, reverse=True):
 
287
                    pending.append(current_transport.clone(subdir))
 
288
 
 
289
    @staticmethod
 
290
    def find_branches(transport):
 
291
        """Find all branches under a transport.
 
292
 
 
293
        This will find all branches below the transport, including branches
 
294
        inside other branches.  Where possible, it will use
 
295
        Repository.find_branches.
 
296
 
 
297
        To list all the branches that use a particular Repository, see
 
298
        Repository.find_branches
 
299
        """
 
300
        def evaluate(bzrdir):
 
301
            try:
 
302
                repository = bzrdir.open_repository()
 
303
            except errors.NoRepositoryPresent:
 
304
                pass
 
305
            else:
 
306
                return False, (None, repository)
 
307
            try:
 
308
                branch = bzrdir.open_branch()
 
309
            except errors.NotBranchError:
 
310
                return True, (None, None)
 
311
            else:
 
312
                return True, (branch, None)
 
313
        branches = []
 
314
        for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
 
315
            if repo is not None:
 
316
                branches.extend(repo.find_branches())
 
317
            if branch is not None:
 
318
                branches.append(branch)
 
319
        return branches
 
320
 
 
321
 
248
322
    def destroy_repository(self):
249
323
        """Destroy the repository in this BzrDir"""
250
324
        raise NotImplementedError(self.destroy_repository)
674
748
    def _get_tree_branch(self):
675
749
        """Return the branch and tree, if any, for this bzrdir.
676
750
 
677
 
        Return None for tree if not present.
 
751
        Return None for tree if not present or inaccessible.
678
752
        Raise NotBranchError if no branch is present.
679
753
        :return: (tree, branch)
680
754
        """
1971
2045
    def _load_updated_inventory(self, rev_id):
1972
2046
        assert rev_id in self.converted_revs
1973
2047
        inv_xml = self.inv_weave.get_text(rev_id)
1974
 
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
 
2048
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
1975
2049
        return inv
1976
2050
 
1977
2051
    def _convert_one_rev(self, rev_id):
2378
2452
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2379
2453
    """
2380
2454
 
 
2455
    def __init__(self):
 
2456
        """Create a BzrDirFormatRegistry."""
 
2457
        self._aliases = set()
 
2458
        super(BzrDirFormatRegistry, self).__init__()
 
2459
 
 
2460
    def aliases(self):
 
2461
        """Return a set of the format names which are aliases."""
 
2462
        return frozenset(self._aliases)
 
2463
 
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,
2385
2468
             hidden=False,
2386
 
             experimental=False):
 
2469
             experimental=False,
 
2470
             alias=False):
2387
2471
        """Register a metadir subformat.
2388
2472
 
2389
2473
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2422
2506
                bd.repository_format = _load(repository_format)
2423
2507
            return bd
2424
2508
        self.register(key, helper, help, native, deprecated, hidden,
2425
 
            experimental)
 
2509
            experimental, alias)
2426
2510
 
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.
2430
2514
        
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.
2436
2520
        """
2437
 
        registry.Registry.register(self, key, factory, help, 
 
2521
        registry.Registry.register(self, key, factory, help,
2438
2522
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
 
2523
        if alias:
 
2524
            self._aliases.add(key)
2439
2525
 
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))
 
2530
        if alias:
 
2531
            self._aliases.add(key)
2444
2532
 
2445
2533
    def set_default(self, key):
2446
2534
        """Set the 'default' key to be a clone of the supplied key.
2447
2535
        
2448
2536
        This method must be called once and only once.
2449
2537
        """
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')
2452
2541
 
2453
2542
    def set_default_repository(self, key):
2454
2543
        """Set the FormatRegistry default and Repository default.
2557
2646
        ' bzr < 1.0',
2558
2647
    branch_format='bzrlib.branch.BzrBranchFormat6',
2559
2648
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2560
 
    hidden=False,
2561
2649
    )
2562
2650
format_registry.register_metadir('dirstate-with-subtree',
2563
2651
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2566
2654
        'bzr branches. Incompatible with bzr < 0.15.',
2567
2655
    branch_format='bzrlib.branch.BzrBranchFormat6',
2568
2656
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2657
    experimental=True,
2569
2658
    hidden=True,
2570
2659
    )
2571
2660
format_registry.register_metadir('pack-0.92',
2578
2667
        'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2579
2668
    branch_format='bzrlib.branch.BzrBranchFormat6',
2580
2669
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2581
 
    experimental=True,
2582
2670
    )
2583
2671
format_registry.register_metadir('pack-0.92-subtree',
2584
2672
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
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',
2605
 
    hidden=False,
 
2687
        'rich-root format repositories. Incompatible with'
 
2688
        ' bzr < 1.0',
 
2689
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2690
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2691
    )
 
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. '
 
2698
        'Please read '
 
2699
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2700
        'before use.',
 
2701
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2702
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2703
    experimental=True,
 
2704
    alias=True,
 
2705
    )
 
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 '
 
2713
        'before use.',
 
2714
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2715
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2716
    experimental=True,
 
2717
    alias=True,
 
2718
    )
 
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. '
 
2723
        'Please read '
 
2724
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2725
        'before use.',
 
2726
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2727
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2728
    hidden=True,
 
2729
    experimental=True,
 
2730
    )
 
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. '
 
2734
        'Please read '
 
2735
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2736
        'before use.',
 
2737
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2738
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2739
    hidden=True,
2606
2740
    experimental=True,
2607
2741
    )
2608
2742
format_registry.set_default('pack-0.92')