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.
140
181
fixer = tree.relpath
141
182
for filename in file_list:
143
new_list.append(fixer(osutils.dereference_path(filename)))
184
relpath = fixer(osutils.dereference_path(filename))
185
if view_files and not osutils.is_inside_any(view_files, relpath):
186
raise errors.FileOutsideView(filename, view_files)
187
new_list.append(relpath)
144
188
except errors.PathNotChild:
145
189
raise errors.FileInWrongBranch(tree.branch, filename)
193
def _get_view_info_for_change_reporter(tree):
194
"""Get the view information from a tree for change reporting."""
197
current_view = tree.views.get_view_info()[0]
198
if current_view is not None:
199
view_info = (current_view, tree.views.lookup_view())
200
except errors.ViewsNotSupported:
149
205
# TODO: Make sure no commands unconditionally use the working directory as a
150
206
# branch. If a filename argument is used, the first of them should be used to
151
207
# specify the branch. (Perhaps this can be factored out into some kind of
1206
1260
revno = tree.branch.revision_id_to_revno(last_rev)
1207
1261
note("Tree is up to date at revision %d." % (revno,))
1263
view_info = _get_view_info_for_change_reporter(tree)
1209
1264
conflicts = tree.update(
1210
delta._ChangeReporter(unversioned_filter=tree.is_ignored),
1211
possible_transports=possible_transports)
1265
delta._ChangeReporter(unversioned_filter=tree.is_ignored,
1266
view_info=view_info), possible_transports=possible_transports)
1212
1267
revno = tree.branch.revision_id_to_revno(
1213
1268
_mod_revision.ensure_null(tree.last_revision()))
1214
1269
note('Updated to revision %d.' % (revno,))
1227
1282
"""Show information about a working tree, branch or repository.
1229
1284
This command will show all known locations and formats associated to the
1230
tree, branch or repository. Statistical information is included with
1285
tree, branch or repository.
1287
In verbose mode, statistical information is included with each report.
1288
To see extended statistic information, use a verbosity level of 2 or
1289
higher by specifying the verbose option multiple times, e.g. -vv.
1233
1291
Branches and working trees will also report any missing revisions.
1295
Display information on the format and related locations:
1299
Display the above together with extended format information and
1300
basic statistics (like the number of files in the working tree and
1301
number of revisions in the branch and repository):
1305
Display the above together with number of committers to the branch:
1235
1309
_see_also = ['revno', 'working-trees', 'repositories']
1236
1310
takes_args = ['location?']
1687
1761
' one or two revision specifiers')
1689
1763
old_tree, new_tree, specific_files, extra_trees = \
1690
_get_trees_to_diff(file_list, revision, old, new)
1691
return show_diff_trees(old_tree, new_tree, sys.stdout,
1764
_get_trees_to_diff(file_list, revision, old, new,
1766
return show_diff_trees(old_tree, new_tree, sys.stdout,
1692
1767
specific_files=specific_files,
1693
1768
external_diff_options=diff_options,
1694
1769
old_label=old_label, new_label=new_label,
1850
1925
The following options can be used to control what information is
1853
1928
-l N display a maximum of N revisions
1854
1929
-n N display N levels of revisions (0 for all, 1 for collapsed)
1855
1930
-v display a status summary (delta) for each revision
1856
1931
-p display a diff (patch) for each revision
1857
1932
--show-ids display revision-ids (and file-ids), not just revnos
1859
1934
Note that the default number of levels to display is a function of the
1860
1935
log format. If the -n option is not used, ``short`` and ``line`` show
1861
1936
just the top level (mainline) while ``long`` shows all levels of merged
1864
1939
Status summaries are shown using status flags like A, M, etc. To see
1865
1940
the changes explained using words like ``added`` and ``modified``
1866
1941
instead, use the -vv option.
1868
1943
:Ordering control:
1870
1945
To display revisions from oldest to newest, use the --forward option.
1871
1946
In most cases, using this option will have little impact on the total
1872
1947
time taken to produce a log, though --forward does not incrementally
1873
1948
display revisions like --reverse does when it can.
1875
1950
:Revision filtering:
1877
1952
The -r option can be used to specify what revision or range of revisions
1878
1953
to filter against. The various forms are shown below::
1880
1955
-rX display revision X
1881
1956
-rX.. display revision X and later
1882
1957
-r..Y display up to and including revision Y
1883
1958
-rX..Y display from X to Y inclusive
1885
1960
See ``bzr help revisionspec`` for details on how to specify X and Y.
1886
1961
Some common examples are given below::
1888
1963
-r-1 show just the tip
1889
1964
-r-10.. show the last 10 mainline revisions
1890
1965
-rsubmit:.. show what's new on this branch
1891
1966
-rancestor:path.. show changes since the common ancestor of this
1892
1967
branch and the one at location path
1893
1968
-rdate:yesterday.. show changes since yesterday
1895
1970
When logging a range of revisions using -rX..Y, log starts at
1896
1971
revision Y and searches back in history through the primary
1897
1972
("left-hand") parents until it finds X. When logging just the
1900
1975
a nested merge revision and the log will be truncated accordingly.
1902
1977
:Path filtering:
1904
1979
If a parameter is given and it's not a branch, the log will be filtered
1905
1980
to show only those revisions that changed the nominated file or
1908
1983
Filenames are interpreted within their historical context. To log a
1909
1984
deleted file, specify a revision range so that the file existed at
1910
1985
the end or start of the range.
1912
1987
Historical context is also important when interpreting pathnames of
1913
1988
renamed files/directories. Consider the following example:
1915
1990
* revision 1: add tutorial.txt
1916
1991
* revision 2: modify tutorial.txt
1917
1992
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
1921
1996
* ``bzr log guide.txt`` will log the file added in revision 1
1923
1998
* ``bzr log tutorial.txt`` will log the new file added in revision 3
1925
2000
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
1926
2001
the original file in revision 2.
1928
2003
* ``bzr log -r2 -p guide.txt`` will display an error message as there
1929
2004
was no file called guide.txt in revision 2.
1931
2006
Renames are always followed by log. By design, there is no need to
1932
2007
explicitly ask for this (and no way to stop logging a file back
1933
2008
until it was last renamed).
1935
2010
Note: If the path is a directory, only revisions that directly changed
1936
2011
that directory object are currently shown. This is considered a bug.
1937
2012
(Support for filtering against multiple files and for files within a
1938
2013
directory is under development.)
1940
2015
:Other filtering:
1942
2017
The --message option can be used for finding revisions that match a
1943
2018
regular expression in a commit message.
1945
2020
:Tips & tricks:
1947
2022
GUI tools and IDEs are often better at exploring history than command
1948
2023
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
1949
2024
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
1950
2025
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
1952
2027
Web interfaces are often better at exploring history than command line
1953
2028
tools, particularly for branches on servers. You may prefer Loggerhead
1954
2029
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
1956
2031
You may find it useful to add the aliases below to ``bazaar.conf``::
1959
2034
tip = log -r-1 -n1
1960
2035
top = log -r-10.. --short --forward
1961
2036
show = log -v -p -n1 --long
1963
2038
``bzr tip`` will then show the latest revision while ``bzr top``
1964
2039
will show the last 10 mainline revisions. To see the details of a
1965
2040
particular revision X, ``bzr show -rX``.
1967
2042
As many GUI tools and Web interfaces do, you may prefer viewing
1968
2043
history collapsed initially. If you are interested in looking deeper
1969
2044
into a particular merge X, use ``bzr log -n0 -rX``. If you like
1970
2045
working this way, you may wish to either:
1972
2047
* change your default log format to short (or line)
1973
2048
* add this alias: log = log -n1
1975
2050
``bzr log -v`` on a branch with lots of history is currently
1976
2051
very slow. A fix for this issue is currently under development.
1977
2052
With or without that fix, it is recommended that a revision range
1978
2053
be given when using the -v option.
1980
2055
bzr has a generic full-text matching plugin, bzr-search, that can be
1981
2056
used to find revisions matching user names, commit messages, etc.
1982
2057
Among other features, this plugin can find all revisions containing
1983
2058
a list of words but not others.
1985
2060
When exploring non-mainline history on large projects with deep
1986
2061
history, the performance of log can be greatly improved by installing
1987
2062
the revnocache plugin. This plugin buffers historical information
3962
4038
This prints out the given file with an annotation on the left side
3963
4039
indicating which revision, author and date introduced the change.
3965
If the origin is the same for a run of consecutive lines, it is
4041
If the origin is the same for a run of consecutive lines, it is
3966
4042
shown only at the top, unless the --all option is given.
3968
4044
# TODO: annotate directories; showing when each file was last changed
3969
# TODO: if the working copy is modified, show annotations on that
4045
# TODO: if the working copy is modified, show annotations on that
3970
4046
# with new uncommitted lines marked
3971
4047
aliases = ['ann', 'blame', 'praise']
3972
4048
takes_args = ['filename']
4981
5057
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4982
5058
takes_args = ['location?']
4983
takes_options = [RegistryOption.from_kwargs('target_type',
4984
title='Target type',
4985
help='The type to reconfigure the directory to.',
4986
value_switches=True, enum_switch=False,
4987
branch='Reconfigure to be an unbound branch '
4988
'with no working tree.',
4989
tree='Reconfigure to be an unbound branch '
4990
'with a working tree.',
4991
checkout='Reconfigure to be a bound branch '
4992
'with a working tree.',
4993
lightweight_checkout='Reconfigure to be a lightweight'
4994
' checkout (with no local history).',
4995
standalone='Reconfigure to be a standalone branch '
4996
'(i.e. stop using shared repository).',
4997
use_shared='Reconfigure to use a shared repository.'),
4998
Option('bind-to', help='Branch to bind checkout to.',
5001
help='Perform reconfiguration even if local changes'
5060
RegistryOption.from_kwargs(
5062
title='Target type',
5063
help='The type to reconfigure the directory to.',
5064
value_switches=True, enum_switch=False,
5065
branch='Reconfigure to be an unbound branch with no working tree.',
5066
tree='Reconfigure to be an unbound branch with a working tree.',
5067
checkout='Reconfigure to be a bound branch with a working tree.',
5068
lightweight_checkout='Reconfigure to be a lightweight'
5069
' checkout (with no local history).',
5070
standalone='Reconfigure to be a standalone branch '
5071
'(i.e. stop using shared repository).',
5072
use_shared='Reconfigure to use a shared repository.',
5073
with_trees='Reconfigure repository to create '
5074
'working trees on branches by default.',
5075
with_no_trees='Reconfigure repository to not create '
5076
'working trees on branches by default.'
5078
Option('bind-to', help='Branch to bind checkout to.', type=str),
5080
help='Perform reconfiguration even if local changes'
5005
5084
def run(self, location=None, target_type=None, bind_to=None, force=False):
5006
5085
directory = bzrdir.BzrDir.open(location)
5020
5099
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5021
5100
elif target_type == 'standalone':
5022
5101
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5102
elif target_type == 'with-trees':
5103
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5105
elif target_type == 'with-no-trees':
5106
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5023
5108
reconfiguration.apply(force)
5026
5111
class cmd_switch(Command):
5027
5112
"""Set the branch of a checkout and update.
5029
5114
For lightweight checkouts, this changes the branch being referenced.
5030
5115
For heavyweight checkouts, this checks that there are no local commits
5031
5116
versus the current bound branch, then it makes the local branch a mirror
5075
5160
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5163
class cmd_view(Command):
5164
"""Manage filtered views.
5166
Views provide a mask over the tree so that users can focus on
5167
a subset of a tree when doing their work. After creating a view,
5168
commands that support a list of files - status, diff, commit, etc -
5169
effectively have that list of files implicitly given each time.
5170
An explicit list of files can still be given but those files
5171
must be within the current view.
5173
In most cases, a view has a short life-span: it is created to make
5174
a selected change and is deleted once that change is committed.
5175
At other times, you may wish to create one or more named views
5176
and switch between them.
5178
To disable the current view without deleting it, you can switch to
5179
the pseudo view called ``off``. This can be useful when you need
5180
to see the whole tree for an operation or two (e.g. merge) but
5181
want to switch back to your view after that.
5184
To define the current view::
5186
bzr view file1 dir1 ...
5188
To list the current view::
5192
To delete the current view::
5196
To disable the current view without deleting it::
5198
bzr view --switch off
5200
To define a named view and switch to it::
5202
bzr view --name view-name file1 dir1 ...
5204
To list a named view::
5206
bzr view --name view-name
5208
To delete a named view::
5210
bzr view --name view-name --delete
5212
To switch to a named view::
5214
bzr view --switch view-name
5216
To list all views defined::
5220
To delete all views::
5222
bzr view --delete --all
5226
takes_args = ['file*']
5229
help='Apply list or delete action to all views.',
5232
help='Delete the view.',
5235
help='Name of the view to define, list or delete.',
5239
help='Name of the view to switch to.',
5244
def run(self, file_list,
5250
tree, file_list = tree_files(file_list, apply_view=False)
5251
current_view, view_dict = tree.views.get_view_info()
5256
raise errors.BzrCommandError(
5257
"Both --delete and a file list specified")
5259
raise errors.BzrCommandError(
5260
"Both --delete and --switch specified")
5262
tree.views.set_view_info(None, {})
5263
self.outf.write("Deleted all views.\n")
5265
raise errors.BzrCommandError("No current view to delete")
5267
tree.views.delete_view(name)
5268
self.outf.write("Deleted '%s' view.\n" % name)
5271
raise errors.BzrCommandError(
5272
"Both --switch and a file list specified")
5274
raise errors.BzrCommandError(
5275
"Both --switch and --all specified")
5276
elif switch == 'off':
5277
if current_view is None:
5278
raise errors.BzrCommandError("No current view to disable")
5279
tree.views.set_view_info(None, view_dict)
5280
self.outf.write("Disabled '%s' view.\n" % (current_view))
5282
tree.views.set_view_info(switch, view_dict)
5283
view_str = views.view_display_str(tree.views.lookup_view())
5284
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5287
self.outf.write('Views defined:\n')
5288
for view in sorted(view_dict):
5289
if view == current_view:
5293
view_str = views.view_display_str(view_dict[view])
5294
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5296
self.outf.write('No views defined.\n')
5299
# No name given and no current view set
5302
raise errors.BzrCommandError(
5303
"Cannot change the 'off' pseudo view")
5304
tree.views.set_view(name, sorted(file_list))
5305
view_str = views.view_display_str(tree.views.lookup_view())
5306
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5310
# No name given and no current view set
5311
self.outf.write('No current view.\n')
5313
view_str = views.view_display_str(tree.views.lookup_view(name))
5314
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5078
5317
class cmd_hooks(Command):
5079
5318
"""Show a branch's currently registered hooks.