~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-27 11:48:50 UTC
  • mto: This revision was merged to the branch mainline in revision 6173.
  • Revision ID: v.ladeuil+lp@free.fr-20110927114850-338r2mns0138klv0
Global options respect their hidden attribute

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
 
 
23
21
from bzrlib.lazy_import import lazy_import
24
22
lazy_import(globals(), """
25
23
import cStringIO
31
29
    bugtracker,
32
30
    bundle,
33
31
    btree_index,
34
 
    controldir,
 
32
    bzrdir,
35
33
    directory_service,
36
34
    delta,
37
35
    config as _mod_config,
199
197
    the --directory option is used to specify a different branch."""
200
198
    if directory is not None:
201
199
        return (None, Branch.open(directory), filename)
202
 
    return controldir.ControlDir.open_containing_tree_or_branch(filename)
 
200
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
203
201
 
204
202
 
205
203
# TODO: Make sure no commands unconditionally use the working directory as a
341
339
            raise errors.BzrCommandError(gettext('You must supply either'
342
340
                                         ' --revision or a revision_id'))
343
341
 
344
 
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
 
342
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
345
343
 
346
344
        revisions = b.repository.revisions
347
345
        if revisions is None:
475
473
            location_list=['.']
476
474
 
477
475
        for location in location_list:
478
 
            d = controldir.ControlDir.open(location)
479
 
 
 
476
            d = bzrdir.BzrDir.open(location)
 
477
            
480
478
            try:
481
479
                working = d.open_workingtree()
482
480
            except errors.NoWorkingTree:
559
557
    takes_args = ['location?']
560
558
    takes_options = [
561
559
        Option('tree', help='Show revno of working tree'),
562
 
        'revision',
563
560
        ]
564
561
 
565
562
    @display_command
566
 
    def run(self, tree=False, location=u'.', revision=None):
567
 
        if revision is not None and tree:
568
 
            raise errors.BzrCommandError(gettext("--tree and --revision can "
569
 
                "not be used together"))
570
 
 
 
563
    def run(self, tree=False, location=u'.'):
571
564
        if tree:
572
565
            try:
573
566
                wt = WorkingTree.open_containing(location)[0]
574
567
                self.add_cleanup(wt.lock_read().unlock)
575
568
            except (errors.NoWorkingTree, errors.NotLocalUrl):
576
569
                raise errors.NoWorkingTree(location)
577
 
            b = wt.branch
578
570
            revid = wt.last_revision()
 
571
            try:
 
572
                revno_t = wt.branch.revision_id_to_dotted_revno(revid)
 
573
            except errors.NoSuchRevision:
 
574
                revno_t = ('???',)
 
575
            revno = ".".join(str(n) for n in revno_t)
579
576
        else:
580
577
            b = Branch.open_containing(location)[0]
581
578
            self.add_cleanup(b.lock_read().unlock)
582
 
            if revision:
583
 
                if len(revision) != 1:
584
 
                    raise errors.BzrCommandError(gettext(
585
 
                        "Tags can only be placed on a single revision, "
586
 
                        "not on a range"))
587
 
                revid = revision[0].as_revision_id(b)
588
 
            else:
589
 
                revid = b.last_revision()
590
 
        try:
591
 
            revno_t = b.revision_id_to_dotted_revno(revid)
592
 
        except errors.NoSuchRevision:
593
 
            revno_t = ('???',)
594
 
        revno = ".".join(str(n) for n in revno_t)
 
579
            revno = b.revno()
595
580
        self.cleanup_now()
596
 
        self.outf.write(revno + '\n')
 
581
        self.outf.write(str(revno) + '\n')
597
582
 
598
583
 
599
584
class cmd_revision_info(Command):
763
748
            if id != None:
764
749
                os.mkdir(d)
765
750
                wt.add([dd])
766
 
                if not is_quiet():
767
 
                    self.outf.write(gettext('added %s\n') % d)
 
751
                self.outf.write(gettext('added %s\n') % d)
768
752
            else:
769
753
                raise errors.NotVersionedError(path=base)
770
754
 
1001
985
    location to use the default.  To change the default, use --remember. The
1002
986
    value will only be saved if the remote location can be accessed.
1003
987
 
1004
 
    The --verbose option will display the revisions pulled using the log_format
1005
 
    configuration option. You can use a different format by overriding it with
1006
 
    -Olog_format=<other_format>.
1007
 
 
1008
988
    Note: The location can be specified either in the form of a branch,
1009
989
    or in the form of a path to a file containing a merge directive generated
1010
990
    with bzr send.
1140
1120
    --no-remember to avoid setting it).  After that, you can omit the
1141
1121
    location to use the default.  To change the default, use --remember. The
1142
1122
    value will only be saved if the remote location can be accessed.
1143
 
 
1144
 
    The --verbose option will display the revisions pushed using the log_format
1145
 
    configuration option. You can use a different format by overriding it with
1146
 
    -Olog_format=<other_format>.
1147
1123
    """
1148
1124
 
1149
1125
    _see_also = ['pull', 'update', 'working-trees']
1187
1163
            directory = '.'
1188
1164
        # Get the source branch
1189
1165
        (tree, br_from,
1190
 
         _unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
 
1166
         _unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1191
1167
        # Get the tip's revision_id
1192
1168
        revision = _get_one_revision('push', revision)
1193
1169
        if revision is not None:
1290
1266
                deprecated_name=self.invoked_as,
1291
1267
                recommended_name='branch',
1292
1268
                deprecated_in_version='2.4')
1293
 
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
 
1269
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1294
1270
            from_location)
1295
1271
        if not (hardlink or files_from):
1296
1272
            # accelerator_tree is usually slower because you have to read N
1319
1295
                    'already exists.') % to_location)
1320
1296
            else:
1321
1297
                try:
1322
 
                    to_dir = controldir.ControlDir.open_from_transport(
1323
 
                        to_transport)
 
1298
                    bzrdir.BzrDir.open_from_transport(to_transport)
1324
1299
                except errors.NotBranchError:
1325
 
                    to_dir = None
 
1300
                    pass
1326
1301
                else:
1327
 
                    try:
1328
 
                        to_dir.open_branch()
1329
 
                    except errors.NotBranchError:
1330
 
                        pass
1331
 
                    else:
1332
 
                        raise errors.AlreadyBranchError(to_location)
 
1302
                    raise errors.AlreadyBranchError(to_location)
1333
1303
        except errors.NoSuchFile:
1334
1304
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1335
1305
                                         % to_location)
1336
 
        else:
1337
 
            to_dir = None
1338
 
        if to_dir is None:
1339
 
            try:
1340
 
                # preserve whatever source format we have.
1341
 
                to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1342
 
                                            possible_transports=[to_transport],
1343
 
                                            accelerator_tree=accelerator_tree,
1344
 
                                            hardlink=hardlink, stacked=stacked,
1345
 
                                            force_new_repo=standalone,
1346
 
                                            create_tree_if_local=not no_tree,
1347
 
                                            source_branch=br_from)
1348
 
                branch = to_dir.open_branch()
1349
 
            except errors.NoSuchRevision:
1350
 
                to_transport.delete_tree('.')
1351
 
                msg = gettext("The branch {0} has no revision {1}.").format(
1352
 
                    from_location, revision)
1353
 
                raise errors.BzrCommandError(msg)
1354
 
        else:
1355
 
            branch = br_from.sprout(to_dir, revision_id=revision_id)
 
1306
        try:
 
1307
            # preserve whatever source format we have.
 
1308
            dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
 
1309
                                        possible_transports=[to_transport],
 
1310
                                        accelerator_tree=accelerator_tree,
 
1311
                                        hardlink=hardlink, stacked=stacked,
 
1312
                                        force_new_repo=standalone,
 
1313
                                        create_tree_if_local=not no_tree,
 
1314
                                        source_branch=br_from)
 
1315
            branch = dir.open_branch()
 
1316
        except errors.NoSuchRevision:
 
1317
            to_transport.delete_tree('.')
 
1318
            msg = gettext("The branch {0} has no revision {1}.").format(
 
1319
                from_location, revision)
 
1320
            raise errors.BzrCommandError(msg)
1356
1321
        _merge_tags_if_possible(br_from, branch)
1357
1322
        # If the source branch is stacked, the new branch may
1358
1323
        # be stacked whether we asked for that explicitly or not.
1395
1360
            if not t.listable():
1396
1361
                raise errors.BzrCommandError(
1397
1362
                    "Can't scan this type of location.")
1398
 
            for b in controldir.ControlDir.find_branches(t):
 
1363
            for b in bzrdir.BzrDir.find_branches(t):
1399
1364
                self.outf.write("%s\n" % urlutils.unescape_for_display(
1400
1365
                    urlutils.relative_url(t.base, b.base),
1401
1366
                    self.outf.encoding).rstrip("/"))
1402
1367
        else:
1403
 
            dir = controldir.ControlDir.open_containing(location)[0]
 
1368
            dir = bzrdir.BzrDir.open_containing(location)[0]
1404
1369
            for branch in dir.list_branches():
1405
1370
                if branch.name is None:
1406
1371
                    self.outf.write(gettext(" (default)\n"))
1453
1418
        if branch_location is None:
1454
1419
            branch_location = osutils.getcwd()
1455
1420
            to_location = branch_location
1456
 
        accelerator_tree, source = controldir.ControlDir.open_tree_or_branch(
 
1421
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1457
1422
            branch_location)
1458
1423
        if not (hardlink or files_from):
1459
1424
            # accelerator_tree is usually slower because you have to read N
1514
1479
 
1515
1480
 
1516
1481
class cmd_update(Command):
1517
 
    __doc__ = """Update a working tree to a new revision.
1518
 
 
1519
 
    This will perform a merge of the destination revision (the tip of the
1520
 
    branch, or the specified revision) into the working tree, and then make
1521
 
    that revision the basis revision for the working tree.  
1522
 
 
1523
 
    You can use this to visit an older revision, or to update a working tree
1524
 
    that is out of date from its branch.
1525
 
    
1526
 
    If there are any uncommitted changes in the tree, they will be carried
1527
 
    across and remain as uncommitted changes after the update.  To discard
1528
 
    these changes, use 'bzr revert'.  The uncommitted changes may conflict
1529
 
    with the changes brought in by the change in basis revision.
1530
 
 
1531
 
    If the tree's branch is bound to a master branch, bzr will also update
 
1482
    __doc__ = """Update a tree to have the latest code committed to its branch.
 
1483
 
 
1484
    This will perform a merge into the working tree, and may generate
 
1485
    conflicts. If you have any local changes, you will still
 
1486
    need to commit them after the update for the update to be complete.
 
1487
 
 
1488
    If you want to discard your local changes, you can just do a
 
1489
    'bzr revert' instead of 'bzr commit' after the update.
 
1490
 
 
1491
    If you want to restore a file that has been removed locally, use
 
1492
    'bzr revert' instead of 'bzr update'.
 
1493
 
 
1494
    If the tree's branch is bound to a master branch, it will also update
1532
1495
    the branch from the master.
1533
 
 
1534
 
    You cannot update just a single file or directory, because each Bazaar
1535
 
    working tree has just a single basis revision.  If you want to restore a
1536
 
    file that has been removed locally, use 'bzr revert' instead of 'bzr
1537
 
    update'.  If you want to restore a file to its state in a previous
1538
 
    revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1539
 
    out the old content of that file to a new location.
1540
 
 
1541
 
    The 'dir' argument, if given, must be the location of the root of a
1542
 
    working tree to update.  By default, the working tree that contains the 
1543
 
    current working directory is used.
1544
1496
    """
1545
1497
 
1546
1498
    _see_also = ['pull', 'working-trees', 'status-flags']
1551
1503
                     ]
1552
1504
    aliases = ['up']
1553
1505
 
1554
 
    def run(self, dir=None, revision=None, show_base=None):
 
1506
    def run(self, dir='.', revision=None, show_base=None):
1555
1507
        if revision is not None and len(revision) != 1:
1556
1508
            raise errors.BzrCommandError(gettext(
1557
 
                "bzr update --revision takes exactly one revision"))
1558
 
        if dir is None:
1559
 
            tree = WorkingTree.open_containing('.')[0]
1560
 
        else:
1561
 
            tree, relpath = WorkingTree.open_containing(dir)
1562
 
            if relpath:
1563
 
                # See bug 557886.
1564
 
                raise errors.BzrCommandError(gettext(
1565
 
                    "bzr update can only update a whole tree, "
1566
 
                    "not a file or subdirectory"))
 
1509
                        "bzr update --revision takes exactly one revision"))
 
1510
        tree = WorkingTree.open_containing(dir)[0]
1567
1511
        branch = tree.branch
1568
1512
        possible_transports = []
1569
1513
        master = branch.get_master_branch(
1667
1611
        else:
1668
1612
            noise_level = 0
1669
1613
        from bzrlib.info import show_bzrdir_info
1670
 
        show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
 
1614
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1671
1615
                         verbose=noise_level, outfile=self.outf)
1672
1616
 
1673
1617
 
1805
1749
 
1806
1750
    def run(self, branch=".", canonicalize_chks=False):
1807
1751
        from bzrlib.reconcile import reconcile
1808
 
        dir = controldir.ControlDir.open(branch)
 
1752
        dir = bzrdir.BzrDir.open(branch)
1809
1753
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1810
1754
 
1811
1755
 
1820
1764
    @display_command
1821
1765
    def run(self, location="."):
1822
1766
        branch = Branch.open_containing(location)[0]
1823
 
        self.add_cleanup(branch.lock_read().unlock)
1824
 
        graph = branch.repository.get_graph()
1825
 
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
1826
 
            [_mod_revision.NULL_REVISION]))
1827
 
        for revid in reversed(history):
 
1767
        for revid in branch.revision_history():
1828
1768
            self.outf.write(revid)
1829
1769
            self.outf.write('\n')
1830
1770
 
1891
1831
                help='Specify a format for this branch. '
1892
1832
                'See "help formats".',
1893
1833
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1894
 
                converter=lambda name: controldir.format_registry.make_bzrdir(name),
 
1834
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1895
1835
                value_switches=True,
1896
1836
                title="Branch format",
1897
1837
                ),
1904
1844
    def run(self, location=None, format=None, append_revisions_only=False,
1905
1845
            create_prefix=False, no_tree=False):
1906
1846
        if format is None:
1907
 
            format = controldir.format_registry.make_bzrdir('default')
 
1847
            format = bzrdir.format_registry.make_bzrdir('default')
1908
1848
        if location is None:
1909
1849
            location = u'.'
1910
1850
 
1927
1867
            to_transport.create_prefix()
1928
1868
 
1929
1869
        try:
1930
 
            a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
 
1870
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1931
1871
        except errors.NotBranchError:
1932
1872
            # really a NotBzrDir error...
1933
 
            create_branch = controldir.ControlDir.create_branch_convenience
 
1873
            create_branch = bzrdir.BzrDir.create_branch_convenience
1934
1874
            if no_tree:
1935
1875
                force_new_tree = False
1936
1876
            else:
1947
1887
                        raise errors.BranchExistsWithoutWorkingTree(location)
1948
1888
                raise errors.AlreadyBranchError(location)
1949
1889
            branch = a_bzrdir.create_branch()
1950
 
            if not no_tree and not a_bzrdir.has_workingtree():
 
1890
            if not no_tree:
1951
1891
                a_bzrdir.create_workingtree()
1952
1892
        if append_revisions_only:
1953
1893
            try:
2009
1949
    takes_options = [RegistryOption('format',
2010
1950
                            help='Specify a format for this repository. See'
2011
1951
                                 ' "bzr help formats" for details.',
2012
 
                            lazy_registry=('bzrlib.controldir', 'format_registry'),
2013
 
                            converter=lambda name: controldir.format_registry.make_bzrdir(name),
 
1952
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
1953
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
2014
1954
                            value_switches=True, title='Repository format'),
2015
1955
                     Option('no-trees',
2016
1956
                             help='Branches in the repository will default to'
2020
1960
 
2021
1961
    def run(self, location, format=None, no_trees=False):
2022
1962
        if format is None:
2023
 
            format = controldir.format_registry.make_bzrdir('default')
 
1963
            format = bzrdir.format_registry.make_bzrdir('default')
2024
1964
 
2025
1965
        if location is None:
2026
1966
            location = '.'
2631
2571
                location = revision[0].get_branch()
2632
2572
            else:
2633
2573
                location = '.'
2634
 
            dir, relpath = controldir.ControlDir.open_containing(location)
 
2574
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2635
2575
            b = dir.open_branch()
2636
2576
            self.add_cleanup(b.lock_read().unlock)
2637
2577
            rev1, rev2 = _get_revision_range(revision, b, self.name())
3620
3560
        RegistryOption('format',
3621
3561
            help='Upgrade to a specific format.  See "bzr help'
3622
3562
                 ' formats" for details.',
3623
 
            lazy_registry=('bzrlib.controldir', 'format_registry'),
3624
 
            converter=lambda name: controldir.format_registry.make_bzrdir(name),
 
3563
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3564
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3625
3565
            value_switches=True, title='Branch format'),
3626
3566
        Option('clean',
3627
3567
            help='Remove the backup.bzr directory if successful.'),
4872
4812
        ]
4873
4813
 
4874
4814
    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
4875
 
        dir = controldir.ControlDir.open_containing(branch_or_repo)[0]
 
4815
        dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
4876
4816
        try:
4877
4817
            branch = dir.open_branch()
4878
4818
            repository = branch.repository
5155
5095
            revision=None, force=False, local=False, keep_tags=False):
5156
5096
        if location is None:
5157
5097
            location = u'.'
5158
 
        control, relpath = controldir.ControlDir.open_containing(location)
 
5098
        control, relpath = bzrdir.BzrDir.open_containing(location)
5159
5099
        try:
5160
5100
            tree = control.open_workingtree()
5161
5101
            b = tree.branch
5265
5205
            conf = _mod_config.LockableConfig(file_name=location)
5266
5206
            conf.break_lock()
5267
5207
        else:
5268
 
            control, relpath = controldir.ControlDir.open_containing(location)
 
5208
            control, relpath = bzrdir.BzrDir.open_containing(location)
5269
5209
            try:
5270
5210
                control.break_lock()
5271
5211
            except NotImplementedError:
5855
5795
                    if isinstance(revno, tuple):
5856
5796
                        revno = '.'.join(map(str, revno))
5857
5797
                except (errors.NoSuchRevision,
5858
 
                        errors.GhostRevisionsHaveNoRevno,
5859
 
                        errors.UnsupportedOperation):
 
5798
                        errors.GhostRevisionsHaveNoRevno):
5860
5799
                    # Bad tag data/merges can lead to tagged revisions
5861
5800
                    # which are not in this branch. Fail gracefully ...
5862
5801
                    revno = '?'
5956
5895
    def run(self, location=None, bind_to=None, force=False,
5957
5896
            tree_type=None, repository_type=None, repository_trees=None,
5958
5897
            stacked_on=None, unstacked=None):
5959
 
        directory = controldir.ControlDir.open(location)
 
5898
        directory = bzrdir.BzrDir.open(location)
5960
5899
        if stacked_on and unstacked:
5961
5900
            raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5962
5901
        elif stacked_on is not None:
6044
5983
        from bzrlib import switch
6045
5984
        tree_location = directory
6046
5985
        revision = _get_one_revision('switch', revision)
6047
 
        control_dir = controldir.ControlDir.open_containing(tree_location)[0]
 
5986
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
6048
5987
        if to_location is None:
6049
5988
            if revision is None:
6050
5989
                raise errors.BzrCommandError(gettext('You must supply either a'
6477
6416
        if path is not None:
6478
6417
            branchdir = path
6479
6418
        tree, branch, relpath =(
6480
 
            controldir.ControlDir.open_containing_tree_or_branch(branchdir))
 
6419
            bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
6481
6420
        if path is not None:
6482
6421
            path = relpath
6483
6422
        if tree is None:
6511
6450
    __doc__ = """Export command helps and error messages in po format."""
6512
6451
 
6513
6452
    hidden = True
6514
 
    takes_options = [Option('plugin', 
6515
 
                            help='Export help text from named command '\
6516
 
                                 '(defaults to all built in commands).',
6517
 
                            type=str)]
6518
6453
 
6519
 
    def run(self, plugin=None):
 
6454
    def run(self):
6520
6455
        from bzrlib.export_pot import export_pot
6521
 
        export_pot(self.outf, plugin)
 
6456
        export_pot(self.outf)
6522
6457
 
6523
6458
 
6524
6459
def _register_lazy_builtins():