~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 11:35:49 UTC
  • mfrom: (5531.1.3 662509-ignore-empty)
  • Revision ID: pqm@pqm.ubuntu.com-20101108113549-e4mhhq2fe1i0etbf
(vila) Add an option to accept any output from commands in shell-like tests.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
49
49
    remote,
50
50
    repository,
51
51
    revision as _mod_revision,
52
 
    transport as _mod_transport,
53
52
    ui,
54
53
    urlutils,
55
54
    versionedfile,
67
66
    )
68
67
from bzrlib.repofmt import pack_repo
69
68
from bzrlib.smart.client import _SmartClient
70
 
from bzrlib.store.versioned import VersionedFileStore
 
69
from bzrlib.store.versioned import WeaveStore
71
70
from bzrlib.transactions import WriteTransaction
72
71
from bzrlib.transport import (
73
72
    do_catching_redirections,
 
73
    get_transport,
74
74
    local,
75
75
    )
76
 
from bzrlib.weave import (
77
 
    WeaveFile,
78
 
    Weave,
79
 
    )
 
76
from bzrlib.weave import Weave
80
77
""")
81
78
 
82
79
from bzrlib.trace import (
190
187
        :param create_prefix: Create any missing directories leading up to
191
188
            to_transport.
192
189
        :param use_existing_dir: Use an existing directory if one exists.
193
 
        :param no_tree: If set to true prevents creation of a working tree.
194
190
        """
195
191
        # Overview: put together a broad description of what we want to end up
196
192
        # with; then make as few api calls as possible to do it.
279
275
    # TODO: This should be given a Transport, and should chdir up; otherwise
280
276
    # this will open a new connection.
281
277
    def _make_tail(self, url):
282
 
        t = _mod_transport.get_transport(url)
 
278
        t = get_transport(url)
283
279
        t.ensure_base()
284
280
 
285
281
    @staticmethod
469
465
        """
470
466
        if force_new_tree:
471
467
            # check for non local urls
472
 
            t = _mod_transport.get_transport(base, possible_transports)
 
468
            t = get_transport(base, possible_transports)
473
469
            if not isinstance(t, local.LocalTransport):
474
470
                raise errors.NotLocalUrl(base)
475
471
        bzrdir = BzrDir.create(base, format, possible_transports)
497
493
        :param format: Override for the bzrdir format to create.
498
494
        :return: The WorkingTree object.
499
495
        """
500
 
        t = _mod_transport.get_transport(base)
 
496
        t = get_transport(base)
501
497
        if not isinstance(t, local.LocalTransport):
502
498
            raise errors.NotLocalUrl(base)
503
499
        bzrdir = BzrDir.create_branch_and_repo(base,
717
713
 
718
714
        :param _unsupported: a private parameter to the BzrDir class.
719
715
        """
720
 
        t = _mod_transport.get_transport(base, possible_transports)
 
716
        t = get_transport(base, possible_transports=possible_transports)
721
717
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
722
718
 
723
719
    @staticmethod
762
758
        :param url: url to search from.
763
759
        See open_containing_from_transport for more detail.
764
760
        """
765
 
        transport = _mod_transport.get_transport(url, possible_transports)
 
761
        transport = get_transport(url, possible_transports)
766
762
        return BzrDir.open_containing_from_transport(transport)
767
763
 
768
764
    @staticmethod
924
920
        if cls is not BzrDir:
925
921
            raise AssertionError("BzrDir.create always creates the"
926
922
                "default format, not one of %r" % cls)
927
 
        t = _mod_transport.get_transport(base, possible_transports)
 
923
        t = get_transport(base, possible_transports)
928
924
        t.ensure_base()
929
925
        if format is None:
930
926
            format = controldir.ControlDirFormat.get_default_format()
931
927
        return format.initialize_on_transport(t)
932
928
 
933
929
 
 
930
 
934
931
class BzrDirHooks(hooks.Hooks):
935
932
    """Hooks for BzrDir operations."""
936
933
 
1030
1027
            tree.clone(result)
1031
1028
        return result
1032
1029
 
1033
 
    def create_branch(self, name=None, repository=None):
 
1030
    def create_branch(self, name=None):
1034
1031
        """See BzrDir.create_branch."""
1035
 
        if repository is not None:
1036
 
            raise NotImplementedError(
1037
 
                "create_branch(repository=<not None>) on %r" % (self,))
1038
1032
        return self._format.get_branch_format().initialize(self, name=name)
1039
1033
 
1040
1034
    def destroy_branch(self, name=None):
1270
1264
        """See BzrDir.can_convert_format()."""
1271
1265
        return True
1272
1266
 
1273
 
    def create_branch(self, name=None, repository=None):
 
1267
    def create_branch(self, name=None):
1274
1268
        """See BzrDir.create_branch."""
1275
 
        return self._format.get_branch_format().initialize(self, name=name,
1276
 
                repository=repository)
 
1269
        return self._format.get_branch_format().initialize(self, name=name)
1277
1270
 
1278
1271
    def destroy_branch(self, name=None):
1279
1272
        """See BzrDir.create_branch."""
1670
1663
        utf8_files = [('README',
1671
1664
                       "This is a Bazaar control directory.\n"
1672
1665
                       "Do not change any files in this directory.\n"
1673
 
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
 
1666
                       "See http://bazaar-vcs.org/ for more information about Bazaar.\n"),
1674
1667
                      ('branch-format', self.get_format_string()),
1675
1668
                      ]
1676
1669
        # NB: no need to escape relative paths that are url safe.
1847
1840
        return ConvertBzrDir5To6()
1848
1841
 
1849
1842
    def _initialize_for_clone(self, url):
1850
 
        return self.initialize_on_transport(
1851
 
            _mod_transport.get_transport(url), _cloning=True)
 
1843
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1852
1844
 
1853
1845
    def initialize_on_transport(self, transport, _cloning=False):
1854
1846
        """Format 5 dirs always have working tree, branch and repository.
1908
1900
        return ConvertBzrDir6ToMeta()
1909
1901
 
1910
1902
    def _initialize_for_clone(self, url):
1911
 
        return self.initialize_on_transport(
1912
 
            _mod_transport.get_transport(url), _cloning=True)
 
1903
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1913
1904
 
1914
1905
    def initialize_on_transport(self, transport, _cloning=False):
1915
1906
        """Format 6 dirs always have working tree, branch and repository.
2103
2094
        """Circular import protection."""
2104
2095
        if self._repository_format:
2105
2096
            return self._repository_format
2106
 
        from bzrlib.repository import format_registry
2107
 
        return format_registry.get_default()
 
2097
        from bzrlib.repository import RepositoryFormat
 
2098
        return RepositoryFormat.get_default_format()
2108
2099
 
2109
2100
    def _set_repository_format(self, value):
2110
2101
        """Allow changing the repository format for metadir formats."""
2258
2249
            mode=self.bzrdir._get_file_mode())
2259
2250
 
2260
2251
    def _write_all_weaves(self):
2261
 
        controlweaves = VersionedFileStore(self.bzrdir.transport, prefixed=False,
2262
 
                                           versionedfile_class=WeaveFile)
 
2252
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
2263
2253
        weave_transport = self.bzrdir.transport.clone('weaves')
2264
 
        weaves = VersionedFileStore(weave_transport, prefixed=False,
2265
 
                            versionedfile_class=WeaveFile)
 
2254
        weaves = WeaveStore(weave_transport, prefixed=False)
2266
2255
        transaction = WriteTransaction()
2267
2256
 
2268
2257
        try:
3265
3254
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3266
3255
    )
3267
3256
# The following un-numbered 'development' formats should always just be aliases.
 
3257
register_metadir(controldir.format_registry, 'development-rich-root',
 
3258
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3259
    help='Current development format. Supports rich roots. Can convert data '
 
3260
        'to and from rich-root-pack (and anything compatible with '
 
3261
        'rich-root-pack) format repositories. Repositories and branches in '
 
3262
        'this format can only be read by bzr.dev. Please read '
 
3263
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3264
        'before use.',
 
3265
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3266
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3267
    experimental=True,
 
3268
    alias=True,
 
3269
    hidden=True,
 
3270
    )
 
3271
register_metadir(controldir.format_registry, 'development5-subtree',
 
3272
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
3273
    help='Development format, subtree variant. Can convert data to and '
 
3274
        'from pack-0.92-subtree (and anything compatible with '
 
3275
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
3276
        'this format can only be read by bzr.dev. Please read '
 
3277
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3278
        'before use.',
 
3279
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3280
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3281
    experimental=True,
 
3282
    hidden=True,
 
3283
    alias=False,
 
3284
    )
 
3285
 
 
3286
 
3268
3287
register_metadir(controldir.format_registry, 'development-subtree',
3269
3288
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3270
3289
    help='Current development format, subtree variant. Can convert data to and '
3281
3300
                 # This current non-alias status is simply because we did not introduce a
3282
3301
                 # chk based subtree format.
3283
3302
    )
3284
 
register_metadir(controldir.format_registry, 'development5-subtree',
3285
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3286
 
    help='Development format, subtree variant. Can convert data to and '
3287
 
        'from pack-0.92-subtree (and anything compatible with '
3288
 
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3289
 
        'this format can only be read by bzr.dev. Please read '
3290
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3291
 
        'before use.',
3292
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3293
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3294
 
    experimental=True,
3295
 
    hidden=True,
3296
 
    alias=False,
3297
 
    )
3298
3303
 
3299
3304
# And the development formats above will have aliased one of the following:
3300
 
 
3301
 
# Finally, the current format.
 
3305
register_metadir(controldir.format_registry, 'development6-rich-root',
 
3306
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3307
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
 
3308
        'Please read '
 
3309
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3310
        'before use.',
 
3311
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3312
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3313
    hidden=True,
 
3314
    experimental=True,
 
3315
    )
 
3316
 
 
3317
register_metadir(controldir.format_registry, 'development7-rich-root',
 
3318
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
 
3319
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
 
3320
        'rich roots. Please read '
 
3321
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3322
        'before use.',
 
3323
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3324
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3325
    hidden=True,
 
3326
    experimental=True,
 
3327
    )
 
3328
 
3302
3329
register_metadir(controldir.format_registry, '2a',
3303
3330
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3304
3331
    help='First format for bzr 2.0 series.\n'