~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 11:14:25 UTC
  • mfrom: (6207.3.11 use-controldir)
  • Revision ID: pqm@pqm.ubuntu.com-20111014111425-c7nzqujggvlsd9zz
(jelmer) Move static/class methods from BzrDir to ControlDir. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
 
21
import bzrlib.bzrdir
 
22
 
21
23
from bzrlib.lazy_import import lazy_import
22
24
lazy_import(globals(), """
23
25
import cStringIO
29
31
    bugtracker,
30
32
    bundle,
31
33
    btree_index,
32
 
    bzrdir,
 
34
    controldir,
33
35
    directory_service,
34
36
    delta,
35
37
    config as _mod_config,
197
199
    the --directory option is used to specify a different branch."""
198
200
    if directory is not None:
199
201
        return (None, Branch.open(directory), filename)
200
 
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
202
    return controldir.ControlDir.open_containing_tree_or_branch(filename)
201
203
 
202
204
 
203
205
# TODO: Make sure no commands unconditionally use the working directory as a
339
341
            raise errors.BzrCommandError(gettext('You must supply either'
340
342
                                         ' --revision or a revision_id'))
341
343
 
342
 
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
 
344
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
343
345
 
344
346
        revisions = b.repository.revisions
345
347
        if revisions is None:
473
475
            location_list=['.']
474
476
 
475
477
        for location in location_list:
476
 
            d = bzrdir.BzrDir.open(location)
477
 
            
 
478
            d = controldir.ControlDir.open(location)
 
479
 
478
480
            try:
479
481
                working = d.open_workingtree()
480
482
            except errors.NoWorkingTree:
1185
1187
            directory = '.'
1186
1188
        # Get the source branch
1187
1189
        (tree, br_from,
1188
 
         _unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
 
1190
         _unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
1189
1191
        # Get the tip's revision_id
1190
1192
        revision = _get_one_revision('push', revision)
1191
1193
        if revision is not None:
1288
1290
                deprecated_name=self.invoked_as,
1289
1291
                recommended_name='branch',
1290
1292
                deprecated_in_version='2.4')
1291
 
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
 
1293
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1292
1294
            from_location)
1293
1295
        if not (hardlink or files_from):
1294
1296
            # accelerator_tree is usually slower because you have to read N
1317
1319
                    'already exists.') % to_location)
1318
1320
            else:
1319
1321
                try:
1320
 
                    to_dir = bzrdir.BzrDir.open_from_transport(to_transport)
 
1322
                    to_dir = controldir.ControlDir.open_from_transport(
 
1323
                        to_transport)
1321
1324
                except errors.NotBranchError:
1322
1325
                    to_dir = None
1323
1326
                else:
1392
1395
            if not t.listable():
1393
1396
                raise errors.BzrCommandError(
1394
1397
                    "Can't scan this type of location.")
1395
 
            for b in bzrdir.BzrDir.find_branches(t):
 
1398
            for b in controldir.ControlDir.find_branches(t):
1396
1399
                self.outf.write("%s\n" % urlutils.unescape_for_display(
1397
1400
                    urlutils.relative_url(t.base, b.base),
1398
1401
                    self.outf.encoding).rstrip("/"))
1399
1402
        else:
1400
 
            dir = bzrdir.BzrDir.open_containing(location)[0]
 
1403
            dir = controldir.ControlDir.open_containing(location)[0]
1401
1404
            for branch in dir.list_branches():
1402
1405
                if branch.name is None:
1403
1406
                    self.outf.write(gettext(" (default)\n"))
1450
1453
        if branch_location is None:
1451
1454
            branch_location = osutils.getcwd()
1452
1455
            to_location = branch_location
1453
 
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
 
1456
        accelerator_tree, source = controldir.ControlDir.open_tree_or_branch(
1454
1457
            branch_location)
1455
1458
        if not (hardlink or files_from):
1456
1459
            # accelerator_tree is usually slower because you have to read N
1664
1667
        else:
1665
1668
            noise_level = 0
1666
1669
        from bzrlib.info import show_bzrdir_info
1667
 
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
 
1670
        show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
1668
1671
                         verbose=noise_level, outfile=self.outf)
1669
1672
 
1670
1673
 
1802
1805
 
1803
1806
    def run(self, branch=".", canonicalize_chks=False):
1804
1807
        from bzrlib.reconcile import reconcile
1805
 
        dir = bzrdir.BzrDir.open(branch)
 
1808
        dir = controldir.ControlDir.open(branch)
1806
1809
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1807
1810
 
1808
1811
 
1884
1887
                help='Specify a format for this branch. '
1885
1888
                'See "help formats".',
1886
1889
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1887
 
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
1890
                converter=lambda name: controldir.format_registry.make_bzrdir(name),
1888
1891
                value_switches=True,
