82
84
tree = WorkingTree.open_containing(file_list[0])[0]
83
85
if tree.supports_views():
84
86
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)
88
for filename in file_list:
89
if not osutils.is_inside_any(view_files, filename):
90
raise errors.FileOutsideView(filename, view_files)
89
92
tree = WorkingTree.open_containing(u'.')[0]
90
93
if tree.supports_views():
721
722
takes_args = ['names*']
722
723
takes_options = [Option("after", help="Move only the bzr identifier"
723
724
" of the file, because the file has already been moved."),
725
Option('auto', help='Automatically guess renames.'),
726
Option('dry-run', help='Avoid making changes when guessing renames.'),
725
728
aliases = ['move', 'rename']
726
729
encoding_type = 'replace'
728
def run(self, names_list, after=False):
731
def run(self, names_list, after=False, auto=False, dry_run=False):
733
return self.run_auto(names_list, after, dry_run)
735
raise errors.BzrCommandError('--dry-run requires --auto.')
729
736
if names_list is None:
732
738
if len(names_list) < 2:
733
739
raise errors.BzrCommandError("missing file argument")
734
740
tree, rel_names = tree_files(names_list, canonicalize=False)
747
def run_auto(self, names_list, after, dry_run):
748
if names_list is not None and len(names_list) > 1:
749
raise errors.BzrCommandError('Only one path may be specified to'
752
raise errors.BzrCommandError('--after cannot be specified with'
754
work_tree, file_list = tree_files(names_list, default_branch='.')
755
work_tree.lock_write()
757
rename_map.RenameMap.guess_renames(work_tree, dry_run)
741
761
def _run(self, tree, names_list, rel_names, after):
742
762
into_existing = osutils.isdir(names_list[-1])
743
763
if into_existing and len(names_list) == 2:
1228
1248
class cmd_update(Command):
1229
1249
"""Update a tree to have the latest code committed to its branch.
1231
1251
This will perform a merge into the working tree, and may generate
1232
conflicts. If you have any local changes, you will still
1252
conflicts. If you have any local changes, you will still
1233
1253
need to commit them after the update for the update to be complete.
1235
If you want to discard your local changes, you can just do a
1255
If you want to discard your local changes, you can just do a
1236
1256
'bzr revert' instead of 'bzr commit' after the update.
1282
1302
"""Show information about a working tree, branch or repository.
1284
1304
This command will show all known locations and formats associated to the
1285
tree, branch or repository. Statistical information is included with
1305
tree, branch or repository.
1307
In verbose mode, statistical information is included with each report.
1308
To see extended statistic information, use a verbosity level of 2 or
1309
higher by specifying the verbose option multiple times, e.g. -vv.
1288
1311
Branches and working trees will also report any missing revisions.
1315
Display information on the format and related locations:
1319
Display the above together with extended format information and
1320
basic statistics (like the number of files in the working tree and
1321
number of revisions in the branch and repository):
1325
Display the above together with number of committers to the branch:
1290
1329
_see_also = ['revno', 'working-trees', 'repositories']
1291
1330
takes_args = ['location?']
1744
1783
old_tree, new_tree, specific_files, extra_trees = \
1745
1784
_get_trees_to_diff(file_list, revision, old, new,
1746
1785
apply_view=True)
1747
return show_diff_trees(old_tree, new_tree, sys.stdout,
1786
return show_diff_trees(old_tree, new_tree, sys.stdout,
1748
1787
specific_files=specific_files,
1749
1788
external_diff_options=diff_options,
1750
1789
old_label=old_label, new_label=new_label,
1906
1945
The following options can be used to control what information is
1909
1948
-l N display a maximum of N revisions
1910
1949
-n N display N levels of revisions (0 for all, 1 for collapsed)
1911
1950
-v display a status summary (delta) for each revision
1912
1951
-p display a diff (patch) for each revision
1913
1952
--show-ids display revision-ids (and file-ids), not just revnos
1915
1954
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
1955
log format. If the -n option is not used, the standard log formats show
1956
just the top level (mainline).
1920
1958
Status summaries are shown using status flags like A, M, etc. To see
1921
1959
the changes explained using words like ``added`` and ``modified``
1922
1960
instead, use the -vv option.
1924
1962
:Ordering control:
1926
1964
To display revisions from oldest to newest, use the --forward option.
1927
1965
In most cases, using this option will have little impact on the total
1928
1966
time taken to produce a log, though --forward does not incrementally
1929
1967
display revisions like --reverse does when it can.
1931
1969
:Revision filtering:
1933
1971
The -r option can be used to specify what revision or range of revisions
1934
1972
to filter against. The various forms are shown below::
1936
1974
-rX display revision X
1937
1975
-rX.. display revision X and later
1938
1976
-r..Y display up to and including revision Y
1939
1977
-rX..Y display from X to Y inclusive
1941
1979
See ``bzr help revisionspec`` for details on how to specify X and Y.
1942
1980
Some common examples are given below::
1944
1982
-r-1 show just the tip
1945
1983
-r-10.. show the last 10 mainline revisions
1946
1984
-rsubmit:.. show what's new on this branch
1947
1985
-rancestor:path.. show changes since the common ancestor of this
1948
1986
branch and the one at location path
1949
1987
-rdate:yesterday.. show changes since yesterday
1951
1989
When logging a range of revisions using -rX..Y, log starts at
1952
1990
revision Y and searches back in history through the primary
1953
1991
("left-hand") parents until it finds X. When logging just the
1956
1994
a nested merge revision and the log will be truncated accordingly.
1958
1996
:Path filtering:
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
1998
If parameters are given and the first one is not a branch, the log
1999
will be filtered to show only those revisions that changed the
2000
nominated files or directories.
1964
2002
Filenames are interpreted within their historical context. To log a
1965
2003
deleted file, specify a revision range so that the file existed at
1966
2004
the end or start of the range.
1968
2006
Historical context is also important when interpreting pathnames of
1969
2007
renamed files/directories. Consider the following example:
1971
2009
* revision 1: add tutorial.txt
1972
2010
* revision 2: modify tutorial.txt
1973
2011
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
1977
2015
* ``bzr log guide.txt`` will log the file added in revision 1
1979
2017
* ``bzr log tutorial.txt`` will log the new file added in revision 3
1981
2019
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
1982
2020
the original file in revision 2.
1984
2022
* ``bzr log -r2 -p guide.txt`` will display an error message as there
1985
2023
was no file called guide.txt in revision 2.
1987
2025
Renames are always followed by log. By design, there is no need to
1988
2026
explicitly ask for this (and no way to stop logging a file back
1989
2027
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.)
1996
2029
:Other filtering:
1998
2031
The --message option can be used for finding revisions that match a
1999
2032
regular expression in a commit message.
2001
2034
:Tips & tricks:
2003
2036
GUI tools and IDEs are often better at exploring history than command
2004
2037
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
2005
2038
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2006
2039
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2008
2041
Web interfaces are often better at exploring history than command line
2009
2042
tools, particularly for branches on servers. You may prefer Loggerhead
2010
2043
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
2012
2045
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
2049
top = log -l10 --line
2019
2052
``bzr tip`` will then show the latest revision while ``bzr top``
2020
2053
will show the last 10 mainline revisions. To see the details of a
2021
2054
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
2056
If you are interested in looking deeper into a particular merge X,
2057
use ``bzr log -n0 -rX``.
2031
2059
``bzr log -v`` on a branch with lots of history is currently
2032
2060
very slow. A fix for this issue is currently under development.
2033
2061
With or without that fix, it is recommended that a revision range
2034
2062
be given when using the -v option.
2036
2064
bzr has a generic full-text matching plugin, bzr-search, that can be
2037
2065
used to find revisions matching user names, commit messages, etc.
2038
2066
Among other features, this plugin can find all revisions containing
2039
2067
a list of words but not others.
2041
2069
When exploring non-mainline history on large projects with deep
2042
2070
history, the performance of log can be greatly improved by installing
2043
2071
the revnocache plugin. This plugin buffers historical information
2044
2072
trading disk space for faster speed.
2046
takes_args = ['location?']
2074
takes_args = ['file*']
2047
2075
_see_also = ['log-formats', 'revisionspec']
2048
2076
takes_options = [
2049
2077
Option('forward',
2105
2137
revision = change
2110
# find the file id to log:
2112
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
2115
file_id = _get_fileid_to_log(revision, tree, b, fp)
2140
filter_by_dir = False
2142
# find the file ids to log and check for directory filtering
2143
b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2145
for relpath, file_id, kind in file_info_list:
2116
2146
if file_id is None:
2117
2147
raise errors.BzrCommandError(
2118
2148
"Path unknown at end or start of revision range: %s" %
2150
# If the relpath is the top of the tree, we log everything
2155
file_ids.append(file_id)
2156
filter_by_dir = filter_by_dir or (
2157
kind in ['directory', 'tree-reference'])
2122
# FIXME ? log the current subdir only RBC 20060203
2160
# FIXME ? log the current subdir only RBC 20060203
2123
2161
if revision is not None \
2124
2162
and len(revision) > 0 and revision[0].get_branch():
2125
2163
location = revision[0].get_branch()
2128
2166
dir, relpath = bzrdir.BzrDir.open_containing(location)
2129
2167
b = dir.open_branch()
2133
2168
rev1, rev2 = _get_revision_range(revision, b, self.name())
2170
# Decide on the type of delta & diff filtering to use
2171
# TODO: add an --all-files option to make this configurable & consistent
2179
diff_type = 'partial'
2185
# Build the log formatter
2134
2186
if log_format is None:
2135
2187
log_format = log.log_formatter_registry.get_default(b)
2137
2188
lf = log_format(show_ids=show_ids, to_file=self.outf,
2138
2189
show_timezone=timezone,
2139
2190
delta_format=get_verbosity_level(),
2146
direction=direction,
2147
start_revision=rev1,
2151
show_diff=show_diff)
2193
# Choose the algorithm for doing the logging. It's annoying
2194
# having multiple code paths like this but necessary until
2195
# the underlying repository format is faster at generating
2196
# deltas or can provide everything we need from the indices.
2197
# The default algorithm - match-using-deltas - works for
2198
# multiple files and directories and is faster for small
2199
# amounts of history (200 revisions say). However, it's too
2200
# slow for logging a single file in a repository with deep
2201
# history, i.e. > 10K revisions. In the spirit of "do no
2202
# evil when adding features", we continue to use the
2203
# original algorithm - per-file-graph - for the "single
2204
# file that isn't a directory without showing a delta" case.
2205
partial_history = revision and b.repository._format.supports_chks
2206
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2207
or delta_type or partial_history)
2209
# Build the LogRequest and execute it
2210
if len(file_ids) == 0:
2212
rqst = make_log_request_dict(
2213
direction=direction, specific_fileids=file_ids,
2214
start_revision=rev1, end_revision=rev2, limit=limit,
2215
message_search=message, delta_type=delta_type,
2216
diff_type=diff_type, _match_using_deltas=match_using_deltas)
2217
Logger(b, rqst).show(lf)
2388
2467
if not name_pattern_list:
2389
2468
raise errors.BzrCommandError("ignore requires at least one "
2390
2469
"NAME_PATTERN or --old-default-rules")
2391
name_pattern_list = [globbing.normalize_pattern(p)
2470
name_pattern_list = [globbing.normalize_pattern(p)
2392
2471
for p in name_pattern_list]
2393
2472
for name_pattern in name_pattern_list:
2394
if (name_pattern[0] == '/' or
2473
if (name_pattern[0] == '/' or
2395
2474
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2396
2475
raise errors.BzrCommandError(
2397
2476
"NAME_PATTERN should not be an absolute path")
2523
2606
If no revision is nominated, the last revision is used.
2525
2608
Note: Take care to redirect standard output when using this command on a
2529
2612
_see_also = ['ls']
2530
2613
takes_options = [
2531
2614
Option('name-from-revision', help='The path name in the old tree.'),
2615
Option('filters', help='Apply content filters to display the '
2616
'convenience form.'),
2534
2619
takes_args = ['filename']
2535
2620
encoding_type = 'exact'
2537
2622
@display_command
2538
def run(self, filename, revision=None, name_from_revision=False):
2623
def run(self, filename, revision=None, name_from_revision=False,
2539
2625
if revision is not None and len(revision) != 1:
2540
2626
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2541
2627
" one revision specifier")
2544
2630
branch.lock_read()
2546
2632
return self._run(tree, branch, relpath, filename, revision,
2633
name_from_revision, filters)
2549
2635
branch.unlock()
2551
def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2637
def _run(self, tree, b, relpath, filename, revision, name_from_revision,
2552
2639
if tree is None:
2553
2640
tree = b.basis_tree()
2554
2641
rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2556
cur_file_id = tree.path2id(relpath)
2557
2643
old_file_id = rev_tree.path2id(relpath)
2559
2645
if name_from_revision:
2646
# Try in revision if requested
2560
2647
if old_file_id is None:
2561
2648
raise errors.BzrCommandError(
2562
2649
"%r is not present in revision %s" % (
2563
2650
filename, rev_tree.get_revision_id()))
2565
2652
content = rev_tree.get_file_text(old_file_id)
2566
elif cur_file_id is not None:
2567
content = rev_tree.get_file_text(cur_file_id)
2568
elif old_file_id is not None:
2569
content = rev_tree.get_file_text(old_file_id)
2571
raise errors.BzrCommandError(
2572
"%r is not present in revision %s" % (
2573
filename, rev_tree.get_revision_id()))
2574
self.outf.write(content)
2654
cur_file_id = tree.path2id(relpath)
2656
if cur_file_id is not None:
2657
# Then try with the actual file id
2659
content = rev_tree.get_file_text(cur_file_id)
2661
except errors.NoSuchId:
2662
# The actual file id didn't exist at that time
2664
if not found and old_file_id is not None:
2665
# Finally try with the old file id
2666
content = rev_tree.get_file_text(old_file_id)
2669
# Can't be found anywhere
2670
raise errors.BzrCommandError(
2671
"%r is not present in revision %s" % (
2672
filename, rev_tree.get_revision_id()))
2674
from bzrlib.filters import (
2675
ContentFilterContext,
2676
filtered_output_bytes,
2678
filters = rev_tree._content_filter_stack(relpath)
2679
chunks = content.splitlines(True)
2680
content = filtered_output_bytes(chunks, filters,
2681
ContentFilterContext(relpath, rev_tree))
2682
self.outf.writelines(content)
2684
self.outf.write(content)
2577
2687
class cmd_local_time_offset(Command):
2578
2688
"""Show the offset in seconds from GMT to local time."""
2580
2690
@display_command
2582
2692
print osutils.local_time_offset()
2649
2761
help="Refuse to commit if there are unknown "
2650
2762
"files in the working tree."),
2651
2763
ListOption('fixes', type=str,
2652
help="Mark a bug as being fixed by this revision."),
2653
Option('author', type=unicode,
2764
help="Mark a bug as being fixed by this revision "
2765
"(see \"bzr help bugs\")."),
2766
ListOption('author', type=unicode,
2654
2767
help="Set the author's name, if it's different "
2655
2768
"from the committer."),
2656
2769
Option('local',
2666
2779
aliases = ['ci', 'checkin']
2668
def _get_bug_fix_properties(self, fixes, branch):
2781
def _iter_bug_fix_urls(self, fixes, branch):
2670
2782
# Configure the properties for bug fixing attributes.
2671
2783
for fixed_bug in fixes:
2672
2784
tokens = fixed_bug.split(':')
2673
2785
if len(tokens) != 2:
2674
2786
raise errors.BzrCommandError(
2675
"Invalid bug %s. Must be in the form of 'tag:id'. "
2676
"Commit refused." % fixed_bug)
2787
"Invalid bug %s. Must be in the form of 'tracker:id'. "
2788
"See \"bzr help bugs\" for more information on this "
2789
"feature.\nCommit refused." % fixed_bug)
2677
2790
tag, bug_id = tokens
2679
bug_url = bugtracker.get_bug_url(tag, branch, bug_id)
2792
yield bugtracker.get_bug_url(tag, branch, bug_id)
2680
2793
except errors.UnknownBugTrackerAbbreviation:
2681
2794
raise errors.BzrCommandError(
2682
2795
'Unrecognized bug %s. Commit refused.' % fixed_bug)
2683
except errors.MalformedBugIdentifier:
2796
except errors.MalformedBugIdentifier, e:
2684
2797
raise errors.BzrCommandError(
2685
"Invalid bug identifier for %s. Commit refused."
2687
properties.append('%s fixed' % bug_url)
2688
return '\n'.join(properties)
2798
"%s\nCommit refused." % (str(e),))
2690
2800
def run(self, message=None, file=None, verbose=False, selected_list=None,
2691
2801
unchanged=False, strict=False, local=False, fixes=None,
3119
3235
lsprof_timed=None, cache_dir=None,
3120
3236
first=False, list_only=False,
3121
3237
randomize=None, exclude=None, strict=False,
3122
load_list=None, debugflag=None, starting_with=None):
3238
load_list=None, debugflag=None, starting_with=None, subunit=False,
3123
3240
from bzrlib.tests import selftest
3124
3241
import bzrlib.benchmarks as benchmarks
3125
3242
from bzrlib.benchmarks import tree_creator
3335
3462
allow_pending = True
3336
3463
verified = 'inapplicable'
3337
3464
tree = WorkingTree.open_containing(directory)[0]
3466
# die as quickly as possible if there are uncommitted changes
3468
basis_tree = tree.revision_tree(tree.last_revision())
3469
except errors.NoSuchRevision:
3470
basis_tree = tree.basis_tree()
3472
changes = tree.changes_from(basis_tree)
3473
if changes.has_changed():
3474
raise errors.UncommittedChanges(tree)
3338
3476
view_info = _get_view_info_for_change_reporter(tree)
3339
3477
change_reporter = delta._ChangeReporter(
3340
3478
unversioned_filter=tree.is_ignored, view_info=view_info)
4019
4158
This prints out the given file with an annotation on the left side
4020
4159
indicating which revision, author and date introduced the change.
4022
If the origin is the same for a run of consecutive lines, it is
4161
If the origin is the same for a run of consecutive lines, it is
4023
4162
shown only at the top, unless the --all option is given.
4025
4164
# TODO: annotate directories; showing when each file was last changed
4026
# TODO: if the working copy is modified, show annotations on that
4165
# TODO: if the working copy is modified, show annotations on that
4027
4166
# with new uncommitted lines marked
4028
4167
aliases = ['ann', 'blame', 'praise']
4029
4168
takes_args = ['filename']
4708
4849
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4709
4850
no_patch=False, revision=None, remember=False, output=None,
4710
format='4', mail_to=None, message=None, **kwargs):
4851
format='4', mail_to=None, message=None, body=None, **kwargs):
4711
4852
return self._run(submit_branch, revision, public_branch, remember,
4712
4853
format, no_bundle, no_patch, output,
4713
kwargs.get('from', '.'), mail_to, message)
4854
kwargs.get('from', '.'), mail_to, message, body)
4715
4856
def _run(self, submit_branch, revision, public_branch, remember, format,
4716
no_bundle, no_patch, output, from_, mail_to, message):
4857
no_bundle, no_patch, output, from_, mail_to, message, body):
4717
4858
from bzrlib.revision import NULL_REVISION
4718
4859
branch = Branch.open_containing(from_)[0]
4719
4860
if output is None:
4888
5035
return self._run(submit_branch, revision, public_branch, remember,
4889
5036
format, no_bundle, no_patch, output,
4890
kwargs.get('from', '.'), None, None)
5037
kwargs.get('from', '.'), None, None, None)
4893
5040
class cmd_tag(Command):
4894
5041
"""Create, remove or modify a tag naming a revision.
4896
5043
Tags give human-meaningful names to revisions. Commands that take a -r
4897
5044
(--revision) option can be given -rtag:X, where X is any previously
5298
5445
class cmd_hooks(Command):
5299
"""Show a branch's currently registered hooks.
5303
takes_args = ['path?']
5305
def run(self, path=None):
5308
branch_hooks = Branch.open(path).hooks
5309
for hook_type in branch_hooks:
5310
hooks = branch_hooks[hook_type]
5311
self.outf.write("%s:\n" % (hook_type,))
5314
self.outf.write(" %s\n" %
5315
(branch_hooks.get_hook_name(hook),))
5317
self.outf.write(" <no hooks installed>\n")
5451
for hook_key in sorted(hooks.known_hooks.keys()):
5452
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5453
self.outf.write("%s:\n" % type(some_hooks).__name__)
5454
for hook_name, hook_point in sorted(some_hooks.items()):
5455
self.outf.write(" %s:\n" % (hook_name,))
5456
found_hooks = list(hook_point)
5458
for hook in found_hooks:
5459
self.outf.write(" %s\n" %
5460
(some_hooks.get_hook_name(hook),))
5462
self.outf.write(" <no hooks installed>\n")
5320
5465
class cmd_shelve(Command):
5353
5498
value_switches=True, enum_switch=False),
5355
5500
Option('list', help='List shelved changes.'),
5502
help='Destroy removed changes instead of shelving them.'),
5357
5504
_see_also = ['unshelve']
5359
5506
def run(self, revision=None, all=False, file_list=None, message=None,
5360
writer=None, list=False):
5507
writer=None, list=False, destroy=False):
5362
5509
return self.run_for_list()
5363
5510
from bzrlib.shelf_ui import Shelver
5413
5560
Unshelver.from_args(shelf_id, action).run()
5563
class cmd_clean_tree(Command):
5564
"""Remove unwanted files from working tree.
5566
By default, only unknown files, not ignored files, are deleted. Versioned
5567
files are never deleted.
5569
Another class is 'detritus', which includes files emitted by bzr during
5570
normal operations and selftests. (The value of these files decreases with
5573
If no options are specified, unknown files are deleted. Otherwise, option
5574
flags are respected, and may be combined.
5576
To check what clean-tree will do, use --dry-run.
5578
takes_options = [Option('ignored', help='Delete all ignored files.'),
5579
Option('detritus', help='Delete conflict files, merge'
5580
' backups, and failed selftest dirs.'),
5582
help='Delete files unknown to bzr (default).'),
5583
Option('dry-run', help='Show files to delete instead of'
5585
Option('force', help='Do not prompt before deleting.')]
5586
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5588
from bzrlib.clean_tree import clean_tree
5589
if not (unknown or ignored or detritus):
5593
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5594
dry_run=dry_run, no_prompt=force)
5416
5597
def _create_prefix(cur_transport):
5417
5598
needed = [cur_transport]
5418
5599
# Recurse upwards until we can create a directory successfully