122
122
def _get_one_revision_tree(command_name, revisions, branch=None, tree=None):
123
"""Get a revision tree. Not suitable for commands that change the tree.
125
Specifically, the basis tree in dirstate trees is coupled to the dirstate
126
and doing a commit/uncommit/pull will at best fail due to changing the
129
If tree is passed in, it should be already locked, for lifetime management
130
of the trees internal cached state.
123
132
if branch is None:
124
133
branch = tree.branch
125
134
if revisions is None:
616
628
help='Lookup file ids from this tree.'),
618
630
encoding_type = 'replace'
619
_see_also = ['remove']
631
_see_also = ['remove', 'ignore']
621
633
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
622
634
file_ids_from=None):
654
666
for path in ignored[glob]:
655
667
self.outf.write("ignored %s matching \"%s\"\n"
659
for glob, paths in ignored.items():
660
match_len += len(paths)
661
self.outf.write("ignored %d file(s).\n" % match_len)
662
self.outf.write("If you wish to add ignored files, "
663
"please add them explicitly by name. "
664
"(\"bzr ignored\" gives a list)\n")
667
671
class cmd_mkdir(Command):
1172
1176
help='Hard-link working tree files where possible.'),
1173
1177
Option('no-tree',
1174
1178
help="Create a branch without a working-tree."),
1180
help="Switch the checkout in the current directory "
1181
"to the new branch."),
1175
1182
Option('stacked',
1176
1183
help='Create a stacked branch referring to the source branch. '
1177
1184
'The new branch will depend on the availability of the source '
1189
1196
def run(self, from_location, to_location=None, revision=None,
1190
1197
hardlink=False, stacked=False, standalone=False, no_tree=False,
1191
use_existing_dir=False):
1198
use_existing_dir=False, switch=False):
1199
from bzrlib import switch as _mod_switch
1192
1200
from bzrlib.tag import _merge_tags_if_possible
1194
1201
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1196
1203
if (accelerator_tree is not None and
1250
1257
except (errors.NotStacked, errors.UnstackableBranchFormat,
1251
1258
errors.UnstackableRepositoryFormat), e:
1252
1259
note('Branched %d revision(s).' % branch.revno())
1261
# Switch to the new branch
1262
wt, _ = WorkingTree.open_containing('.')
1263
_mod_switch.switch(wt.bzrdir, branch)
1264
note('Switched to branch: %s',
1265
urlutils.unescape_for_display(branch.base, 'utf-8'))
1254
1267
br_from.unlock()
1472
1485
title='Deletion Strategy', value_switches=True, enum_switch=False,
1473
1486
safe='Only delete files if they can be'
1474
1487
' safely recovered (default).',
1475
keep="Don't delete any files.",
1488
keep='Delete from bzr but leave the working copy.',
1476
1489
force='Delete all the specified files, even if they can not be '
1477
1490
'recovered and even if they are non-empty directories.')]
1478
1491
aliases = ['rm', 'del']
1660
1673
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1661
1674
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1662
1675
value_switches=True,
1663
title="Branch Format",
1676
title="Branch format",
1665
1678
Option('append-revisions-only',
1666
1679
help='Never change revnos or the existing log.'
2263
2276
filter_by_dir = False
2265
# find the file ids to log and check for directory filtering
2266
b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2268
for relpath, file_id, kind in file_info_list:
2270
raise errors.BzrCommandError(
2271
"Path unknown at end or start of revision range: %s" %
2273
# If the relpath is the top of the tree, we log everything
2280
# find the file ids to log and check for directory filtering
2281
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2282
revision, file_list)
2283
for relpath, file_id, kind in file_info_list:
2285
raise errors.BzrCommandError(
2286
"Path unknown at end or start of revision range: %s" %
2288
# If the relpath is the top of the tree, we log everything
2293
file_ids.append(file_id)
2294
filter_by_dir = filter_by_dir or (
2295
kind in ['directory', 'tree-reference'])
2298
# FIXME ? log the current subdir only RBC 20060203
2299
if revision is not None \
2300
and len(revision) > 0 and revision[0].get_branch():
2301
location = revision[0].get_branch()
2278
file_ids.append(file_id)
2279
filter_by_dir = filter_by_dir or (
2280
kind in ['directory', 'tree-reference'])
2283
# FIXME ? log the current subdir only RBC 20060203
2284
if revision is not None \
2285
and len(revision) > 0 and revision[0].get_branch():
2286
location = revision[0].get_branch()
2289
dir, relpath = bzrdir.BzrDir.open_containing(location)
2290
b = dir.open_branch()
2291
rev1, rev2 = _get_revision_range(revision, b, self.name())
2293
# Decide on the type of delta & diff filtering to use
2294
# TODO: add an --all-files option to make this configurable & consistent
2302
diff_type = 'partial'
2304
dir, relpath = bzrdir.BzrDir.open_containing(location)
2305
b = dir.open_branch()
2307
rev1, rev2 = _get_revision_range(revision, b, self.name())
2309
# Decide on the type of delta & diff filtering to use
2310
# TODO: add an --all-files option to make this configurable & consistent
2318
diff_type = 'partial'
2308
2322
# Build the log formatter
2309
2323
if log_format is None:
2310
2324
log_format = log.log_formatter_registry.get_default(b)
2410
2425
@display_command
2411
2426
def run(self, filename):
2412
2427
tree, relpath = WorkingTree.open_containing(filename)
2428
file_id = tree.path2id(relpath)
2413
2429
b = tree.branch
2414
file_id = tree.path2id(relpath)
2415
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
2416
self.outf.write("%6d %s\n" % (revno, what))
2432
touching_revs = log.find_touching_revisions(b, file_id)
2433
for revno, revision_id, what in touching_revs:
2434
self.outf.write("%6d %s\n" % (revno, what))
2419
2439
class cmd_ls(Command):
3025
3045
raise errors.BzrCommandError("empty commit message specified")
3026
3046
return my_message
3048
# The API permits a commit with a filter of [] to mean 'select nothing'
3049
# but the command line should not do that.
3050
if not selected_list:
3051
selected_list = None
3029
3053
tree.commit(message_callback=get_message,
3030
3054
specific_files=selected_list,
4385
4409
branch.lock_read()
4387
4411
tree = _get_one_revision_tree('annotate', revision, branch=branch)
4389
file_id = wt.path2id(relpath)
4391
file_id = tree.path2id(relpath)
4393
raise errors.NotVersionedError(filename)
4394
file_version = tree.inventory[file_id].revision
4395
if wt is not None and revision is None:
4396
# If there is a tree and we're not annotating historical
4397
# versions, annotate the working tree's content.
4398
annotate_file_tree(wt, file_id, self.outf, long, all,
4401
annotate_file(branch, file_version, file_id, long, all, self.outf,
4415
file_id = wt.path2id(relpath)
4417
file_id = tree.path2id(relpath)
4419
raise errors.NotVersionedError(filename)
4420
file_version = tree.inventory[file_id].revision
4421
if wt is not None and revision is None:
4422
# If there is a tree and we're not annotating historical
4423
# versions, annotate the working tree's content.
4424
annotate_file_tree(wt, file_id, self.outf, long, all,
4427
annotate_file(branch, file_version, file_id, long, all,
4428
self.outf, show_ids=show_ids)
4404
4432
if wt is not None:
5260
5288
Option('bind-to', help='Branch to bind checkout to.', type=str),
5261
5289
Option('force',
5262
help='Perform reconfiguration even if local changes'
5290
help='Perform reconfiguration even if local changes'
5292
Option('stacked-on',
5293
help='Reconfigure a branch to be stacked on another branch.',
5297
help='Reconfigure a branch to be unstacked. This '
5298
'may require copying substantial data into it.',
5266
def run(self, location=None, target_type=None, bind_to=None, force=False):
5302
def run(self, location=None, target_type=None, bind_to=None, force=False,
5267
5305
directory = bzrdir.BzrDir.open(location)
5306
if stacked_on and unstacked:
5307
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5308
elif stacked_on is not None:
5309
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5311
reconfigure.ReconfigureUnstacked().apply(directory)
5312
# At the moment you can use --stacked-on and a different
5313
# reconfiguration shape at the same time; there seems no good reason
5268
5315
if target_type is None:
5269
raise errors.BzrCommandError('No target configuration specified')
5316
if stacked_on or unstacked:
5319
raise errors.BzrCommandError('No target configuration '
5270
5321
elif target_type == 'branch':
5271
5322
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5272
5323
elif target_type == 'tree':
5604
5655
if writer is None:
5605
5656
writer = bzrlib.option.diff_writer_registry.get()
5607
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5608
message, destroy=destroy).run()
5658
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5659
file_list, message, destroy=destroy)
5663
shelver.work_tree.unlock()
5609
5664
except errors.UserAbort:
5651
5706
def run(self, shelf_id=None, action='apply'):
5652
5707
from bzrlib.shelf_ui import Unshelver
5653
Unshelver.from_args(shelf_id, action).run()
5708
unshelver = Unshelver.from_args(shelf_id, action)
5712
unshelver.tree.unlock()
5656
5715
class cmd_clean_tree(Command):