/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: Robert Collins
  • Date: 2008-02-13 03:30:01 UTC
  • mfrom: (3221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3224.
  • Revision ID: robertc@robertcollins.net-20080213033001-rw70ul0zb02ph856
Merge to fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from cStringIO import StringIO
31
31
import os
 
32
import sys
32
33
 
33
34
from bzrlib.lazy_import import lazy_import
34
35
lazy_import(globals(), """
48
49
    symbol_versioning,
49
50
    ui,
50
51
    urlutils,
 
52
    win32utils,
 
53
    workingtree,
 
54
    workingtree_4,
51
55
    xml4,
52
56
    xml5,
53
 
    workingtree,
54
 
    workingtree_4,
55
57
    )
56
58
from bzrlib.osutils import (
57
59
    sha_strings,
243
245
            format = BzrDirFormat.get_default_format()
244
246
        return format.initialize_on_transport(t)
245
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
 
 
322
    def destroy_repository(self):
 
323
        """Destroy the repository in this BzrDir"""
 
324
        raise NotImplementedError(self.destroy_repository)
 
325
 
246
326
    def create_branch(self):
247
327
        """Create a branch in this BzrDir.
248
328
 
375
455
                                               format=format).bzrdir
376
456
        return bzrdir.create_workingtree()
377
457
 
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.
380
461
        
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.
383
468
        """
384
469
        raise NotImplementedError(self.create_workingtree)
385
470
 
660
745
                raise errors.NotBranchError(path=url)
661
746
            a_transport = new_t
662
747
 
 
748
    def _get_tree_branch(self):
 
749
        """Return the branch and tree, if any, for this bzrdir.
 
750
 
 
751
        Return None for tree if not present or inaccessible.
 
752
        Raise NotBranchError if no branch is present.
 
753
        :return: (tree, branch)
 
754
        """
 
755
        try:
 
756
            tree = self.open_workingtree()
 
757
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
758
            tree = None
 
759
            branch = self.open_branch()
 
760
        else:
 
761
            branch = tree.branch
 
762
        return tree, branch
 
763
 
 
764
    @classmethod
 
765
    def open_tree_or_branch(klass, location):
 
766
        """Return the branch and working tree at a location.
 
767
 
 
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
 
770
        raised
 
771
        :return: (tree, branch)
 
772
        """
 
773
        bzrdir = klass.open(location)
 
774
        return bzrdir._get_tree_branch()
 
775
 
663
776
    @classmethod
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.
672
785
        """
673
786
        bzrdir, relpath = klass.open_containing(location)
674
 
        try:
675
 
            tree = bzrdir.open_workingtree()
676
 
        except (errors.NoWorkingTree, errors.NotLocalUrl):
677
 
            tree = None
678
 
            branch = bzrdir.open_branch()
679
 
        else:
680
 
            branch = tree.branch
 
787
        tree, branch = bzrdir._get_tree_branch()
681
788
        return tree, branch, relpath
682
789
 
683
790
    def open_repository(self, _unsupported=False):
782
889
        return self.cloning_metadir()
783
890
 
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
787
895
        development.
788
896
 
795
903
 
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.
798
910
        """
799
911
        target_transport = get_transport(url, possible_transports)
800
912
        target_transport.ensure_base()
839
951
            result.create_branch()
840
952
        if isinstance(target_transport, LocalTransport) and (
841
953
            result_repo is None or result_repo.make_working_trees()):
842
 
            wt = result.create_workingtree()
 
954
            wt = result.create_workingtree(accelerator_tree=accelerator_tree)
843
955
            wt.lock_write()
844
956
            try:
845
957
                if wt.path2id('') is None:
929
1041
            raise errors.IncompatibleFormat('shared repository', self._format)
930
1042
        return self.open_repository()
931
1043
 
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)
 
1047
 
 
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)
1004
1121
 
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)
1017
1134
        except errors.NotBranchError:
1018
1135
            pass
1019
1136
        # we always want a working tree
1020
 
        WorkingTreeFormat2().initialize(result)
 
1137
        WorkingTreeFormat2().initialize(result,
 
1138
                                        accelerator_tree=accelerator_tree)
1021
1139
        return result
1022
1140
 
1023
1141
 
1107
1225
        """See BzrDir.create_repository."""
1108
1226
        return self._format.repository_format.initialize(self, shared)
1109
1227
 
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')
 
1231
 
 
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)
1114
1238
 
1115
1239
    def destroy_workingtree(self):
1116
1240
        """See BzrDir.destroy_workingtree."""
1355
1479
                                      # FIXME: RBC 20060121 don't peek under
1356
1480
                                      # the covers
1357
1481
                                      mode=temp_control._dir_mode)
 
1482
        if sys.platform == 'win32' and isinstance(transport, LocalTransport):
 
1483
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1358
1484
        file_mode = temp_control._file_mode
1359
1485
        del temp_control
1360
1486
        mutter('created control directory in ' + transport.base)
1717
1843
        return RepositoryFormat.get_default_format()
1718
1844
 
1719
1845
    def __set_repository_format(self, value):
1720
 
        """Allow changint the repository format for metadir formats."""
 
1846
        """Allow changing the repository format for metadir formats."""
1721
1847
        self._repository_format = value
1722
1848
 
1723
1849
    repository_format = property(__return_repository_format, __set_repository_format)
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)
1918
2044
        return inv
1919
2045
 
1920
2046
    def _convert_one_rev(self, rev_id):
1983
2109
        del ie.text_id
1984
2110
        assert getattr(ie, 'revision', None) is not None
1985
2111
 
 
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
1989
2116
 
 
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)
 
2122
 
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',
2489
2622
    )
 
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'
 
2626
        ' bzr < 1.0',
 
2627
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2628
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2629
    )
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',
 
2637
    experimental=True,
2497
2638
    hidden=True,
2498
2639
    )
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',
2508
 
    experimental=True,
2509
2650
    )
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',
2519
2661
    hidden=True,
2520
2662
    experimental=True,
2521
2663
    )
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'
 
2668
        ' bzr < 1.0',
 
2669
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2670
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2671
    )
 
2672
format_registry.set_default('pack-0.92')