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)
205
203
# TODO: Make sure no commands unconditionally use the working directory as a
559
557
takes_args = ['location?']
560
558
takes_options = [
561
559
Option('tree', help='Show revno of working tree'),
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"))
563
def run(self, tree=False, location=u'.'):
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)
578
570
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)
580
577
b = Branch.open_containing(location)[0]
581
578
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)
595
580
self.cleanup_now()
596
self.outf.write(revno + '\n')
581
self.outf.write(str(revno) + '\n')
599
584
class cmd_revision_info(Command):
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.
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>.
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
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.
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>.
1149
1125
_see_also = ['pull', 'update', 'working-trees']
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(
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)
1322
to_dir = controldir.ControlDir.open_from_transport(
1298
bzrdir.BzrDir.open_from_transport(to_transport)
1324
1299
except errors.NotBranchError:
1328
to_dir.open_branch()
1329
except errors.NotBranchError:
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.')
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)
1355
branch = br_from.sprout(to_dir, revision_id=revision_id)
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("/"))
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
1516
1481
class cmd_update(Command):
1517
__doc__ = """Update a working tree to a new revision.
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.
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.
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.
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.
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
1532
1495
the branch from the master.
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.
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.
1546
1498
_see_also = ['pull', 'working-trees', 'status-flags']
1552
1504
aliases = ['up']
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"))
1559
tree = WorkingTree.open_containing('.')[0]
1561
tree, relpath = WorkingTree.open_containing(dir)
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(
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)
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')
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",
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'.'
1927
1867
to_transport.create_prefix()
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
1935
1875
force_new_tree = False
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():
1951
1891
a_bzrdir.create_workingtree()
1952
1892
if append_revisions_only:
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'
2631
2571
location = revision[0].get_branch()
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.'),
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]
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)
5160
5100
tree = control.open_workingtree()
5161
5101
b = tree.branch
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 ...
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'
6511
6450
__doc__ = """Export command helps and error messages in po format."""
6514
takes_options = [Option('plugin',
6515
help='Export help text from named command '\
6516
'(defaults to all built in commands).',
6519
def run(self, plugin=None):
6520
6455
from bzrlib.export_pot import export_pot
6521
export_pot(self.outf, plugin)
6456
export_pot(self.outf)
6524
6459
def _register_lazy_builtins():