1889
1892
                title="Branch format",
1890
1893
                ),
1897
1900
    def run(self, location=None, format=None, append_revisions_only=False,
1898
1901
            create_prefix=False, no_tree=False):
1899
1902
        if format is None:
1900
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
1903
            format = controldir.format_registry.make_bzrdir('default')
1901
1904
        if location is None:
1902
1905
            location = u'.'
1903
1906
 
1920
1923
            to_transport.create_prefix()
1921
1924
 
1922
1925
        try:
1923
 
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
 
1926
            a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
1924
1927
        except errors.NotBranchError:
1925
1928
            # really a NotBzrDir error...
1926
 
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1929
            create_branch = controldir.ControlDir.create_branch_convenience
1927
1930
            if no_tree:
1928
1931
                force_new_tree = False
1929
1932
            else:
2002
2005
    takes_options = [RegistryOption('format',
2003
2006
                            help='Specify a format for this repository. See'
2004
2007
                                 ' "bzr help formats" for details.',
2005
 
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
2006
 
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
2008
                            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
2009
                            converter=lambda name: controldir.format_registry.make_bzrdir(name),
2007
2010
                            value_switches=True, title='Repository format'),
2008
2011
                     Option('no-trees',
2009
2012
                             help='Branches in the repository will default to'
2013
2016
 
2014
2017
    def run(self, location, format=None, no_trees=False):
2015
2018
        if format is None:
2016
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
2019
            format = controldir.format_registry.make_bzrdir('default')
2017
2020
 
2018
2021
        if location is None:
2019
2022
            location = '.'
2624
2627
                location = revision[0].get_branch()
2625
2628
            else:
2626
2629
                location = '.'
2627
 
            dir, relpath = bzrdir.BzrDir.open_containing(location)
 
2630
            dir, relpath = controldir.ControlDir.open_containing(location)
2628
2631
            b = dir.open_branch()
2629
2632
            self.add_cleanup(b.lock_read().unlock)
2630
2633
            rev1, rev2 = _get_revision_range(revision, b, self.name())
3613
3616
        RegistryOption('format',
3614
3617
            help='Upgrade to a specific format.  See "bzr help'
3615
3618
                 ' formats" for details.',
3616
 
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3617
 
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3619
            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
3620
            converter=lambda name: controldir.format_registry.make_bzrdir(name),
3618
3621
            value_switches=True, title='Branch format'),
3619
3622
        Option('clean',
3620
3623
            help='Remove the backup.bzr directory if successful.'),
4865
4868
        ]
4866
4869
 
4867
4870
    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
4868
 
        dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
 
4871
        dir = controldir.ControlDir.open_containing(branch_or_repo)[0]
4869
4872
        try:
4870
4873
            branch = dir.open_branch()
4871
4874
            repository = branch.repository
5148
5151
            revision=None, force=False, local=False, keep_tags=False):
5149
5152
        if location is None:
5150
5153
            location = u'.'
5151
 
        control, relpath = bzrdir.BzrDir.open_containing(location)
 
5154
        control, relpath = controldir.ControlDir.open_containing(location)
5152
5155
        try:
5153
5156
            tree = control.open_workingtree()
5154
5157
            b = tree.branch
5258
5261
            conf = _mod_config.LockableConfig(file_name=location)
5259
5262
            conf.break_lock()
5260
5263
        else:
5261
 
            control, relpath = bzrdir.BzrDir.open_containing(location)
 
5264
            control, relpath = controldir.ControlDir.open_containing(location)
5262
5265
            try:
5263
5266
                control.break_lock()
5264
5267
            except NotImplementedError:
5949
5952
    def run(self, location=None, bind_to=None, force=False,
5950
5953
            tree_type=None, repository_type=None, repository_trees=None,
5951
5954
            stacked_on=None, unstacked=None):
5952
 
        directory = bzrdir.BzrDir.open(location)
 
5955
        directory = controldir.ControlDir.open(location)
5953
5956
        if stacked_on and unstacked:
5954
5957
            raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5955
5958
        elif stacked_on is not None:
6037
6040
        from bzrlib import switch
6038
6041
        tree_location = directory
6039
6042
        revision = _get_one_revision('switch', revision)
6040
 
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
 
6043
        control_dir = controldir.ControlDir.open_containing(tree_location)[0]
6041
6044
        if to_location is None:
6042
6045
            if revision is None:
6043
6046
                raise errors.BzrCommandError(gettext('You must supply either a'
6470
6473
        if path is not None:
6471
6474
            branchdir = path
6472
6475
        tree, branch, relpath =(
6473
 
            bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
 
6476
            controldir.ControlDir.open_containing_tree_or_branch(branchdir))
6474
6477
        if path is not None:
6475
6478
            path = relpath
6476
6479
        if tree is None: