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)
203
205
# TODO: Make sure no commands unconditionally use the working directory as a
557
559
takes_args = ['location?']
558
560
takes_options = [
559
561
Option('tree', help='Show revno of working tree'),
563
def run(self, tree=False, location=u'.'):
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"))
566
573
wt = WorkingTree.open_containing(location)[0]
567
574
self.add_cleanup(wt.lock_read().unlock)
568
575
except (errors.NoWorkingTree, errors.NotLocalUrl):
569
576
raise errors.NoWorkingTree(location)
570
578
revid = wt.last_revision()
572
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
except errors.NoSuchRevision:
575
revno = ".".join(str(n) for n in revno_t)
577
580
b = Branch.open_containing(location)[0]
578
581
self.add_cleanup(b.lock_read().unlock)
583
if len(revision) != 1:
584
raise errors.BzrCommandError(gettext(
585
"Tags can only be placed on a single revision, "
587
revid = revision[0].as_revision_id(b)
589
revid = b.last_revision()
591
revno_t = b.revision_id_to_dotted_revno(revid)
592
except errors.NoSuchRevision:
594
revno = ".".join(str(n) for n in revno_t)
580
595
self.cleanup_now()
581
self.outf.write(str(revno) + '\n')
596
self.outf.write(revno + '\n')
584
599
class cmd_revision_info(Command):
868
884
if len(names_list) < 2:
869
885
raise errors.BzrCommandError(gettext("missing file argument"))
870
886
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
887
for file_name in rel_names[0:-1]:
889
raise errors.BzrCommandError(gettext("can not move root of branch"))
871
890
self.add_cleanup(tree.lock_tree_write().unlock)
872
891
self._run(tree, names_list, rel_names, after)
985
1004
location to use the default. To change the default, use --remember. The
986
1005
value will only be saved if the remote location can be accessed.
1007
The --verbose option will display the revisions pulled using the log_format
1008
configuration option. You can use a different format by overriding it with
1009
-Olog_format=<other_format>.
988
1011
Note: The location can be specified either in the form of a branch,
989
1012
or in the form of a path to a file containing a merge directive generated
1120
1143
--no-remember to avoid setting it). After that, you can omit the
1121
1144
location to use the default. To change the default, use --remember. The
1122
1145
value will only be saved if the remote location can be accessed.
1147
The --verbose option will display the revisions pushed using the log_format
1148
configuration option. You can use a different format by overriding it with
1149
-Olog_format=<other_format>.
1125
1152
_see_also = ['pull', 'update', 'working-trees']
1266
1293
deprecated_name=self.invoked_as,
1267
1294
recommended_name='branch',
1268
1295
deprecated_in_version='2.4')
1269
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1296
accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1271
1298
if not (hardlink or files_from):
1272
1299
# accelerator_tree is usually slower because you have to read N
1295
1322
'already exists.') % to_location)
1298
bzrdir.BzrDir.open_from_transport(to_transport)
1325
to_dir = controldir.ControlDir.open_from_transport(
1299
1327
except errors.NotBranchError:
1302
raise errors.AlreadyBranchError(to_location)
1331
to_dir.open_branch()
1332
except errors.NotBranchError:
1335
raise errors.AlreadyBranchError(to_location)
1303
1336
except errors.NoSuchFile:
1304
1337
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
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)
1343
# preserve whatever source format we have.
1344
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1345
possible_transports=[to_transport],
1346
accelerator_tree=accelerator_tree,
1347
hardlink=hardlink, stacked=stacked,
1348
force_new_repo=standalone,
1349
create_tree_if_local=not no_tree,
1350
source_branch=br_from)
1351
branch = to_dir.open_branch()
1352
except errors.NoSuchRevision:
1353
to_transport.delete_tree('.')
1354
msg = gettext("The branch {0} has no revision {1}.").format(
1355
from_location, revision)
1356
raise errors.BzrCommandError(msg)
1358
branch = br_from.sprout(to_dir, revision_id=revision_id)
1321
1359
_merge_tags_if_possible(br_from, branch)
1322
1360
# If the source branch is stacked, the new branch may
1323
1361
# be stacked whether we asked for that explicitly or not.
1360
1398
if not t.listable():
1361
1399
raise errors.BzrCommandError(
1362
1400
"Can't scan this type of location.")
1363
for b in bzrdir.BzrDir.find_branches(t):
1401
for b in controldir.ControlDir.find_branches(t):
1364
1402
self.outf.write("%s\n" % urlutils.unescape_for_display(
1365
1403
urlutils.relative_url(t.base, b.base),
1366
1404
self.outf.encoding).rstrip("/"))
1368
dir = bzrdir.BzrDir.open_containing(location)[0]
1406
dir = controldir.ControlDir.open_containing(location)[0]
1369
1407
for branch in dir.list_branches():
1370
1408
if branch.name is None:
1371
1409
self.outf.write(gettext(" (default)\n"))
1418
1456
if branch_location is None:
1419
1457
branch_location = osutils.getcwd()
1420
1458
to_location = branch_location
1421
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1459
accelerator_tree, source = controldir.ControlDir.open_tree_or_branch(
1422
1460
branch_location)
1423
1461
if not (hardlink or files_from):
1424
1462
# accelerator_tree is usually slower because you have to read N
1481
1519
class cmd_update(Command):
1482
__doc__ = """Update a tree to have the latest code committed to its branch.
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.
1488
If you want to discard your local changes, you can just do a
1489
'bzr revert' instead of 'bzr commit' after the update.
1491
If you want to restore a file that has been removed locally, use
1492
'bzr revert' instead of 'bzr update'.
1494
If the tree's branch is bound to a master branch, it will also update
1520
__doc__ = """Update a working tree to a new revision.
1522
This will perform a merge of the destination revision (the tip of the
1523
branch, or the specified revision) into the working tree, and then make
1524
that revision the basis revision for the working tree.
1526
You can use this to visit an older revision, or to update a working tree
1527
that is out of date from its branch.
1529
If there are any uncommitted changes in the tree, they will be carried
1530
across and remain as uncommitted changes after the update. To discard
1531
these changes, use 'bzr revert'. The uncommitted changes may conflict
1532
with the changes brought in by the change in basis revision.
1534
If the tree's branch is bound to a master branch, bzr will also update
1495
1535
the branch from the master.
1537
You cannot update just a single file or directory, because each Bazaar
1538
working tree has just a single basis revision. If you want to restore a
1539
file that has been removed locally, use 'bzr revert' instead of 'bzr
1540
update'. If you want to restore a file to its state in a previous
1541
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1542
out the old content of that file to a new location.
1544
The 'dir' argument, if given, must be the location of the root of a
1545
working tree to update. By default, the working tree that contains the
1546
current working directory is used.
1498
1549
_see_also = ['pull', 'working-trees', 'status-flags']
1504
1555
aliases = ['up']
1506
def run(self, dir='.', revision=None, show_base=None):
1557
def run(self, dir=None, revision=None, show_base=None):
1507
1558
if revision is not None and len(revision) != 1:
1508
1559
raise errors.BzrCommandError(gettext(
1509
"bzr update --revision takes exactly one revision"))
1510
tree = WorkingTree.open_containing(dir)[0]
1560
"bzr update --revision takes exactly one revision"))
1562
tree = WorkingTree.open_containing('.')[0]
1564
tree, relpath = WorkingTree.open_containing(dir)
1567
raise errors.BzrCommandError(gettext(
1568
"bzr update can only update a whole tree, "
1569
"not a file or subdirectory"))
1511
1570
branch = tree.branch
1512
1571
possible_transports = []
1513
1572
master = branch.get_master_branch(
1750
1809
def run(self, branch=".", canonicalize_chks=False):
1751
1810
from bzrlib.reconcile import reconcile
1752
dir = bzrdir.BzrDir.open(branch)
1811
dir = controldir.ControlDir.open(branch)
1753
1812
reconcile(dir, canonicalize_chks=canonicalize_chks)
1764
1823
@display_command
1765
1824
def run(self, location="."):
1766
1825
branch = Branch.open_containing(location)[0]
1767
for revid in branch.revision_history():
1826
self.add_cleanup(branch.lock_read().unlock)
1827
graph = branch.repository.get_graph()
1828
history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
1829
[_mod_revision.NULL_REVISION]))
1830
for revid in reversed(history):
1768
1831
self.outf.write(revid)
1769
1832
self.outf.write('\n')
1831
1894
help='Specify a format for this branch. '
1832
1895
'See "help formats".',
1833
1896
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1834
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1897
converter=lambda name: controldir.format_registry.make_bzrdir(name),
1835
1898
value_switches=True,
1836
1899
title="Branch format",
1844
1907
def run(self, location=None, format=None, append_revisions_only=False,
1845
1908
create_prefix=False, no_tree=False):
1846
1909
if format is None:
1847
format = bzrdir.format_registry.make_bzrdir('default')
1910
format = controldir.format_registry.make_bzrdir('default')
1848
1911
if location is None:
1849
1912
location = u'.'
1867
1930
to_transport.create_prefix()
1870
a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1933
a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
1871
1934
except errors.NotBranchError:
1872
1935
# really a NotBzrDir error...
1873
create_branch = bzrdir.BzrDir.create_branch_convenience
1936
create_branch = controldir.ControlDir.create_branch_convenience
1875
1938
force_new_tree = False
1887
1950
raise errors.BranchExistsWithoutWorkingTree(location)
1888
1951
raise errors.AlreadyBranchError(location)
1889
1952
branch = a_bzrdir.create_branch()
1953
if not no_tree and not a_bzrdir.has_workingtree():
1891
1954
a_bzrdir.create_workingtree()
1892
1955
if append_revisions_only:
1949
2012
takes_options = [RegistryOption('format',
1950
2013
help='Specify a format for this repository. See'
1951
2014
' "bzr help formats" for details.',
1952
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1953
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
2015
lazy_registry=('bzrlib.controldir', 'format_registry'),
2016
converter=lambda name: controldir.format_registry.make_bzrdir(name),
1954
2017
value_switches=True, title='Repository format'),
1955
2018
Option('no-trees',
1956
2019
help='Branches in the repository will default to'
2571
2634
location = revision[0].get_branch()
2574
dir, relpath = bzrdir.BzrDir.open_containing(location)
2637
dir, relpath = controldir.ControlDir.open_containing(location)
2575
2638
b = dir.open_branch()
2576
2639
self.add_cleanup(b.lock_read().unlock)
2577
2640
rev1, rev2 = _get_revision_range(revision, b, self.name())
3560
3623
RegistryOption('format',
3561
3624
help='Upgrade to a specific format. See "bzr help'
3562
3625
' formats" for details.',
3563
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3564
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3626
lazy_registry=('bzrlib.controldir', 'format_registry'),
3627
converter=lambda name: controldir.format_registry.make_bzrdir(name),
3565
3628
value_switches=True, title='Branch format'),
3566
3629
Option('clean',
3567
3630
help='Remove the backup.bzr directory if successful.'),
4814
4877
def run(self, branch_or_repo='.', clean_obsolete_packs=False):
4815
dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
4878
dir = controldir.ControlDir.open_containing(branch_or_repo)[0]
4817
4880
branch = dir.open_branch()
4818
4881
repository = branch.repository
5095
5158
revision=None, force=False, local=False, keep_tags=False):
5096
5159
if location is None:
5097
5160
location = u'.'
5098
control, relpath = bzrdir.BzrDir.open_containing(location)
5161
control, relpath = controldir.ControlDir.open_containing(location)
5100
5163
tree = control.open_workingtree()
5101
5164
b = tree.branch
5255
5318
'option leads to global uncontrolled write access to your '
5321
Option('client-timeout', type=float,
5322
help='Override the default idle client timeout (5min).'),
5260
5325
def get_host_and_port(self, port):
5288
5353
if not allow_writes:
5289
5354
url = 'readonly+' + url
5290
5355
t = transport.get_transport(url)
5291
protocol(t, host, port, inet)
5357
protocol(t, host, port, inet, client_timeout)
5358
except TypeError, e:
5359
# We use symbol_versioning.deprecated_in just so that people
5360
# grepping can find it here.
5361
# symbol_versioning.deprecated_in((2, 5, 0))
5362
symbol_versioning.warn(
5363
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5364
'Most likely it needs to be updated to support a'
5365
' "timeout" parameter (added in bzr 2.5.0)'
5366
% (e, protocol.__module__, protocol),
5368
protocol(t, host, port, inet)
5294
5371
class cmd_join(Command):
5781
5858
if isinstance(revno, tuple):
5782
5859
revno = '.'.join(map(str, revno))
5783
5860
except (errors.NoSuchRevision,
5784
errors.GhostRevisionsHaveNoRevno):
5861
errors.GhostRevisionsHaveNoRevno,
5862
errors.UnsupportedOperation):
5785
5863
# Bad tag data/merges can lead to tagged revisions
5786
5864
# which are not in this branch. Fail gracefully ...
5881
5959
def run(self, location=None, bind_to=None, force=False,
5882
5960
tree_type=None, repository_type=None, repository_trees=None,
5883
5961
stacked_on=None, unstacked=None):
5884
directory = bzrdir.BzrDir.open(location)
5962
directory = controldir.ControlDir.open(location)
5885
5963
if stacked_on and unstacked:
5886
5964
raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5887
5965
elif stacked_on is not None:
5969
6047
from bzrlib import switch
5970
6048
tree_location = directory
5971
6049
revision = _get_one_revision('switch', revision)
5972
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
6050
control_dir = controldir.ControlDir.open_containing(tree_location)[0]
5973
6051
if to_location is None:
5974
6052
if revision is None:
5975
6053
raise errors.BzrCommandError(gettext('You must supply either a'
6436
6514
__doc__ = """Export command helps and error messages in po format."""
6517
takes_options = [Option('plugin',
6518
help='Export help text from named command '\
6519
'(defaults to all built in commands).',
6522
def run(self, plugin=None):
6441
6523
from bzrlib.export_pot import export_pot
6442
export_pot(self.outf)
6524
export_pot(self.outf, plugin)
6445
6527
def _register_lazy_builtins():