239
362
' --revision or a revision_id')
240
363
b = WorkingTree.open_containing(u'.')[0].branch
242
# TODO: jam 20060112 should cat-revision always output utf-8?
243
if revision_id is not None:
244
revision_id = osutils.safe_revision_id(revision_id, warn=False)
365
revisions = b.repository.revisions
366
if revisions is None:
367
raise errors.BzrCommandError('Repository %r does not support '
368
'access to raw revision texts')
370
b.repository.lock_read()
372
# TODO: jam 20060112 should cat-revision always output utf-8?
373
if revision_id is not None:
374
revision_id = osutils.safe_revision_id(revision_id, warn=False)
376
self.print_revision(revisions, revision_id)
377
except errors.NoSuchRevision:
378
msg = "The repository %s contains no revision %s." % (
379
b.repository.base, revision_id)
380
raise errors.BzrCommandError(msg)
381
elif revision is not None:
384
raise errors.BzrCommandError(
385
'You cannot specify a NULL revision.')
386
rev_id = rev.as_revision_id(b)
387
self.print_revision(revisions, rev_id)
389
b.repository.unlock()
392
class cmd_dump_btree(Command):
393
"""Dump the contents of a btree index file to stdout.
395
PATH is a btree index file, it can be any URL. This includes things like
396
.bzr/repository/pack-names, or .bzr/repository/indices/a34b3a...ca4a4.iix
398
By default, the tuples stored in the index file will be displayed. With
399
--raw, we will uncompress the pages, but otherwise display the raw bytes
403
# TODO: Do we want to dump the internal nodes as well?
404
# TODO: It would be nice to be able to dump the un-parsed information,
405
# rather than only going through iter_all_entries. However, this is
406
# good enough for a start
408
encoding_type = 'exact'
409
takes_args = ['path']
410
takes_options = [Option('raw', help='Write the uncompressed bytes out,'
411
' rather than the parsed tuples.'),
414
def run(self, path, raw=False):
415
dirname, basename = osutils.split(path)
416
t = transport.get_transport(dirname)
418
self._dump_raw_bytes(t, basename)
420
self._dump_entries(t, basename)
422
def _get_index_and_bytes(self, trans, basename):
423
"""Create a BTreeGraphIndex and raw bytes."""
424
bt = btree_index.BTreeGraphIndex(trans, basename, None)
425
bytes = trans.get_bytes(basename)
426
bt._file = cStringIO.StringIO(bytes)
427
bt._size = len(bytes)
430
def _dump_raw_bytes(self, trans, basename):
433
# We need to parse at least the root node.
434
# This is because the first page of every row starts with an
435
# uncompressed header.
436
bt, bytes = self._get_index_and_bytes(trans, basename)
437
for page_idx, page_start in enumerate(xrange(0, len(bytes),
438
btree_index._PAGE_SIZE)):
439
page_end = min(page_start + btree_index._PAGE_SIZE, len(bytes))
440
page_bytes = bytes[page_start:page_end]
442
self.outf.write('Root node:\n')
443
header_end, data = bt._parse_header_from_bytes(page_bytes)
444
self.outf.write(page_bytes[:header_end])
446
self.outf.write('\nPage %d\n' % (page_idx,))
447
decomp_bytes = zlib.decompress(page_bytes)
448
self.outf.write(decomp_bytes)
449
self.outf.write('\n')
451
def _dump_entries(self, trans, basename):
453
st = trans.stat(basename)
454
except errors.TransportNotPossible:
455
# We can't stat, so we'll fake it because we have to do the 'get()'
457
bt, _ = self._get_index_and_bytes(trans, basename)
459
bt = btree_index.BTreeGraphIndex(trans, basename, st.st_size)
460
for node in bt.iter_all_entries():
461
# Node is made up of:
462
# (index, key, value, [references])
246
self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
247
except errors.NoSuchRevision:
248
msg = "The repository %s contains no revision %s." % (b.repository.base,
250
raise errors.BzrCommandError(msg)
251
elif revision is not None:
254
raise errors.BzrCommandError('You cannot specify a NULL'
256
rev_id = rev.as_revision_id(b)
257
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
466
refs_as_tuples = None
468
refs_as_tuples = static_tuple.as_tuples(refs)
469
as_tuple = (tuple(node[1]), node[2], refs_as_tuples)
470
self.outf.write('%s\n' % (as_tuple,))
260
473
class cmd_remove_tree(Command):
261
474
"""Remove the working tree from a given branch/checkout.
592
864
into_existing = False
594
866
inv = tree.inventory
595
from_id = tree.path2id(rel_names[0])
867
# 'fix' the case of a potential 'from'
868
from_id = tree.path2id(
869
tree.get_canonical_inventory_path(rel_names[0]))
596
870
if (not osutils.lexists(names_list[0]) and
597
871
from_id and inv.get_file_kind(from_id) == "directory"):
598
872
into_existing = False
600
874
if into_existing:
601
875
# move into existing directory
602
for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
603
self.outf.write("%s => %s\n" % pair)
876
# All entries reference existing inventory items, so fix them up
877
# for cicp file-systems.
878
rel_names = tree.get_canonical_inventory_paths(rel_names)
879
for src, dest in tree.move(rel_names[:-1], rel_names[-1], after=after):
881
self.outf.write("%s => %s\n" % (src, dest))
605
883
if len(names_list) != 2:
606
884
raise errors.BzrCommandError('to mv multiple files the'
607
885
' destination must be a versioned'
609
tree.rename_one(rel_names[0], rel_names[1], after=after)
610
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
888
# for cicp file-systems: the src references an existing inventory
890
src = tree.get_canonical_inventory_path(rel_names[0])
891
# Find the canonical version of the destination: In all cases, the
892
# parent of the target must be in the inventory, so we fetch the
893
# canonical version from there (we do not always *use* the
894
# canonicalized tail portion - we may be attempting to rename the
896
canon_dest = tree.get_canonical_inventory_path(rel_names[1])
897
dest_parent = osutils.dirname(canon_dest)
898
spec_tail = osutils.basename(rel_names[1])
899
# For a CICP file-system, we need to avoid creating 2 inventory
900
# entries that differ only by case. So regardless of the case
901
# we *want* to use (ie, specified by the user or the file-system),
902
# we must always choose to use the case of any existing inventory
903
# items. The only exception to this is when we are attempting a
904
# case-only rename (ie, canonical versions of src and dest are
906
dest_id = tree.path2id(canon_dest)
907
if dest_id is None or tree.path2id(src) == dest_id:
908
# No existing item we care about, so work out what case we
909
# are actually going to use.
911
# If 'after' is specified, the tail must refer to a file on disk.
913
dest_parent_fq = osutils.pathjoin(tree.basedir, dest_parent)
915
# pathjoin with an empty tail adds a slash, which breaks
917
dest_parent_fq = tree.basedir
919
dest_tail = osutils.canonical_relpath(
921
osutils.pathjoin(dest_parent_fq, spec_tail))
923
# not 'after', so case as specified is used
924
dest_tail = spec_tail
926
# Use the existing item so 'mv' fails with AlreadyVersioned.
927
dest_tail = os.path.basename(canon_dest)
928
dest = osutils.pathjoin(dest_parent, dest_tail)
929
mutter("attempting to move %s => %s", src, dest)
930
tree.rename_one(src, dest, after=after)
932
self.outf.write("%s => %s\n" % (src, dest))
613
935
class cmd_pull(Command):
614
936
"""Turn this branch into a mirror of another branch.
616
This command only works on branches that have not diverged. Branches are
617
considered diverged if the destination branch's most recent commit is one
618
that has not been merged (directly or indirectly) into the parent.
938
By default, this command only works on branches that have not diverged.
939
Branches are considered diverged if the destination branch's most recent
940
commit is one that has not been merged (directly or indirectly) into the
620
943
If branches have diverged, you can use 'bzr merge' to integrate the changes
621
944
from one into the other. Once one branch has merged, the other should
622
945
be able to pull it again.
624
If you want to forget your local changes and just update your branch to
625
match the remote one, use pull --overwrite.
947
If you want to replace your local changes and just want your branch to
948
match the remote one, use pull --overwrite. This will work even if the two
949
branches have diverged.
627
951
If there is no default location set, the first pull will set it. After
628
952
that, you can omit the location to use the default. To change the
856
1200
takes_args = ['from_location', 'to_location?']
857
1201
takes_options = ['revision', Option('hardlink',
858
1202
help='Hard-link working tree files where possible.'),
1204
help="Create a branch without a working-tree."),
1206
help="Switch the checkout in the current directory "
1207
"to the new branch."),
859
1208
Option('stacked',
860
1209
help='Create a stacked branch referring to the source branch. '
861
1210
'The new branch will depend on the availability of the source '
862
1211
'branch for all operations.'),
863
1212
Option('standalone',
864
1213
help='Do not use a shared repository, even if available.'),
1214
Option('use-existing-dir',
1215
help='By default branch will fail if the target'
1216
' directory exists, but does not already'
1217
' have a control directory. This flag will'
1218
' allow branch to proceed.'),
1220
help="Bind new branch to from location."),
866
1222
aliases = ['get', 'clone']
868
1224
def run(self, from_location, to_location=None, revision=None,
869
hardlink=False, stacked=False, standalone=False):
1225
hardlink=False, stacked=False, standalone=False, no_tree=False,
1226
use_existing_dir=False, switch=False, bind=False):
1227
from bzrlib import switch as _mod_switch
870
1228
from bzrlib.tag import _merge_tags_if_possible
873
elif len(revision) > 1:
874
raise errors.BzrCommandError(
875
'bzr branch --revision takes exactly 1 revision value')
877
1229
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1231
revision = _get_one_revision('branch', revision)
879
1232
br_from.lock_read()
1233
self.add_cleanup(br_from.unlock)
1234
if revision is not None:
1235
revision_id = revision.as_revision_id(br_from)
1237
# FIXME - wt.last_revision, fallback to branch, fall back to
1238
# None or perhaps NULL_REVISION to mean copy nothing
1240
revision_id = br_from.last_revision()
1241
if to_location is None:
1242
to_location = urlutils.derive_to_location(from_location)
1243
to_transport = transport.get_transport(to_location)
881
if len(revision) == 1 and revision[0] is not None:
882
revision_id = revision[0].as_revision_id(br_from)
1245
to_transport.mkdir('.')
1246
except errors.FileExists:
1247
if not use_existing_dir:
1248
raise errors.BzrCommandError('Target directory "%s" '
1249
'already exists.' % to_location)
884
# FIXME - wt.last_revision, fallback to branch, fall back to
885
# None or perhaps NULL_REVISION to mean copy nothing
887
revision_id = br_from.last_revision()
888
if to_location is None:
889
to_location = urlutils.derive_to_location(from_location)
890
to_transport = transport.get_transport(to_location)
892
to_transport.mkdir('.')
893
except errors.FileExists:
894
raise errors.BzrCommandError('Target directory "%s" already'
895
' exists.' % to_location)
896
except errors.NoSuchFile:
897
raise errors.BzrCommandError('Parent of "%s" does not exist.'
900
# preserve whatever source format we have.
901
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
902
possible_transports=[to_transport],
903
accelerator_tree=accelerator_tree,
904
hardlink=hardlink, stacked=stacked,
905
force_new_repo=standalone)
906
branch = dir.open_branch()
907
except errors.NoSuchRevision:
908
to_transport.delete_tree('.')
909
msg = "The branch %s has no revision %s." % (from_location,
911
raise errors.BzrCommandError(msg)
912
_merge_tags_if_possible(br_from, branch)
913
# If the source branch is stacked, the new branch may
914
# be stacked whether we asked for that explicitly or not.
915
# We therefore need a try/except here and not just 'if stacked:'
917
note('Created new stacked branch referring to %s.' %
918
branch.get_stacked_on_url())
919
except (errors.NotStacked, errors.UnstackableBranchFormat,
920
errors.UnstackableRepositoryFormat), e:
921
note('Branched %d revision(s).' % branch.revno())
1252
bzrdir.BzrDir.open_from_transport(to_transport)
1253
except errors.NotBranchError:
1256
raise errors.AlreadyBranchError(to_location)
1257
except errors.NoSuchFile:
1258
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1261
# preserve whatever source format we have.
1262
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1263
possible_transports=[to_transport],
1264
accelerator_tree=accelerator_tree,
1265
hardlink=hardlink, stacked=stacked,
1266
force_new_repo=standalone,
1267
create_tree_if_local=not no_tree,
1268
source_branch=br_from)
1269
branch = dir.open_branch()
1270
except errors.NoSuchRevision:
1271
to_transport.delete_tree('.')
1272
msg = "The branch %s has no revision %s." % (from_location,
1274
raise errors.BzrCommandError(msg)
1275
_merge_tags_if_possible(br_from, branch)
1276
# If the source branch is stacked, the new branch may
1277
# be stacked whether we asked for that explicitly or not.
1278
# We therefore need a try/except here and not just 'if stacked:'
1280
note('Created new stacked branch referring to %s.' %
1281
branch.get_stacked_on_url())
1282
except (errors.NotStacked, errors.UnstackableBranchFormat,
1283
errors.UnstackableRepositoryFormat), e:
1284
note('Branched %d revision(s).' % branch.revno())
1286
# Bind to the parent
1287
parent_branch = Branch.open(from_location)
1288
branch.bind(parent_branch)
1289
note('New branch bound to %s' % from_location)
1291
# Switch to the new branch
1292
wt, _ = WorkingTree.open_containing('.')
1293
_mod_switch.switch(wt.bzrdir, branch)
1294
note('Switched to branch: %s',
1295
urlutils.unescape_for_display(branch.base, 'utf-8'))
926
1298
class cmd_checkout(Command):
1009
1377
def run(self, dir=u'.'):
1010
1378
tree = WorkingTree.open_containing(dir)[0]
1011
1379
tree.lock_read()
1013
new_inv = tree.inventory
1014
old_tree = tree.basis_tree()
1015
old_tree.lock_read()
1017
old_inv = old_tree.inventory
1018
renames = list(_mod_tree.find_renames(old_inv, new_inv))
1020
for old_name, new_name in renames:
1021
self.outf.write("%s => %s\n" % (old_name, new_name))
1380
self.add_cleanup(tree.unlock)
1381
new_inv = tree.inventory
1382
old_tree = tree.basis_tree()
1383
old_tree.lock_read()
1384
self.add_cleanup(old_tree.unlock)
1385
old_inv = old_tree.inventory
1387
iterator = tree.iter_changes(old_tree, include_unchanged=True)
1388
for f, paths, c, v, p, n, k, e in iterator:
1389
if paths[0] == paths[1]:
1393
renames.append(paths)
1395
for old_name, new_name in renames:
1396
self.outf.write("%s => %s\n" % (old_name, new_name))
1028
1399
class cmd_update(Command):
1029
1400
"""Update a tree to have the latest code committed to its branch.
1031
1402
This will perform a merge into the working tree, and may generate
1032
conflicts. If you have any local changes, you will still
1403
conflicts. If you have any local changes, you will still
1033
1404
need to commit them after the update for the update to be complete.
1035
If you want to discard your local changes, you can just do a
1406
If you want to discard your local changes, you can just do a
1036
1407
'bzr revert' instead of 'bzr commit' after the update.
1409
If the tree's branch is bound to a master branch, it will also update
1410
the branch from the master.
1039
1413
_see_also = ['pull', 'working-trees', 'status-flags']
1040
1414
takes_args = ['dir?']
1415
takes_options = ['revision']
1041
1416
aliases = ['up']
1043
def run(self, dir='.'):
1418
def run(self, dir='.', revision=None):
1419
if revision is not None and len(revision) != 1:
1420
raise errors.BzrCommandError(
1421
"bzr update --revision takes exactly one revision")
1044
1422
tree = WorkingTree.open_containing(dir)[0]
1423
branch = tree.branch
1045
1424
possible_transports = []
1046
master = tree.branch.get_master_branch(
1425
master = branch.get_master_branch(
1047
1426
possible_transports=possible_transports)
1048
1427
if master is not None:
1049
1428
tree.lock_write()
1429
branch_location = master.base
1051
1431
tree.lock_tree_write()
1432
branch_location = tree.branch.base
1433
self.add_cleanup(tree.unlock)
1434
# get rid of the final '/' and be ready for display
1435
branch_location = urlutils.unescape_for_display(
1436
branch_location.rstrip('/'),
1438
existing_pending_merges = tree.get_parent_ids()[1:]
1442
# may need to fetch data into a heavyweight checkout
1443
# XXX: this may take some time, maybe we should display a
1445
old_tip = branch.update(possible_transports)
1446
if revision is not None:
1447
revision_id = revision[0].as_revision_id(branch)
1449
revision_id = branch.last_revision()
1450
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1451
revno = branch.revision_id_to_dotted_revno(revision_id)
1452
note("Tree is up to date at revision %s of branch %s" %
1453
('.'.join(map(str, revno)), branch_location))
1455
view_info = _get_view_info_for_change_reporter(tree)
1456
change_reporter = delta._ChangeReporter(
1457
unversioned_filter=tree.is_ignored,
1458
view_info=view_info)
1053
existing_pending_merges = tree.get_parent_ids()[1:]
1054
last_rev = _mod_revision.ensure_null(tree.last_revision())
1055
if last_rev == _mod_revision.ensure_null(
1056
tree.branch.last_revision()):
1057
# may be up to date, check master too.
1058
if master is None or last_rev == _mod_revision.ensure_null(
1059
master.last_revision()):
1060
revno = tree.branch.revision_id_to_revno(last_rev)
1061
note("Tree is up to date at revision %d." % (revno,))
1063
1460
conflicts = tree.update(
1064
delta._ChangeReporter(unversioned_filter=tree.is_ignored),
1065
possible_transports=possible_transports)
1066
revno = tree.branch.revision_id_to_revno(
1067
_mod_revision.ensure_null(tree.last_revision()))
1068
note('Updated to revision %d.' % (revno,))
1069
if tree.get_parent_ids()[1:] != existing_pending_merges:
1070
note('Your local commits will now show as pending merges with '
1071
"'bzr status', and can be committed with 'bzr commit'.")
1462
possible_transports=possible_transports,
1463
revision=revision_id,
1465
except errors.NoSuchRevision, e:
1466
raise errors.BzrCommandError(
1467
"branch has no revision %s\n"
1468
"bzr update --revision only works"
1469
" for a revision in the branch history"
1471
revno = tree.branch.revision_id_to_dotted_revno(
1472
_mod_revision.ensure_null(tree.last_revision()))
1473
note('Updated to revision %s of branch %s' %
1474
('.'.join(map(str, revno)), branch_location))
1475
if tree.get_parent_ids()[1:] != existing_pending_merges:
1476
note('Your local commits will now show as pending merges with '
1477
"'bzr status', and can be committed with 'bzr commit'.")
1080
1484
class cmd_info(Command):
1081
1485
"""Show information about a working tree, branch or repository.
1083
1487
This command will show all known locations and formats associated to the
1084
tree, branch or repository. Statistical information is included with
1488
tree, branch or repository.
1490
In verbose mode, statistical information is included with each report.
1491
To see extended statistic information, use a verbosity level of 2 or
1492
higher by specifying the verbose option multiple times, e.g. -vv.
1087
1494
Branches and working trees will also report any missing revisions.
1498
Display information on the format and related locations:
1502
Display the above together with extended format information and
1503
basic statistics (like the number of files in the working tree and
1504
number of revisions in the branch and repository):
1508
Display the above together with number of committers to the branch:
1089
1512
_see_also = ['revno', 'working-trees', 'repositories']
1090
1513
takes_args = ['location?']
1652
2112
raise errors.BzrCommandError(msg)
2115
def _parse_levels(s):
2119
msg = "The levels argument must be an integer."
2120
raise errors.BzrCommandError(msg)
1655
2123
class cmd_log(Command):
1656
"""Show log of a branch, file, or directory.
1658
By default show the log of the branch containing the working directory.
1660
To request a range of logs, you can use the command -r begin..end
1661
-r revision requests a specific revision, -r ..end or -r begin.. are
1665
Log the current branch::
1673
Log the last 10 revisions of a branch::
1675
bzr log -r -10.. http://server/branch
2124
"""Show historical log for a branch or subset of a branch.
2126
log is bzr's default tool for exploring the history of a branch.
2127
The branch to use is taken from the first parameter. If no parameters
2128
are given, the branch containing the working directory is logged.
2129
Here are some simple examples::
2131
bzr log log the current branch
2132
bzr log foo.py log a file in its branch
2133
bzr log http://server/branch log a branch on a server
2135
The filtering, ordering and information shown for each revision can
2136
be controlled as explained below. By default, all revisions are
2137
shown sorted (topologically) so that newer revisions appear before
2138
older ones and descendants always appear before ancestors. If displayed,
2139
merged revisions are shown indented under the revision in which they
2144
The log format controls how information about each revision is
2145
displayed. The standard log formats are called ``long``, ``short``
2146
and ``line``. The default is long. See ``bzr help log-formats``
2147
for more details on log formats.
2149
The following options can be used to control what information is
2152
-l N display a maximum of N revisions
2153
-n N display N levels of revisions (0 for all, 1 for collapsed)
2154
-v display a status summary (delta) for each revision
2155
-p display a diff (patch) for each revision
2156
--show-ids display revision-ids (and file-ids), not just revnos
2158
Note that the default number of levels to display is a function of the
2159
log format. If the -n option is not used, the standard log formats show
2160
just the top level (mainline).
2162
Status summaries are shown using status flags like A, M, etc. To see
2163
the changes explained using words like ``added`` and ``modified``
2164
instead, use the -vv option.
2168
To display revisions from oldest to newest, use the --forward option.
2169
In most cases, using this option will have little impact on the total
2170
time taken to produce a log, though --forward does not incrementally
2171
display revisions like --reverse does when it can.
2173
:Revision filtering:
2175
The -r option can be used to specify what revision or range of revisions
2176
to filter against. The various forms are shown below::
2178
-rX display revision X
2179
-rX.. display revision X and later
2180
-r..Y display up to and including revision Y
2181
-rX..Y display from X to Y inclusive
2183
See ``bzr help revisionspec`` for details on how to specify X and Y.
2184
Some common examples are given below::
2186
-r-1 show just the tip
2187
-r-10.. show the last 10 mainline revisions
2188
-rsubmit:.. show what's new on this branch
2189
-rancestor:path.. show changes since the common ancestor of this
2190
branch and the one at location path
2191
-rdate:yesterday.. show changes since yesterday
2193
When logging a range of revisions using -rX..Y, log starts at
2194
revision Y and searches back in history through the primary
2195
("left-hand") parents until it finds X. When logging just the
2196
top level (using -n1), an error is reported if X is not found
2197
along the way. If multi-level logging is used (-n0), X may be
2198
a nested merge revision and the log will be truncated accordingly.
2202
If parameters are given and the first one is not a branch, the log
2203
will be filtered to show only those revisions that changed the
2204
nominated files or directories.
2206
Filenames are interpreted within their historical context. To log a
2207
deleted file, specify a revision range so that the file existed at
2208
the end or start of the range.
2210
Historical context is also important when interpreting pathnames of
2211
renamed files/directories. Consider the following example:
2213
* revision 1: add tutorial.txt
2214
* revision 2: modify tutorial.txt
2215
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
2219
* ``bzr log guide.txt`` will log the file added in revision 1
2221
* ``bzr log tutorial.txt`` will log the new file added in revision 3
2223
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2224
the original file in revision 2.
2226
* ``bzr log -r2 -p guide.txt`` will display an error message as there
2227
was no file called guide.txt in revision 2.
2229
Renames are always followed by log. By design, there is no need to
2230
explicitly ask for this (and no way to stop logging a file back
2231
until it was last renamed).
2235
The --message option can be used for finding revisions that match a
2236
regular expression in a commit message.
2240
GUI tools and IDEs are often better at exploring history than command
2241
line tools: you may prefer qlog or viz from qbzr or bzr-gtk, the
2242
bzr-explorer shell, or the Loggerhead web interface. See the Plugin
2243
Guide <http://doc.bazaar.canonical.com/plugins/en/> and
2244
<http://wiki.bazaar.canonical.com/IDEIntegration>.
2246
You may find it useful to add the aliases below to ``bazaar.conf``::
2250
top = log -l10 --line
2253
``bzr tip`` will then show the latest revision while ``bzr top``
2254
will show the last 10 mainline revisions. To see the details of a
2255
particular revision X, ``bzr show -rX``.
2257
If you are interested in looking deeper into a particular merge X,
2258
use ``bzr log -n0 -rX``.
2260
``bzr log -v`` on a branch with lots of history is currently
2261
very slow. A fix for this issue is currently under development.
2262
With or without that fix, it is recommended that a revision range
2263
be given when using the -v option.
2265
bzr has a generic full-text matching plugin, bzr-search, that can be
2266
used to find revisions matching user names, commit messages, etc.
2267
Among other features, this plugin can find all revisions containing
2268
a list of words but not others.
2270
When exploring non-mainline history on large projects with deep
2271
history, the performance of log can be greatly improved by installing
2272
the historycache plugin. This plugin buffers historical information
2273
trading disk space for faster speed.
1678
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1680
takes_args = ['location?']
2275
takes_args = ['file*']
2276
_see_also = ['log-formats', 'revisionspec']
1681
2277
takes_options = [
1682
2278
Option('forward',
1683
2279
help='Show from oldest to newest.'),
1686
help='Display timezone as local, original, or utc.'),
1687
2281
custom_help('verbose',
1688
2282
help='Show files changed in each revision.'),
1755
2377
dir, relpath = bzrdir.BzrDir.open_containing(location)
1756
2378
b = dir.open_branch()
1760
if revision is None:
1763
elif len(revision) == 1:
1764
rev1 = rev2 = revision[0].in_history(b)
1765
elif len(revision) == 2:
1766
if revision[1].get_branch() != revision[0].get_branch():
1767
# b is taken from revision[0].get_branch(), and
1768
# show_log will use its revision_history. Having
1769
# different branches will lead to weird behaviors.
1770
raise errors.BzrCommandError(
1771
"Log doesn't accept two revisions in different"
1773
rev1 = revision[0].in_history(b)
1774
rev2 = revision[1].in_history(b)
1776
raise errors.BzrCommandError(
1777
'bzr log --revision takes one or two values.')
1779
if log_format is None:
1780
log_format = log.log_formatter_registry.get_default(b)
1782
lf = log_format(show_ids=show_ids, to_file=self.outf,
1783
show_timezone=timezone)
1789
direction=direction,
1790
start_revision=rev1,
2380
self.add_cleanup(b.unlock)
2381
rev1, rev2 = _get_revision_range(revision, b, self.name())
2383
# Decide on the type of delta & diff filtering to use
2384
# TODO: add an --all-files option to make this configurable & consistent
2392
diff_type = 'partial'
2396
# Build the log formatter
2397
if log_format is None:
2398
log_format = log.log_formatter_registry.get_default(b)
2399
# Make a non-encoding output to include the diffs - bug 328007
2400
unencoded_output = ui.ui_factory.make_output_stream(encoding_type='exact')
2401
lf = log_format(show_ids=show_ids, to_file=self.outf,
2402
to_exact_file=unencoded_output,
2403
show_timezone=timezone,
2404
delta_format=get_verbosity_level(),
2406
show_advice=levels is None)
2408
# Choose the algorithm for doing the logging. It's annoying
2409
# having multiple code paths like this but necessary until
2410
# the underlying repository format is faster at generating
2411
# deltas or can provide everything we need from the indices.
2412
# The default algorithm - match-using-deltas - works for
2413
# multiple files and directories and is faster for small
2414
# amounts of history (200 revisions say). However, it's too
2415
# slow for logging a single file in a repository with deep
2416
# history, i.e. > 10K revisions. In the spirit of "do no
2417
# evil when adding features", we continue to use the
2418
# original algorithm - per-file-graph - for the "single
2419
# file that isn't a directory without showing a delta" case.
2420
partial_history = revision and b.repository._format.supports_chks
2421
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2422
or delta_type or partial_history)
2424
# Build the LogRequest and execute it
2425
if len(file_ids) == 0:
2427
rqst = make_log_request_dict(
2428
direction=direction, specific_fileids=file_ids,
2429
start_revision=rev1, end_revision=rev2, limit=limit,
2430
message_search=message, delta_type=delta_type,
2431
diff_type=diff_type, _match_using_deltas=match_using_deltas)
2432
Logger(b, rqst).show(lf)
2435
def _get_revision_range(revisionspec_list, branch, command_name):
2436
"""Take the input of a revision option and turn it into a revision range.
2438
It returns RevisionInfo objects which can be used to obtain the rev_id's
2439
of the desired revisions. It does some user input validations.
2441
if revisionspec_list is None:
2444
elif len(revisionspec_list) == 1:
2445
rev1 = rev2 = revisionspec_list[0].in_history(branch)
2446
elif len(revisionspec_list) == 2:
2447
start_spec = revisionspec_list[0]
2448
end_spec = revisionspec_list[1]
2449
if end_spec.get_branch() != start_spec.get_branch():
2450
# b is taken from revision[0].get_branch(), and
2451
# show_log will use its revision_history. Having
2452
# different branches will lead to weird behaviors.
2453
raise errors.BzrCommandError(
2454
"bzr %s doesn't accept two revisions in different"
2455
" branches." % command_name)
2456
if start_spec.spec is None:
2457
# Avoid loading all the history.
2458
rev1 = RevisionInfo(branch, None, None)
2460
rev1 = start_spec.in_history(branch)
2461
# Avoid loading all of history when we know a missing
2462
# end of range means the last revision ...
2463
if end_spec.spec is None:
2464
last_revno, last_revision_id = branch.last_revision_info()
2465
rev2 = RevisionInfo(branch, last_revno, last_revision_id)
2467
rev2 = end_spec.in_history(branch)
2469
raise errors.BzrCommandError(
2470
'bzr %s --revision takes one or two values.' % command_name)
2474
def _revision_range_to_revid_range(revision_range):
2477
if revision_range[0] is not None:
2478
rev_id1 = revision_range[0].rev_id
2479
if revision_range[1] is not None:
2480
rev_id2 = revision_range[1].rev_id
2481
return rev_id1, rev_id2
1798
2483
def get_log_format(long=False, short=False, line=False, default='long'):
1799
2484
log_format = default
2120
2860
If no revision is nominated, the last revision is used.
2122
2862
Note: Take care to redirect standard output when using this command on a
2126
2866
_see_also = ['ls']
2127
2867
takes_options = [
2128
2868
Option('name-from-revision', help='The path name in the old tree.'),
2869
Option('filters', help='Apply content filters to display the '
2870
'convenience form.'),
2131
2873
takes_args = ['filename']
2132
2874
encoding_type = 'exact'
2134
2876
@display_command
2135
def run(self, filename, revision=None, name_from_revision=False):
2877
def run(self, filename, revision=None, name_from_revision=False,
2136
2879
if revision is not None and len(revision) != 1:
2137
2880
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2138
2881
" one revision specifier")
2139
2882
tree, branch, relpath = \
2140
2883
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2141
2884
branch.lock_read()
2143
return self._run(tree, branch, relpath, filename, revision,
2885
self.add_cleanup(branch.unlock)
2886
return self._run(tree, branch, relpath, filename, revision,
2887
name_from_revision, filters)
2148
def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2889
def _run(self, tree, b, relpath, filename, revision, name_from_revision,
2149
2891
if tree is None:
2150
2892
tree = b.basis_tree()
2151
2893
rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2894
rev_tree.lock_read()
2895
self.add_cleanup(rev_tree.unlock)
2153
cur_file_id = tree.path2id(relpath)
2154
2897
old_file_id = rev_tree.path2id(relpath)
2156
2899
if name_from_revision:
2900
# Try in revision if requested
2157
2901
if old_file_id is None:
2158
2902
raise errors.BzrCommandError(
2159
2903
"%r is not present in revision %s" % (
2160
2904
filename, rev_tree.get_revision_id()))
2162
2906
content = rev_tree.get_file_text(old_file_id)
2163
elif cur_file_id is not None:
2164
content = rev_tree.get_file_text(cur_file_id)
2165
elif old_file_id is not None:
2166
content = rev_tree.get_file_text(old_file_id)
2168
raise errors.BzrCommandError(
2169
"%r is not present in revision %s" % (
2170
filename, rev_tree.get_revision_id()))
2171
self.outf.write(content)
2908
cur_file_id = tree.path2id(relpath)
2910
if cur_file_id is not None:
2911
# Then try with the actual file id
2913
content = rev_tree.get_file_text(cur_file_id)
2915
except errors.NoSuchId:
2916
# The actual file id didn't exist at that time
2918
if not found and old_file_id is not None:
2919
# Finally try with the old file id
2920
content = rev_tree.get_file_text(old_file_id)
2923
# Can't be found anywhere
2924
raise errors.BzrCommandError(
2925
"%r is not present in revision %s" % (
2926
filename, rev_tree.get_revision_id()))
2928
from bzrlib.filters import (
2929
ContentFilterContext,
2930
filtered_output_bytes,
2932
filters = rev_tree._content_filter_stack(relpath)
2933
chunks = content.splitlines(True)
2934
content = filtered_output_bytes(chunks, filters,
2935
ContentFilterContext(relpath, rev_tree))
2937
self.outf.writelines(content)
2940
self.outf.write(content)
2174
2943
class cmd_local_time_offset(Command):
2175
2944
"""Show the offset in seconds from GMT to local time."""
2177
2946
@display_command
2179
print osutils.local_time_offset()
2948
self.outf.write("%s\n" % osutils.local_time_offset())
2183
2952
class cmd_commit(Command):
2184
2953
"""Commit changes into a new revision.
2186
If no arguments are given, the entire tree is committed.
2188
If selected files are specified, only changes to those files are
2189
committed. If a directory is specified then the directory and everything
2190
within it is committed.
2192
When excludes are given, they take precedence over selected files.
2193
For example, too commit only changes within foo, but not changes within
2196
bzr commit foo -x foo/bar
2198
If author of the change is not the same person as the committer, you can
2199
specify the author's name using the --author option. The name should be
2200
in the same format as a committer-id, e.g. "John Doe <jdoe@example.com>".
2202
A selected-file commit may fail in some cases where the committed
2203
tree would be invalid. Consider::
2208
bzr commit foo -m "committing foo"
2209
bzr mv foo/bar foo/baz
2212
bzr commit foo/bar -m "committing bar but not baz"
2214
In the example above, the last commit will fail by design. This gives
2215
the user the opportunity to decide whether they want to commit the
2216
rename at the same time, separately first, or not at all. (As a general
2217
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
2219
Note: A selected-file commit after a merge is not yet supported.
2955
An explanatory message needs to be given for each commit. This is
2956
often done by using the --message option (getting the message from the
2957
command line) or by using the --file option (getting the message from
2958
a file). If neither of these options is given, an editor is opened for
2959
the user to enter the message. To see the changed files in the
2960
boilerplate text loaded into the editor, use the --show-diff option.
2962
By default, the entire tree is committed and the person doing the
2963
commit is assumed to be the author. These defaults can be overridden
2968
If selected files are specified, only changes to those files are
2969
committed. If a directory is specified then the directory and
2970
everything within it is committed.
2972
When excludes are given, they take precedence over selected files.
2973
For example, to commit only changes within foo, but not changes
2976
bzr commit foo -x foo/bar
2978
A selective commit after a merge is not yet supported.
2982
If the author of the change is not the same person as the committer,
2983
you can specify the author's name using the --author option. The
2984
name should be in the same format as a committer-id, e.g.
2985
"John Doe <jdoe@example.com>". If there is more than one author of
2986
the change you can specify the option multiple times, once for each
2991
A common mistake is to forget to add a new file or directory before
2992
running the commit command. The --strict option checks for unknown
2993
files and aborts the commit if any are found. More advanced pre-commit
2994
checks can be implemented by defining hooks. See ``bzr help hooks``
2999
If you accidentially commit the wrong changes or make a spelling
3000
mistake in the commit message say, you can use the uncommit command
3001
to undo it. See ``bzr help uncommit`` for details.
3003
Hooks can also be configured to run after a commit. This allows you
3004
to trigger updates to external systems like bug trackers. The --fixes
3005
option can be used to record the association between a revision and
3006
one or more bugs. See ``bzr help bugs`` for details.
3008
A selective commit may fail in some cases where the committed
3009
tree would be invalid. Consider::
3014
bzr commit foo -m "committing foo"
3015
bzr mv foo/bar foo/baz
3018
bzr commit foo/bar -m "committing bar but not baz"
3020
In the example above, the last commit will fail by design. This gives
3021
the user the opportunity to decide whether they want to commit the
3022
rename at the same time, separately first, or not at all. (As a general
3023
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
2221
3025
# TODO: Run hooks on tree to-be-committed, and after commit.
2315
3129
if fixes is None:
2317
bug_property = self._get_bug_fix_properties(fixes, tree.branch)
3131
bug_property = bugtracker.encode_fixes_bug_urls(
3132
self._iter_bug_fix_urls(fixes, tree.branch))
2318
3133
if bug_property:
2319
3134
properties['bugs'] = bug_property
2321
3136
if local and not tree.branch.get_bound_location():
2322
3137
raise errors.LocalRequiresBoundBranch()
3139
if message is not None:
3141
file_exists = osutils.lexists(message)
3142
except UnicodeError:
3143
# The commit message contains unicode characters that can't be
3144
# represented in the filesystem encoding, so that can't be a
3149
'The commit message is a file name: "%(f)s".\n'
3150
'(use --file "%(f)s" to take commit message from that file)'
3152
ui.ui_factory.show_warning(warning_msg)
3154
message = message.replace('\r\n', '\n')
3155
message = message.replace('\r', '\n')
3157
raise errors.BzrCommandError(
3158
"please specify either --message or --file")
2324
3160
def get_message(commit_obj):
2325
3161
"""Callback to get commit message"""
2326
my_message = message
2327
if my_message is None and not file:
2328
t = make_commit_message_template_encoded(tree,
3163
my_message = codecs.open(
3164
file, 'rt', osutils.get_user_encoding()).read()
3165
elif message is not None:
3166
my_message = message
3168
# No message supplied: make one up.
3169
# text is the status of the tree
3170
text = make_commit_message_template_encoded(tree,
2329
3171
selected_list, diff=show_diff,
2330
3172
output_encoding=osutils.get_user_encoding())
2331
my_message = edit_commit_message_encoded(t)
3173
# start_message is the template generated from hooks
3174
# XXX: Warning - looks like hooks return unicode,
3175
# make_commit_message_template_encoded returns user encoding.
3176
# We probably want to be using edit_commit_message instead to
3178
start_message = generate_commit_message_template(commit_obj)
3179
my_message = edit_commit_message_encoded(text,
3180
start_message=start_message)
2332
3181
if my_message is None:
2333
3182
raise errors.BzrCommandError("please specify a commit"
2334
3183
" message with either --message or --file")
2335
elif my_message and file:
2336
raise errors.BzrCommandError(
2337
"please specify either --message or --file")
2339
my_message = codecs.open(file, 'rt',
2340
osutils.get_user_encoding()).read()
2341
3184
if my_message == "":
2342
3185
raise errors.BzrCommandError("empty commit message specified")
2343
3186
return my_message
3188
# The API permits a commit with a filter of [] to mean 'select nothing'
3189
# but the command line should not do that.
3190
if not selected_list:
3191
selected_list = None
2346
3193
tree.commit(message_callback=get_message,
2347
3194
specific_files=selected_list,
2348
3195
allow_pointless=unchanged, strict=strict, local=local,
2349
3196
reporter=None, verbose=verbose, revprops=properties,
3197
authors=author, timestamp=commit_stamp,
2351
3199
exclude=safe_relpath_files(tree, exclude))
2352
3200
except PointlessCommit:
2353
# FIXME: This should really happen before the file is read in;
2354
# perhaps prepare the commit; get the message; then actually commit
2355
raise errors.BzrCommandError("no changes to commit."
2356
" use --unchanged to commit anyhow")
3201
raise errors.BzrCommandError("No changes to commit."
3202
" Use --unchanged to commit anyhow.")
2357
3203
except ConflictsInTree:
2358
3204
raise errors.BzrCommandError('Conflicts detected in working '
2359
3205
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
2920
3807
allow_pending = True
2921
3808
verified = 'inapplicable'
2922
3809
tree = WorkingTree.open_containing(directory)[0]
3812
basis_tree = tree.revision_tree(tree.last_revision())
3813
except errors.NoSuchRevision:
3814
basis_tree = tree.basis_tree()
3816
# die as quickly as possible if there are uncommitted changes
3818
if tree.has_changes():
3819
raise errors.UncommittedChanges(tree)
3821
view_info = _get_view_info_for_change_reporter(tree)
2923
3822
change_reporter = delta._ChangeReporter(
2924
unversioned_filter=tree.is_ignored)
2927
pb = ui.ui_factory.nested_progress_bar()
2928
cleanups.append(pb.finished)
2930
cleanups.append(tree.unlock)
2931
if location is not None:
2933
mergeable = bundle.read_mergeable_from_url(location,
2934
possible_transports=possible_transports)
2935
except errors.NotABundle:
2939
raise errors.BzrCommandError('Cannot use --uncommitted'
2940
' with bundles or merge directives.')
2942
if revision is not None:
2943
raise errors.BzrCommandError(
2944
'Cannot use -r with merge directives or bundles')
2945
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2948
if merger is None and uncommitted:
2949
if revision is not None and len(revision) > 0:
2950
raise errors.BzrCommandError('Cannot use --uncommitted and'
2951
' --revision at the same time.')
2952
location = self._select_branch_location(tree, location)[0]
2953
other_tree, other_path = WorkingTree.open_containing(location)
2954
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2956
allow_pending = False
2957
if other_path != '':
2958
merger.interesting_files = [other_path]
2961
merger, allow_pending = self._get_merger_from_branch(tree,
2962
location, revision, remember, possible_transports, pb)
2964
merger.merge_type = merge_type
2965
merger.reprocess = reprocess
2966
merger.show_base = show_base
2967
self.sanity_check_merger(merger)
2968
if (merger.base_rev_id == merger.other_rev_id and
2969
merger.other_rev_id is not None):
2970
note('Nothing to do.')
3823
unversioned_filter=tree.is_ignored, view_info=view_info)
3824
pb = ui.ui_factory.nested_progress_bar()
3825
self.add_cleanup(pb.finished)
3827
self.add_cleanup(tree.unlock)
3828
if location is not None:
3830
mergeable = bundle.read_mergeable_from_url(location,
3831
possible_transports=possible_transports)
3832
except errors.NotABundle:
3836
raise errors.BzrCommandError('Cannot use --uncommitted'
3837
' with bundles or merge directives.')
3839
if revision is not None:
3840
raise errors.BzrCommandError(
3841
'Cannot use -r with merge directives or bundles')
3842
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3845
if merger is None and uncommitted:
3846
if revision is not None and len(revision) > 0:
3847
raise errors.BzrCommandError('Cannot use --uncommitted and'
3848
' --revision at the same time.')
3849
merger = self.get_merger_from_uncommitted(tree, location, None)
3850
allow_pending = False
3853
merger, allow_pending = self._get_merger_from_branch(tree,
3854
location, revision, remember, possible_transports, None)
3856
merger.merge_type = merge_type
3857
merger.reprocess = reprocess
3858
merger.show_base = show_base
3859
self.sanity_check_merger(merger)
3860
if (merger.base_rev_id == merger.other_rev_id and
3861
merger.other_rev_id is not None):
3862
note('Nothing to do.')
3865
if merger.interesting_files is not None:
3866
raise errors.BzrCommandError('Cannot pull individual files')
3867
if (merger.base_rev_id == tree.last_revision()):
3868
result = tree.pull(merger.other_branch, False,
3869
merger.other_rev_id)
3870
result.report(self.outf)
2973
if merger.interesting_files is not None:
2974
raise errors.BzrCommandError('Cannot pull individual files')
2975
if (merger.base_rev_id == tree.last_revision()):
2976
result = tree.pull(merger.other_branch, False,
2977
merger.other_rev_id)
2978
result.report(self.outf)
2980
merger.check_basis(not force)
2982
return self._do_preview(merger)
2984
return self._do_merge(merger, change_reporter, allow_pending,
2987
for cleanup in reversed(cleanups):
3872
if merger.this_basis is None:
3873
raise errors.BzrCommandError(
3874
"This branch has no commits."
3875
" (perhaps you would prefer 'bzr pull')")
3877
return self._do_preview(merger)
3879
return self._do_interactive(merger)
3881
return self._do_merge(merger, change_reporter, allow_pending,
3884
def _get_preview(self, merger):
3885
tree_merger = merger.make_merger()
3886
tt = tree_merger.make_preview_transform()
3887
self.add_cleanup(tt.finalize)
3888
result_tree = tt.get_preview_tree()
2990
3891
def _do_preview(self, merger):
2991
3892
from bzrlib.diff import show_diff_trees
2992
tree_merger = merger.make_merger()
2993
tt = tree_merger.make_preview_transform()
2995
result_tree = tt.get_preview_tree()
2996
show_diff_trees(merger.this_tree, result_tree, self.outf,
2997
old_label='', new_label='')
3893
result_tree = self._get_preview(merger)
3894
show_diff_trees(merger.this_tree, result_tree, self.outf,
3895
old_label='', new_label='')
3001
3897
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3002
3898
merger.change_reporter = change_reporter
3149
4083
def run(self, file_list=None, merge_type=None, show_base=False,
3150
4084
reprocess=False):
4085
from bzrlib.conflicts import restore
3151
4086
if merge_type is None:
3152
4087
merge_type = _mod_merge.Merge3Merger
3153
4088
tree, file_list = tree_files(file_list)
3154
4089
tree.lock_write()
4090
self.add_cleanup(tree.unlock)
4091
parents = tree.get_parent_ids()
4092
if len(parents) != 2:
4093
raise errors.BzrCommandError("Sorry, remerge only works after normal"
4094
" merges. Not cherrypicking or"
4096
repository = tree.branch.repository
4097
interesting_ids = None
4099
conflicts = tree.conflicts()
4100
if file_list is not None:
4101
interesting_ids = set()
4102
for filename in file_list:
4103
file_id = tree.path2id(filename)
4105
raise errors.NotVersionedError(filename)
4106
interesting_ids.add(file_id)
4107
if tree.kind(file_id) != "directory":
4110
for name, ie in tree.inventory.iter_entries(file_id):
4111
interesting_ids.add(ie.file_id)
4112
new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
4114
# Remerge only supports resolving contents conflicts
4115
allowed_conflicts = ('text conflict', 'contents conflict')
4116
restore_files = [c.path for c in conflicts
4117
if c.typestring in allowed_conflicts]
4118
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
4119
tree.set_conflicts(ConflictList(new_conflicts))
4120
if file_list is not None:
4121
restore_files = file_list
4122
for filename in restore_files:
4124
restore(tree.abspath(filename))
4125
except errors.NotConflicted:
4127
# Disable pending merges, because the file texts we are remerging
4128
# have not had those merges performed. If we use the wrong parents
4129
# list, we imply that the working tree text has seen and rejected
4130
# all the changes from the other tree, when in fact those changes
4131
# have not yet been seen.
4132
tree.set_parent_ids(parents[:1])
3156
parents = tree.get_parent_ids()
3157
if len(parents) != 2:
3158
raise errors.BzrCommandError("Sorry, remerge only works after normal"
3159
" merges. Not cherrypicking or"
3161
repository = tree.branch.repository
3162
interesting_ids = None
3164
conflicts = tree.conflicts()
3165
if file_list is not None:
3166
interesting_ids = set()
3167
for filename in file_list:
3168
file_id = tree.path2id(filename)
3170
raise errors.NotVersionedError(filename)
3171
interesting_ids.add(file_id)
3172
if tree.kind(file_id) != "directory":
3175
for name, ie in tree.inventory.iter_entries(file_id):
3176
interesting_ids.add(ie.file_id)
3177
new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
3179
# Remerge only supports resolving contents conflicts
3180
allowed_conflicts = ('text conflict', 'contents conflict')
3181
restore_files = [c.path for c in conflicts
3182
if c.typestring in allowed_conflicts]
3183
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
3184
tree.set_conflicts(ConflictList(new_conflicts))
3185
if file_list is not None:
3186
restore_files = file_list
3187
for filename in restore_files:
3189
restore(tree.abspath(filename))
3190
except errors.NotConflicted:
3192
# Disable pending merges, because the file texts we are remerging
3193
# have not had those merges performed. If we use the wrong parents
3194
# list, we imply that the working tree text has seen and rejected
3195
# all the changes from the other tree, when in fact those changes
3196
# have not yet been seen.
3197
pb = ui.ui_factory.nested_progress_bar()
3198
tree.set_parent_ids(parents[:1])
3200
merger = _mod_merge.Merger.from_revision_ids(pb,
3202
merger.interesting_ids = interesting_ids
3203
merger.merge_type = merge_type
3204
merger.show_base = show_base
3205
merger.reprocess = reprocess
3206
conflicts = merger.do_merge()
3208
tree.set_parent_ids(parents)
4134
merger = _mod_merge.Merger.from_revision_ids(None, tree, parents[1])
4135
merger.interesting_ids = interesting_ids
4136
merger.merge_type = merge_type
4137
merger.show_base = show_base
4138
merger.reprocess = reprocess
4139
conflicts = merger.do_merge()
4141
tree.set_parent_ids(parents)
3212
4142
if conflicts > 0:
3378
4357
" or specified.")
3379
4358
display_url = urlutils.unescape_for_display(parent,
3380
4359
self.outf.encoding)
3381
self.outf.write("Using saved parent location: "
4360
message("Using saved parent location: "
3382
4361
+ display_url + "\n")
3384
4363
remote_branch = Branch.open(other_branch)
3385
4364
if remote_branch.base == local_branch.base:
3386
4365
remote_branch = local_branch
3387
local_branch.lock_read()
3389
4367
remote_branch.lock_read()
3391
local_extra, remote_extra = find_unmerged(
3392
local_branch, remote_branch, restrict,
3393
backward=not reverse,
3394
include_merges=include_merges)
3396
if log_format is None:
3397
registry = log.log_formatter_registry
3398
log_format = registry.get_default(local_branch)
3399
lf = log_format(to_file=self.outf,
3401
show_timezone='original')
3404
if local_extra and not theirs_only:
3405
self.outf.write("You have %d extra revision(s):\n" %
3407
for revision in iter_log_revisions(local_extra,
3408
local_branch.repository,
3410
lf.log_revision(revision)
3411
printed_local = True
3414
printed_local = False
3416
if remote_extra and not mine_only:
3417
if printed_local is True:
3418
self.outf.write("\n\n\n")
3419
self.outf.write("You are missing %d revision(s):\n" %
3421
for revision in iter_log_revisions(remote_extra,
3422
remote_branch.repository,
3424
lf.log_revision(revision)
3427
if mine_only and not local_extra:
3428
# We checked local, and found nothing extra
3429
self.outf.write('This branch is up to date.\n')
3430
elif theirs_only and not remote_extra:
3431
# We checked remote, and found nothing extra
3432
self.outf.write('Other branch is up to date.\n')
3433
elif not (mine_only or theirs_only or local_extra or
3435
# We checked both branches, and neither one had extra
3437
self.outf.write("Branches are up to date.\n")
3439
remote_branch.unlock()
3441
local_branch.unlock()
4368
self.add_cleanup(remote_branch.unlock)
4370
local_revid_range = _revision_range_to_revid_range(
4371
_get_revision_range(my_revision, local_branch,
4374
remote_revid_range = _revision_range_to_revid_range(
4375
_get_revision_range(revision,
4376
remote_branch, self.name()))
4378
local_extra, remote_extra = find_unmerged(
4379
local_branch, remote_branch, restrict,
4380
backward=not reverse,
4381
include_merges=include_merges,
4382
local_revid_range=local_revid_range,
4383
remote_revid_range=remote_revid_range)
4385
if log_format is None:
4386
registry = log.log_formatter_registry
4387
log_format = registry.get_default(local_branch)
4388
lf = log_format(to_file=self.outf,
4390
show_timezone='original')
4393
if local_extra and not theirs_only:
4394
message("You have %d extra revision(s):\n" %
4396
for revision in iter_log_revisions(local_extra,
4397
local_branch.repository,
4399
lf.log_revision(revision)
4400
printed_local = True
4403
printed_local = False
4405
if remote_extra and not mine_only:
4406
if printed_local is True:
4408
message("You are missing %d revision(s):\n" %
4410
for revision in iter_log_revisions(remote_extra,
4411
remote_branch.repository,
4413
lf.log_revision(revision)
4416
if mine_only and not local_extra:
4417
# We checked local, and found nothing extra
4418
message('This branch is up to date.\n')
4419
elif theirs_only and not remote_extra:
4420
# We checked remote, and found nothing extra
4421
message('Other branch is up to date.\n')
4422
elif not (mine_only or theirs_only or local_extra or
4424
# We checked both branches, and neither one had extra
4426
message("Branches are up to date.\n")
3442
4428
if not status_code and parent is None and other_branch is not None:
3443
4429
local_branch.lock_write()
3445
# handle race conditions - a parent might be set while we run.
3446
if local_branch.get_parent() is None:
3447
local_branch.set_parent(remote_branch.base)
3449
local_branch.unlock()
4430
self.add_cleanup(local_branch.unlock)
4431
# handle race conditions - a parent might be set while we run.
4432
if local_branch.get_parent() is None:
4433
local_branch.set_parent(remote_branch.base)
3450
4434
return status_code
4182
5176
short_name='f',
4184
5178
Option('output', short_name='o',
4185
help='Write merge directive to this file; '
5179
help='Write merge directive to this file or directory; '
4186
5180
'use - for stdout.',
5183
help='Refuse to send if there are uncommitted changes in'
5184
' the working tree, --no-strict disables the check.'),
4188
5185
Option('mail-to', help='Mail the request to this address.',
4192
RegistryOption.from_kwargs('format',
4193
'Use the specified output format.',
4194
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4195
'0.9': 'Bundle format 0.9, Merge Directive 1',})
5189
Option('body', help='Body for the email.', type=unicode),
5190
RegistryOption('format',
5191
help='Use the specified output format.',
5192
lazy_registry=('bzrlib.send', 'format_registry')),
4198
5195
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4199
5196
no_patch=False, revision=None, remember=False, output=None,
4200
format='4', mail_to=None, message=None, **kwargs):
4201
return self._run(submit_branch, revision, public_branch, remember,
4202
format, no_bundle, no_patch, output,
4203
kwargs.get('from', '.'), mail_to, message)
4205
def _run(self, submit_branch, revision, public_branch, remember, format,
4206
no_bundle, no_patch, output, from_, mail_to, message):
4207
from bzrlib.revision import NULL_REVISION
4208
branch = Branch.open_containing(from_)[0]
4210
outfile = cStringIO.StringIO()
4214
outfile = open(output, 'wb')
4215
# we may need to write data into branch's repository to calculate
4220
config = branch.get_config()
4222
mail_to = config.get_user_option('submit_to')
4223
mail_client = config.get_mail_client()
4224
if remember and submit_branch is None:
4225
raise errors.BzrCommandError(
4226
'--remember requires a branch to be specified.')
4227
stored_submit_branch = branch.get_submit_branch()
4228
remembered_submit_branch = None
4229
if submit_branch is None:
4230
submit_branch = stored_submit_branch
4231
remembered_submit_branch = "submit"
4233
if stored_submit_branch is None or remember:
4234
branch.set_submit_branch(submit_branch)
4235
if submit_branch is None:
4236
submit_branch = branch.get_parent()
4237
remembered_submit_branch = "parent"
4238
if submit_branch is None:
4239
raise errors.BzrCommandError('No submit branch known or'
4241
if remembered_submit_branch is not None:
4242
note('Using saved %s location "%s" to determine what '
4243
'changes to submit.', remembered_submit_branch,
4247
submit_config = Branch.open(submit_branch).get_config()
4248
mail_to = submit_config.get_user_option("child_submit_to")
4250
stored_public_branch = branch.get_public_branch()
4251
if public_branch is None:
4252
public_branch = stored_public_branch
4253
elif stored_public_branch is None or remember:
4254
branch.set_public_branch(public_branch)
4255
if no_bundle and public_branch is None:
4256
raise errors.BzrCommandError('No public branch specified or'
4258
base_revision_id = None
4260
if revision is not None:
4261
if len(revision) > 2:
4262
raise errors.BzrCommandError('bzr send takes '
4263
'at most two one revision identifiers')
4264
revision_id = revision[-1].as_revision_id(branch)
4265
if len(revision) == 2:
4266
base_revision_id = revision[0].as_revision_id(branch)
4267
if revision_id is None:
4268
revision_id = branch.last_revision()
4269
if revision_id == NULL_REVISION:
4270
raise errors.BzrCommandError('No revisions to submit.')
4272
directive = merge_directive.MergeDirective2.from_objects(
4273
branch.repository, revision_id, time.time(),
4274
osutils.local_time_offset(), submit_branch,
4275
public_branch=public_branch, include_patch=not no_patch,
4276
include_bundle=not no_bundle, message=message,
4277
base_revision_id=base_revision_id)
4278
elif format == '0.9':
4281
patch_type = 'bundle'
4283
raise errors.BzrCommandError('Format 0.9 does not'
4284
' permit bundle with no patch')
4290
directive = merge_directive.MergeDirective.from_objects(
4291
branch.repository, revision_id, time.time(),
4292
osutils.local_time_offset(), submit_branch,
4293
public_branch=public_branch, patch_type=patch_type,
4296
outfile.writelines(directive.to_lines())
4298
subject = '[MERGE] '
4299
if message is not None:
4302
revision = branch.repository.get_revision(revision_id)
4303
subject += revision.get_summary()
4304
basename = directive.get_disk_name(branch)
4305
mail_client.compose_merge_request(mail_to, subject,
4306
outfile.getvalue(), basename)
5197
format=None, mail_to=None, message=None, body=None,
5198
strict=None, **kwargs):
5199
from bzrlib.send import send
5200
return send(submit_branch, revision, public_branch, remember,
5201
format, no_bundle, no_patch, output,
5202
kwargs.get('from', '.'), mail_to, message, body,
4313
5207
class cmd_bundle_revisions(cmd_send):
4315
"""Create a merge-directive for submiting changes.
5208
"""Create a merge-directive for submitting changes.
4317
5210
A merge directive provides many things needed for requesting merges:
4513
5441
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4514
5442
takes_args = ['location?']
4515
takes_options = [RegistryOption.from_kwargs('target_type',
4516
title='Target type',
4517
help='The type to reconfigure the directory to.',
4518
value_switches=True, enum_switch=False,
4519
branch='Reconfigure to be an unbound branch '
4520
'with no working tree.',
4521
tree='Reconfigure to be an unbound branch '
4522
'with a working tree.',
4523
checkout='Reconfigure to be a bound branch '
4524
'with a working tree.',
4525
lightweight_checkout='Reconfigure to be a lightweight'
4526
' checkout (with no local history).',
4527
standalone='Reconfigure to be a standalone branch '
4528
'(i.e. stop using shared repository).',
4529
use_shared='Reconfigure to use a shared repository.'),
4530
Option('bind-to', help='Branch to bind checkout to.',
4533
help='Perform reconfiguration even if local changes'
5444
RegistryOption.from_kwargs(
5446
title='Target type',
5447
help='The type to reconfigure the directory to.',
5448
value_switches=True, enum_switch=False,
5449
branch='Reconfigure to be an unbound branch with no working tree.',
5450
tree='Reconfigure to be an unbound branch with a working tree.',
5451
checkout='Reconfigure to be a bound branch with a working tree.',
5452
lightweight_checkout='Reconfigure to be a lightweight'
5453
' checkout (with no local history).',
5454
standalone='Reconfigure to be a standalone branch '
5455
'(i.e. stop using shared repository).',
5456
use_shared='Reconfigure to use a shared repository.',
5457
with_trees='Reconfigure repository to create '
5458
'working trees on branches by default.',
5459
with_no_trees='Reconfigure repository to not create '
5460
'working trees on branches by default.'
5462
Option('bind-to', help='Branch to bind checkout to.', type=str),
5464
help='Perform reconfiguration even if local changes'
5466
Option('stacked-on',
5467
help='Reconfigure a branch to be stacked on another branch.',
5471
help='Reconfigure a branch to be unstacked. This '
5472
'may require copying substantial data into it.',
4537
def run(self, location=None, target_type=None, bind_to=None, force=False):
5476
def run(self, location=None, target_type=None, bind_to=None, force=False,
4538
5479
directory = bzrdir.BzrDir.open(location)
5480
if stacked_on and unstacked:
5481
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5482
elif stacked_on is not None:
5483
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5485
reconfigure.ReconfigureUnstacked().apply(directory)
5486
# At the moment you can use --stacked-on and a different
5487
# reconfiguration shape at the same time; there seems no good reason
4539
5489
if target_type is None:
4540
raise errors.BzrCommandError('No target configuration specified')
5490
if stacked_on or unstacked:
5493
raise errors.BzrCommandError('No target configuration '
4541
5495
elif target_type == 'branch':
4542
5496
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
4543
5497
elif target_type == 'tree':
4544
5498
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4545
5499
elif target_type == 'checkout':
4546
reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
5500
reconfiguration = reconfigure.Reconfigure.to_checkout(
4548
5502
elif target_type == 'lightweight-checkout':
4549
5503
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
4550
5504
directory, bind_to)
4572
5532
directory of the current branch. For example, if you are currently in a
4573
5533
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
4574
5534
/path/to/newbranch.
5536
Bound branches use the nickname of its master branch unless it is set
5537
locally, in which case switching will update the local nickname to be
4577
takes_args = ['to_location']
5541
takes_args = ['to_location?']
4578
5542
takes_options = [Option('force',
4579
help='Switch even if local commits will be lost.')
5543
help='Switch even if local commits will be lost.'),
5545
Option('create-branch', short_name='b',
5546
help='Create the target branch from this one before'
5547
' switching to it.'),
4582
def run(self, to_location, force=False):
5550
def run(self, to_location=None, force=False, create_branch=False,
4583
5552
from bzrlib import switch
4584
5553
tree_location = '.'
5554
revision = _get_one_revision('switch', revision)
4585
5555
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5556
if to_location is None:
5557
if revision is None:
5558
raise errors.BzrCommandError('You must supply either a'
5559
' revision or a location')
4587
to_branch = Branch.open(to_location)
5562
branch = control_dir.open_branch()
5563
had_explicit_nick = branch.get_config().has_explicit_nickname()
4588
5564
except errors.NotBranchError:
5566
had_explicit_nick = False
5569
raise errors.BzrCommandError('cannot create branch without'
5571
to_location = directory_service.directories.dereference(
5573
if '/' not in to_location and '\\' not in to_location:
5574
# This path is meant to be relative to the existing branch
5575
this_url = self._get_branch_location(control_dir)
5576
to_location = urlutils.join(this_url, '..', to_location)
5577
to_branch = branch.bzrdir.sprout(to_location,
5578
possible_transports=[branch.bzrdir.root_transport],
5579
source_branch=branch).open_branch()
5582
to_branch = Branch.open(to_location)
5583
except errors.NotBranchError:
5584
this_url = self._get_branch_location(control_dir)
5585
to_branch = Branch.open(
5586
urlutils.join(this_url, '..', to_location))
5587
if revision is not None:
5588
revision = revision.as_revision_id(to_branch)
5589
switch.switch(control_dir, to_branch, force, revision_id=revision)
5590
if had_explicit_nick:
5591
branch = control_dir.open_branch() #get the new branch!
5592
branch.nick = to_branch.nick
5593
note('Switched to branch: %s',
5594
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5596
def _get_branch_location(self, control_dir):
5597
"""Return location of branch for this control dir."""
4589
5599
this_branch = control_dir.open_branch()
4590
5600
# This may be a heavy checkout, where we want the master branch
4591
this_url = this_branch.get_bound_location()
5601
master_location = this_branch.get_bound_location()
5602
if master_location is not None:
5603
return master_location
4592
5604
# If not, use a local sibling
4593
if this_url is None:
4594
this_url = this_branch.base
4595
to_branch = Branch.open(
4596
urlutils.join(this_url, '..', to_location))
4597
switch.switch(control_dir, to_branch, force)
4598
note('Switched to branch: %s',
4599
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5605
return this_branch.base
5606
except errors.NotBranchError:
5607
format = control_dir.find_branch_format()
5608
if getattr(format, 'get_reference', None) is not None:
5609
return format.get_reference(control_dir)
5611
return control_dir.root_transport.base
5614
class cmd_view(Command):
5615
"""Manage filtered views.
5617
Views provide a mask over the tree so that users can focus on
5618
a subset of a tree when doing their work. After creating a view,
5619
commands that support a list of files - status, diff, commit, etc -
5620
effectively have that list of files implicitly given each time.
5621
An explicit list of files can still be given but those files
5622
must be within the current view.
5624
In most cases, a view has a short life-span: it is created to make
5625
a selected change and is deleted once that change is committed.
5626
At other times, you may wish to create one or more named views
5627
and switch between them.
5629
To disable the current view without deleting it, you can switch to
5630
the pseudo view called ``off``. This can be useful when you need
5631
to see the whole tree for an operation or two (e.g. merge) but
5632
want to switch back to your view after that.
5635
To define the current view::
5637
bzr view file1 dir1 ...
5639
To list the current view::
5643
To delete the current view::
5647
To disable the current view without deleting it::
5649
bzr view --switch off
5651
To define a named view and switch to it::
5653
bzr view --name view-name file1 dir1 ...
5655
To list a named view::
5657
bzr view --name view-name
5659
To delete a named view::
5661
bzr view --name view-name --delete
5663
To switch to a named view::
5665
bzr view --switch view-name
5667
To list all views defined::
5671
To delete all views::
5673
bzr view --delete --all
5677
takes_args = ['file*']
5680
help='Apply list or delete action to all views.',
5683
help='Delete the view.',
5686
help='Name of the view to define, list or delete.',
5690
help='Name of the view to switch to.',
5695
def run(self, file_list,
5701
tree, file_list = tree_files(file_list, apply_view=False)
5702
current_view, view_dict = tree.views.get_view_info()
5707
raise errors.BzrCommandError(
5708
"Both --delete and a file list specified")
5710
raise errors.BzrCommandError(
5711
"Both --delete and --switch specified")
5713
tree.views.set_view_info(None, {})
5714
self.outf.write("Deleted all views.\n")
5716
raise errors.BzrCommandError("No current view to delete")
5718
tree.views.delete_view(name)
5719
self.outf.write("Deleted '%s' view.\n" % name)
5722
raise errors.BzrCommandError(
5723
"Both --switch and a file list specified")
5725
raise errors.BzrCommandError(
5726
"Both --switch and --all specified")
5727
elif switch == 'off':
5728
if current_view is None:
5729
raise errors.BzrCommandError("No current view to disable")
5730
tree.views.set_view_info(None, view_dict)
5731
self.outf.write("Disabled '%s' view.\n" % (current_view))
5733
tree.views.set_view_info(switch, view_dict)
5734
view_str = views.view_display_str(tree.views.lookup_view())
5735
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5738
self.outf.write('Views defined:\n')
5739
for view in sorted(view_dict):
5740
if view == current_view:
5744
view_str = views.view_display_str(view_dict[view])
5745
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5747
self.outf.write('No views defined.\n')
5750
# No name given and no current view set
5753
raise errors.BzrCommandError(
5754
"Cannot change the 'off' pseudo view")
5755
tree.views.set_view(name, sorted(file_list))
5756
view_str = views.view_display_str(tree.views.lookup_view())
5757
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5761
# No name given and no current view set
5762
self.outf.write('No current view.\n')
5764
view_str = views.view_display_str(tree.views.lookup_view(name))
5765
self.outf.write("'%s' view is: %s\n" % (name, view_str))
4602
5768
class cmd_hooks(Command):
4603
"""Show a branch's currently registered hooks.
4607
takes_args = ['path?']
4609
def run(self, path=None):
5774
for hook_key in sorted(hooks.known_hooks.keys()):
5775
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5776
self.outf.write("%s:\n" % type(some_hooks).__name__)
5777
for hook_name, hook_point in sorted(some_hooks.items()):
5778
self.outf.write(" %s:\n" % (hook_name,))
5779
found_hooks = list(hook_point)
5781
for hook in found_hooks:
5782
self.outf.write(" %s\n" %
5783
(some_hooks.get_hook_name(hook),))
5785
self.outf.write(" <no hooks installed>\n")
5788
class cmd_remove_branch(Command):
5791
This will remove the branch from the specified location but
5792
will keep any working tree or repository in place.
5796
Remove the branch at repo/trunk::
5798
bzr remove-branch repo/trunk
5802
takes_args = ["location?"]
5804
aliases = ["rmbranch"]
5806
def run(self, location=None):
5807
if location is None:
5809
branch = Branch.open_containing(location)[0]
5810
branch.bzrdir.destroy_branch()
5813
class cmd_shelve(Command):
5814
"""Temporarily set aside some changes from the current tree.
5816
Shelve allows you to temporarily put changes you've made "on the shelf",
5817
ie. out of the way, until a later time when you can bring them back from
5818
the shelf with the 'unshelve' command. The changes are stored alongside
5819
your working tree, and so they aren't propagated along with your branch nor
5820
will they survive its deletion.
5822
If shelve --list is specified, previously-shelved changes are listed.
5824
Shelve is intended to help separate several sets of changes that have
5825
been inappropriately mingled. If you just want to get rid of all changes
5826
and you don't need to restore them later, use revert. If you want to
5827
shelve all text changes at once, use shelve --all.
5829
If filenames are specified, only the changes to those files will be
5830
shelved. Other files will be left untouched.
5832
If a revision is specified, changes since that revision will be shelved.
5834
You can put multiple items on the shelf, and by default, 'unshelve' will
5835
restore the most recently shelved changes.
5838
takes_args = ['file*']
5842
Option('all', help='Shelve all changes.'),
5844
RegistryOption('writer', 'Method to use for writing diffs.',
5845
bzrlib.option.diff_writer_registry,
5846
value_switches=True, enum_switch=False),
5848
Option('list', help='List shelved changes.'),
5850
help='Destroy removed changes instead of shelving them.'),
5852
_see_also = ['unshelve']
5854
def run(self, revision=None, all=False, file_list=None, message=None,
5855
writer=None, list=False, destroy=False):
5857
return self.run_for_list()
5858
from bzrlib.shelf_ui import Shelver
5860
writer = bzrlib.option.diff_writer_registry.get()
5862
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5863
file_list, message, destroy=destroy)
5868
except errors.UserAbort:
5871
def run_for_list(self):
5872
tree = WorkingTree.open_containing('.')[0]
5874
self.add_cleanup(tree.unlock)
5875
manager = tree.get_shelf_manager()
5876
shelves = manager.active_shelves()
5877
if len(shelves) == 0:
5878
note('No shelved changes.')
5880
for shelf_id in reversed(shelves):
5881
message = manager.get_metadata(shelf_id).get('message')
5883
message = '<no message>'
5884
self.outf.write('%3d: %s\n' % (shelf_id, message))
5888
class cmd_unshelve(Command):
5889
"""Restore shelved changes.
5891
By default, the most recently shelved changes are restored. However if you
5892
specify a shelf by id those changes will be restored instead. This works
5893
best when the changes don't depend on each other.
5896
takes_args = ['shelf_id?']
5898
RegistryOption.from_kwargs(
5899
'action', help="The action to perform.",
5900
enum_switch=False, value_switches=True,
5901
apply="Apply changes and remove from the shelf.",
5902
dry_run="Show changes, but do not apply or remove them.",
5903
preview="Instead of unshelving the changes, show the diff that "
5904
"would result from unshelving.",
5905
delete_only="Delete changes without applying them.",
5906
keep="Apply changes but don't delete them.",
5909
_see_also = ['shelve']
5911
def run(self, shelf_id=None, action='apply'):
5912
from bzrlib.shelf_ui import Unshelver
5913
unshelver = Unshelver.from_args(shelf_id, action)
5917
unshelver.tree.unlock()
5920
class cmd_clean_tree(Command):
5921
"""Remove unwanted files from working tree.
5923
By default, only unknown files, not ignored files, are deleted. Versioned
5924
files are never deleted.
5926
Another class is 'detritus', which includes files emitted by bzr during
5927
normal operations and selftests. (The value of these files decreases with
5930
If no options are specified, unknown files are deleted. Otherwise, option
5931
flags are respected, and may be combined.
5933
To check what clean-tree will do, use --dry-run.
5935
takes_options = [Option('ignored', help='Delete all ignored files.'),
5936
Option('detritus', help='Delete conflict files, merge'
5937
' backups, and failed selftest dirs.'),
5939
help='Delete files unknown to bzr (default).'),
5940
Option('dry-run', help='Show files to delete instead of'
5942
Option('force', help='Do not prompt before deleting.')]
5943
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5945
from bzrlib.clean_tree import clean_tree
5946
if not (unknown or ignored or detritus):
5950
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5951
dry_run=dry_run, no_prompt=force)
5954
class cmd_reference(Command):
5955
"""list, view and set branch locations for nested trees.
5957
If no arguments are provided, lists the branch locations for nested trees.
5958
If one argument is provided, display the branch location for that tree.
5959
If two arguments are provided, set the branch location for that tree.
5964
takes_args = ['path?', 'location?']
5966
def run(self, path=None, location=None):
5968
if path is not None:
5970
tree, branch, relpath =(
5971
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5972
if path is not None:
5975
tree = branch.basis_tree()
4610
5976
if path is None:
4612
branch_hooks = Branch.open(path).hooks
4613
for hook_type in branch_hooks:
4614
hooks = branch_hooks[hook_type]
4615
self.outf.write("%s:\n" % (hook_type,))
4618
self.outf.write(" %s\n" %
4619
(branch_hooks.get_hook_name(hook),))
5977
info = branch._get_all_reference_info().iteritems()
5978
self._display_reference_info(tree, branch, info)
5980
file_id = tree.path2id(path)
5982
raise errors.NotVersionedError(path)
5983
if location is None:
5984
info = [(file_id, branch.get_reference_info(file_id))]
5985
self._display_reference_info(tree, branch, info)
4621
self.outf.write(" <no hooks installed>\n")
4624
def _create_prefix(cur_transport):
4625
needed = [cur_transport]
4626
# Recurse upwards until we can create a directory successfully
4628
new_transport = cur_transport.clone('..')
4629
if new_transport.base == cur_transport.base:
4630
raise errors.BzrCommandError(
4631
"Failed to create path prefix for %s."
4632
% cur_transport.base)
4634
new_transport.mkdir('.')
4635
except errors.NoSuchFile:
4636
needed.append(new_transport)
4637
cur_transport = new_transport
4640
# Now we only need to create child directories
4642
cur_transport = needed.pop()
4643
cur_transport.ensure_base()
4646
# these get imported and then picked up by the scan for cmd_*
4647
# TODO: Some more consistent way to split command definitions across files;
4648
# we do need to load at least some information about them to know of
4649
# aliases. ideally we would avoid loading the implementation until the
4650
# details were needed.
4651
from bzrlib.cmd_version_info import cmd_version_info
4652
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
4653
from bzrlib.bundle.commands import (
4656
from bzrlib.sign_my_commits import cmd_sign_my_commits
4657
from bzrlib.weave_commands import cmd_versionedfile_list, \
4658
cmd_weave_plan_merge, cmd_weave_merge_text
5987
branch.set_reference_info(file_id, path, location)
5989
def _display_reference_info(self, tree, branch, info):
5991
for file_id, (path, location) in info:
5993
path = tree.id2path(file_id)
5994
except errors.NoSuchId:
5996
ref_list.append((path, location))
5997
for path, location in sorted(ref_list):
5998
self.outf.write('%s %s\n' % (path, location))
6001
def _register_lazy_builtins():
6002
# register lazy builtins from other modules; called at startup and should
6003
# be only called once.
6004
for (name, aliases, module_name) in [
6005
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6006
('cmd_dpush', [], 'bzrlib.foreign'),
6007
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6008
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6009
('cmd_conflicts', [], 'bzrlib.conflicts'),
6010
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6012
builtin_command_registry.register_lazy(name, aliases, module_name)