59
59
from bzrlib.trace import mutter, note, warning, is_quiet, info
62
def tree_files(file_list, default_branch=u'.'):
62
def tree_files(file_list, default_branch=u'.', apply_view=True):
64
return internal_tree_files(file_list, default_branch)
64
return internal_tree_files(file_list, default_branch, apply_view)
65
65
except errors.FileInWrongBranch, e:
66
66
raise errors.BzrCommandError("%s is not in the same branch as %s" %
67
67
(e.path, file_list[0]))
82
82
:param default_branch: Fallback tree path to use if file_list is empty or
85
:param apply_view: if True and a view is set, apply it or check that
86
specified files are within it
85
88
:return: workingtree, [relative_paths]
87
90
if file_list is None or len(file_list) == 0:
88
return WorkingTree.open_containing(default_branch)[0], file_list
91
tree = WorkingTree.open_containing(default_branch)[0]
92
if tree.supports_views() and apply_view:
93
view_files = tree.views.lookup_view()
95
file_list = view_files
96
view_str = ", ".join(view_files)
97
note("ignoring files outside view: %s" % view_str)
98
return tree, file_list
89
99
tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
100
if tree.supports_views() and apply_view:
101
view_files = tree.views.lookup_view()
91
105
for filename in file_list:
93
new_list.append(tree.relpath(osutils.dereference_path(filename)))
107
relpath = tree.relpath(osutils.dereference_path(filename))
108
if view_files and not is_inside_any(view_files, relpath):
109
raise errors.FileOutsideView(filename, view_files)
110
new_list.append(relpath)
94
111
except errors.PathNotChild:
95
112
raise errors.FileInWrongBranch(tree.branch, filename)
96
113
return tree, new_list
4488
4505
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4508
class cmd_view(Command):
4509
"""Manage filtered views.
4511
Views provide a mask over the tree so that users can focus on
4512
a subset of a tree when doing their work. After creating a view,
4513
commands that support a list of files - status, diff, commit, etc -
4514
effectively have that list of files implicitly given each time.
4515
An explicit list of files can still be given but those files
4516
must be within the current view.
4518
In most cases, a view has a short life-span: it is created to make
4519
a selected change and is deleted once that change is committed.
4520
At other times, you may wish to create one or more named views
4521
and switch between them. To see the list of named views defined
4522
for a tree, use the ``info`` command.
4524
To disable the current view without deleting it, you can switch to
4525
the pseudo view called ``off``. This can be useful when you need
4526
to see the whole tree for an operation or two (e.g. merge) but
4527
want to switch back to your view after that.
4530
To change the current view::
4532
bzr view file1 dir1 ...
4534
To list the current view::
4538
To delete the current view::
4542
To disable the current view without deleting it::
4544
bzr view --switch off
4546
To change a named view and switch to it::
4548
bzr view --name view-name file1 dir1 ...
4550
To list a named view::
4552
bzr view --name view-name
4554
To delete a named view::
4556
bzr view --name view-name --delete
4558
To switch to a named view::
4560
bzr view --switch view-name
4563
_see_also = ['info']
4564
takes_args = ['file*']
4567
help='Delete the view.',
4570
help='Name of the view to list, save or delete.',
4574
help='Name of the view to switch to.',
4579
def run(self, file_list,
4584
tree, file_list = tree_files(file_list, apply_view=False)
4585
current_view, view_dict = tree.views.get_view_info()
4590
raise BzrCommandError("Both --delete and a file list specified")
4592
raise BzrCommandError("Both --delete and --switch specified")
4594
raise BzrCommandError("No current view to delete")
4596
tree.views.delete_view(name)
4597
self.outf.write("Deleted '%s' view.\n" % name)
4600
raise BzrCommandError("Both --switch and a file list specified")
4601
elif switch == 'off':
4602
if current_view is None:
4603
raise BzrCommandError("No current view to disable")
4604
tree.views.set_view_info(None, view_dict)
4605
self.outf.write("Disabled '%s' view.\n" % (switch))
4607
tree.views.set_view_info(switch, view_dict)
4608
view_str = ", ".join(tree.views.lookup_view())
4609
self.outf.write("Switched to '%s' view: %s\n" % (switch,view_str))
4612
# No name given and no current view set
4615
raise BzrCommandError("Cannot change the 'off' pseudo view")
4616
tree.views.set_view(name, sorted(file_list))
4617
view_str = ", ".join(tree.views.lookup_view())
4618
self.outf.write("Switched to '%s' view: %s\n" % (name, view_str))
4621
if current_view is None:
4622
self.outf.write('No current view.\n')
4624
view_str = ", ".join(tree.views.lookup_view(name))
4625
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
4491
4628
class cmd_hooks(Command):
4492
4629
"""Show a branch's currently registered hooks.