65
66
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
68
def tree_files(file_list, default_branch=u'.', canonicalize=True):
69
def tree_files(file_list, default_branch=u'.', canonicalize=True,
70
return internal_tree_files(file_list, default_branch, canonicalize)
72
return internal_tree_files(file_list, default_branch, canonicalize,
71
74
except errors.FileInWrongBranch, e:
72
75
raise errors.BzrCommandError("%s is not in the same branch as %s" %
73
76
(e.path, file_list[0]))
79
def tree_files_for_add(file_list):
80
"""Add handles files a bit differently so it a custom implementation."""
82
tree = WorkingTree.open_containing(file_list[0])[0]
83
if tree.supports_views():
84
view_files = tree.views.lookup_view()
85
for filename in file_list:
86
if not osutils.is_inside_any(view_files, filename):
87
raise errors.FileOutsideView(filename, view_files)
89
tree = WorkingTree.open_containing(u'.')[0]
90
if tree.supports_views():
91
view_files = tree.views.lookup_view()
93
file_list = view_files
94
view_str = views.view_display_str(view_files)
95
note("ignoring files outside view: %s" % view_str)
96
return tree, file_list
76
99
def _get_one_revision(command_name, revisions):
77
100
if revisions is None:
108
132
The filenames given are not required to exist.
110
:param file_list: Filenames to convert.
134
:param file_list: Filenames to convert.
112
136
:param default_branch: Fallback tree path to use if file_list is empty or
139
:param apply_view: if True and a view is set, apply it or check that
140
specified files are within it
115
142
:return: workingtree, [relative_paths]
117
144
if file_list is None or len(file_list) == 0:
118
return WorkingTree.open_containing(default_branch)[0], file_list
145
tree = WorkingTree.open_containing(default_branch)[0]
146
if tree.supports_views() and apply_view:
147
view_files = tree.views.lookup_view()
149
file_list = view_files
150
view_str = views.view_display_str(view_files)
151
note("ignoring files outside view: %s" % view_str)
152
return tree, file_list
119
153
tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
120
return tree, safe_relpath_files(tree, file_list, canonicalize)
123
def safe_relpath_files(tree, file_list, canonicalize=True):
154
return tree, safe_relpath_files(tree, file_list, canonicalize,
155
apply_view=apply_view)
158
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
124
159
"""Convert file_list into a list of relpaths in tree.
126
161
:param tree: A tree to operate on.
127
162
:param file_list: A list of user provided paths or None.
163
:param apply_view: if True and a view is set, apply it or check that
164
specified files are within it
128
165
:return: A list of relative paths.
129
166
:raises errors.PathNotChild: When a provided path is in a different tree
132
169
if file_list is None:
171
if tree.supports_views() and apply_view:
172
view_files = tree.views.lookup_view()
135
176
# tree.relpath exists as a "thunk" to osutils, but canonical_relpath
136
177
# doesn't - fix that up here before we enter the loop.
1824
1880
class cmd_log(Command):
1825
"""Show log of a branch, file, or directory.
1827
By default show the log of the branch containing the working directory.
1829
To request a range of logs, you can use the command -r begin..end
1830
-r revision requests a specific revision, -r ..end or -r begin.. are
1834
Log the current branch::
1842
Log the last 10 revisions of a branch::
1844
bzr log -r -10.. http://server/branch
1881
"""Show historical log for a branch or subset of a branch.
1883
log is bzr's default tool for exploring the history of a branch.
1884
The branch to use is taken from the first parameter. If no parameters
1885
are given, the branch containing the working directory is logged.
1886
Here are some simple examples::
1888
bzr log log the current branch
1889
bzr log foo.py log a file in its branch
1890
bzr log http://server/branch log a branch on a server
1892
The filtering, ordering and information shown for each revision can
1893
be controlled as explained below. By default, all revisions are
1894
shown sorted (topologically) so that newer revisions appear before
1895
older ones and descendants always appear before ancestors. If displayed,
1896
merged revisions are shown indented under the revision in which they
1901
The log format controls how information about each revision is
1902
displayed. The standard log formats are called ``long``, ``short``
1903
and ``line``. The default is long. See ``bzr help log-formats``
1904
for more details on log formats.
1906
The following options can be used to control what information is
1909
-l N display a maximum of N revisions
1910
-n N display N levels of revisions (0 for all, 1 for collapsed)
1911
-v display a status summary (delta) for each revision
1912
-p display a diff (patch) for each revision
1913
--show-ids display revision-ids (and file-ids), not just revnos
1915
Note that the default number of levels to display is a function of the
1916
log format. If the -n option is not used, ``short`` and ``line`` show
1917
just the top level (mainline) while ``long`` shows all levels of merged
1920
Status summaries are shown using status flags like A, M, etc. To see
1921
the changes explained using words like ``added`` and ``modified``
1922
instead, use the -vv option.
1926
To display revisions from oldest to newest, use the --forward option.
1927
In most cases, using this option will have little impact on the total
1928
time taken to produce a log, though --forward does not incrementally
1929
display revisions like --reverse does when it can.
1931
:Revision filtering:
1933
The -r option can be used to specify what revision or range of revisions
1934
to filter against. The various forms are shown below::
1936
-rX display revision X
1937
-rX.. display revision X and later
1938
-r..Y display up to and including revision Y
1939
-rX..Y display from X to Y inclusive
1941
See ``bzr help revisionspec`` for details on how to specify X and Y.
1942
Some common examples are given below::
1944
-r-1 show just the tip
1945
-r-10.. show the last 10 mainline revisions
1946
-rsubmit:.. show what's new on this branch
1947
-rancestor:path.. show changes since the common ancestor of this
1948
branch and the one at location path
1949
-rdate:yesterday.. show changes since yesterday
1951
When logging a range of revisions using -rX..Y, log starts at
1952
revision Y and searches back in history through the primary
1953
("left-hand") parents until it finds X. When logging just the
1954
top level (using -n1), an error is reported if X is not found
1955
along the way. If multi-level logging is used (-n0), X may be
1956
a nested merge revision and the log will be truncated accordingly.
1960
If a parameter is given and it's not a branch, the log will be filtered
1961
to show only those revisions that changed the nominated file or
1964
Filenames are interpreted within their historical context. To log a
1965
deleted file, specify a revision range so that the file existed at
1966
the end or start of the range.
1968
Historical context is also important when interpreting pathnames of
1969
renamed files/directories. Consider the following example:
1971
* revision 1: add tutorial.txt
1972
* revision 2: modify tutorial.txt
1973
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
1977
* ``bzr log guide.txt`` will log the file added in revision 1
1979
* ``bzr log tutorial.txt`` will log the new file added in revision 3
1981
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
1982
the original file in revision 2.
1984
* ``bzr log -r2 -p guide.txt`` will display an error message as there
1985
was no file called guide.txt in revision 2.
1987
Renames are always followed by log. By design, there is no need to
1988
explicitly ask for this (and no way to stop logging a file back
1989
until it was last renamed).
1991
Note: If the path is a directory, only revisions that directly changed
1992
that directory object are currently shown. This is considered a bug.
1993
(Support for filtering against multiple files and for files within a
1994
directory is under development.)
1998
The --message option can be used for finding revisions that match a
1999
regular expression in a commit message.
2003
GUI tools and IDEs are often better at exploring history than command
2004
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
2005
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2006
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2008
Web interfaces are often better at exploring history than command line
2009
tools, particularly for branches on servers. You may prefer Loggerhead
2010
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
2012
You may find it useful to add the aliases below to ``bazaar.conf``::
2016
top = log -r-10.. --short --forward
2017
show = log -v -p -n1 --long
2019
``bzr tip`` will then show the latest revision while ``bzr top``
2020
will show the last 10 mainline revisions. To see the details of a
2021
particular revision X, ``bzr show -rX``.
2023
As many GUI tools and Web interfaces do, you may prefer viewing
2024
history collapsed initially. If you are interested in looking deeper
2025
into a particular merge X, use ``bzr log -n0 -rX``. If you like
2026
working this way, you may wish to either:
2028
* change your default log format to short (or line)
2029
* add this alias: log = log -n1
2031
``bzr log -v`` on a branch with lots of history is currently
2032
very slow. A fix for this issue is currently under development.
2033
With or without that fix, it is recommended that a revision range
2034
be given when using the -v option.
2036
bzr has a generic full-text matching plugin, bzr-search, that can be
2037
used to find revisions matching user names, commit messages, etc.
2038
Among other features, this plugin can find all revisions containing
2039
a list of words but not others.
2041
When exploring non-mainline history on large projects with deep
2042
history, the performance of log can be greatly improved by installing
2043
the revnocache plugin. This plugin buffers historical information
2044
trading disk space for faster speed.
1847
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1849
2046
takes_args = ['location?']
2047
_see_also = ['log-formats', 'revisionspec']
1850
2048
takes_options = [
1851
2049
Option('forward',
1852
2050
help='Show from oldest to newest.'),
4833
5038
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4834
5039
takes_args = ['location?']
4835
takes_options = [RegistryOption.from_kwargs('target_type',
4836
title='Target type',
4837
help='The type to reconfigure the directory to.',
4838
value_switches=True, enum_switch=False,
4839
branch='Reconfigure to be an unbound branch '
4840
'with no working tree.',
4841
tree='Reconfigure to be an unbound branch '
4842
'with a working tree.',
4843
checkout='Reconfigure to be a bound branch '
4844
'with a working tree.',
4845
lightweight_checkout='Reconfigure to be a lightweight'
4846
' checkout (with no local history).',
4847
standalone='Reconfigure to be a standalone branch '
4848
'(i.e. stop using shared repository).',
4849
use_shared='Reconfigure to use a shared repository.'),
4850
Option('bind-to', help='Branch to bind checkout to.',
4853
help='Perform reconfiguration even if local changes'
5041
RegistryOption.from_kwargs(
5043
title='Target type',
5044
help='The type to reconfigure the directory to.',
5045
value_switches=True, enum_switch=False,
5046
branch='Reconfigure to be an unbound branch with no working tree.',
5047
tree='Reconfigure to be an unbound branch with a working tree.',
5048
checkout='Reconfigure to be a bound branch with a working tree.',
5049
lightweight_checkout='Reconfigure to be a lightweight'
5050
' checkout (with no local history).',
5051
standalone='Reconfigure to be a standalone branch '
5052
'(i.e. stop using shared repository).',
5053
use_shared='Reconfigure to use a shared repository.',
5054
with_trees='Reconfigure repository to create '
5055
'working trees on branches by default.',
5056
with_no_trees='Reconfigure repository to not create '
5057
'working trees on branches by default.'
5059
Option('bind-to', help='Branch to bind checkout to.', type=str),
5061
help='Perform reconfiguration even if local changes'
4857
5065
def run(self, location=None, target_type=None, bind_to=None, force=False):
4858
5066
directory = bzrdir.BzrDir.open(location)
4927
5141
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5144
class cmd_view(Command):
5145
"""Manage filtered views.
5147
Views provide a mask over the tree so that users can focus on
5148
a subset of a tree when doing their work. After creating a view,
5149
commands that support a list of files - status, diff, commit, etc -
5150
effectively have that list of files implicitly given each time.
5151
An explicit list of files can still be given but those files
5152
must be within the current view.
5154
In most cases, a view has a short life-span: it is created to make
5155
a selected change and is deleted once that change is committed.
5156
At other times, you may wish to create one or more named views
5157
and switch between them.
5159
To disable the current view without deleting it, you can switch to
5160
the pseudo view called ``off``. This can be useful when you need
5161
to see the whole tree for an operation or two (e.g. merge) but
5162
want to switch back to your view after that.
5165
To define the current view::
5167
bzr view file1 dir1 ...
5169
To list the current view::
5173
To delete the current view::
5177
To disable the current view without deleting it::
5179
bzr view --switch off
5181
To define a named view and switch to it::
5183
bzr view --name view-name file1 dir1 ...
5185
To list a named view::
5187
bzr view --name view-name
5189
To delete a named view::
5191
bzr view --name view-name --delete
5193
To switch to a named view::
5195
bzr view --switch view-name
5197
To list all views defined::
5201
To delete all views::
5203
bzr view --delete --all
5207
takes_args = ['file*']
5210
help='Apply list or delete action to all views.',
5213
help='Delete the view.',
5216
help='Name of the view to define, list or delete.',
5220
help='Name of the view to switch to.',
5225
def run(self, file_list,
5231
tree, file_list = tree_files(file_list, apply_view=False)
5232
current_view, view_dict = tree.views.get_view_info()
5237
raise errors.BzrCommandError(
5238
"Both --delete and a file list specified")
5240
raise errors.BzrCommandError(
5241
"Both --delete and --switch specified")
5243
tree.views.set_view_info(None, {})
5244
self.outf.write("Deleted all views.\n")
5246
raise errors.BzrCommandError("No current view to delete")
5248
tree.views.delete_view(name)
5249
self.outf.write("Deleted '%s' view.\n" % name)
5252
raise errors.BzrCommandError(
5253
"Both --switch and a file list specified")
5255
raise errors.BzrCommandError(
5256
"Both --switch and --all specified")
5257
elif switch == 'off':
5258
if current_view is None:
5259
raise errors.BzrCommandError("No current view to disable")
5260
tree.views.set_view_info(None, view_dict)
5261
self.outf.write("Disabled '%s' view.\n" % (current_view))
5263
tree.views.set_view_info(switch, view_dict)
5264
view_str = views.view_display_str(tree.views.lookup_view())
5265
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5268
self.outf.write('Views defined:\n')
5269
for view in sorted(view_dict):
5270
if view == current_view:
5274
view_str = views.view_display_str(view_dict[view])
5275
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5277
self.outf.write('No views defined.\n')
5280
# No name given and no current view set
5283
raise errors.BzrCommandError(
5284
"Cannot change the 'off' pseudo view")
5285
tree.views.set_view(name, sorted(file_list))
5286
view_str = views.view_display_str(tree.views.lookup_view())
5287
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5291
# No name given and no current view set
5292
self.outf.write('No current view.\n')
5294
view_str = views.view_display_str(tree.views.lookup_view(name))
5295
self.outf.write("'%s' view is: %s\n" % (name, view_str))
4930
5298
class cmd_hooks(Command):
4931
5299
"""Show a branch's currently registered hooks.