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:
1167
1176
help='Hard-link working tree files where possible.'),
1168
1177
Option('no-tree',
1169
1178
help="Create a branch without a working-tree."),
1180
help="Switch the checkout in the current directory "
1181
"to the new branch."),
1170
1182
Option('stacked',
1171
1183
help='Create a stacked branch referring to the source branch. '
1172
1184
'The new branch will depend on the availability of the source '
1184
1196
def run(self, from_location, to_location=None, revision=None,
1185
1197
hardlink=False, stacked=False, standalone=False, no_tree=False,
1186
use_existing_dir=False):
1198
use_existing_dir=False, switch=False):
1199
from bzrlib import switch as _mod_switch
1187
1200
from bzrlib.tag import _merge_tags_if_possible
1189
1201
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1191
1203
if (accelerator_tree is not None and
1245
1257
except (errors.NotStacked, errors.UnstackableBranchFormat,
1246
1258
errors.UnstackableRepositoryFormat), e:
1247
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'))
1249
1267
br_from.unlock()
1655
1673
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1656
1674
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1657
1675
value_switches=True,
1658
title="Branch Format",
1676
title="Branch format",
1660
1678
Option('append-revisions-only',
1661
1679
help='Never change revnos or the existing log.'
2258
2276
filter_by_dir = False
2260
# find the file ids to log and check for directory filtering
2261
b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2263
for relpath, file_id, kind in file_info_list:
2265
raise errors.BzrCommandError(
2266
"Path unknown at end or start of revision range: %s" %
2268
# 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()
2273
file_ids.append(file_id)
2274
filter_by_dir = filter_by_dir or (
2275
kind in ['directory', 'tree-reference'])
2278
# FIXME ? log the current subdir only RBC 20060203
2279
if revision is not None \
2280
and len(revision) > 0 and revision[0].get_branch():
2281
location = revision[0].get_branch()
2284
dir, relpath = bzrdir.BzrDir.open_containing(location)
2285
b = dir.open_branch()
2286
rev1, rev2 = _get_revision_range(revision, b, self.name())
2288
# Decide on the type of delta & diff filtering to use
2289
# TODO: add an --all-files option to make this configurable & consistent
2297
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'
2303
2322
# Build the log formatter
2304
2323
if log_format is None:
2305
2324
log_format = log.log_formatter_registry.get_default(b)
2405
2425
@display_command
2406
2426
def run(self, filename):
2407
2427
tree, relpath = WorkingTree.open_containing(filename)
2428
file_id = tree.path2id(relpath)
2408
2429
b = tree.branch
2409
file_id = tree.path2id(relpath)
2410
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
2411
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))
2414
2439
class cmd_ls(Command):
3020
3045
raise errors.BzrCommandError("empty commit message specified")
3021
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
3024
3053
tree.commit(message_callback=get_message,
3025
3054
specific_files=selected_list,
4380
4409
branch.lock_read()
4382
4411
tree = _get_one_revision_tree('annotate', revision, branch=branch)
4384
file_id = wt.path2id(relpath)
4386
file_id = tree.path2id(relpath)
4388
raise errors.NotVersionedError(filename)
4389
file_version = tree.inventory[file_id].revision
4390
if wt is not None and revision is None:
4391
# If there is a tree and we're not annotating historical
4392
# versions, annotate the working tree's content.
4393
annotate_file_tree(wt, file_id, self.outf, long, all,
4396
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)
4399
4432
if wt is not None:
5622
5655
if writer is None:
5623
5656
writer = bzrlib.option.diff_writer_registry.get()
5625
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5626
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()
5627
5664
except errors.UserAbort:
5669
5706
def run(self, shelf_id=None, action='apply'):
5670
5707
from bzrlib.shelf_ui import Unshelver
5671
Unshelver.from_args(shelf_id, action).run()
5708
unshelver = Unshelver.from_args(shelf_id, action)
5712
unshelver.tree.unlock()
5674
5715
class cmd_clean_tree(Command):