60
60
from bzrlib.workingtree import WorkingTree
63
from bzrlib.commands import Command, display_command
63
from bzrlib.commands import (
65
builtin_command_registry,
64
68
from bzrlib.option import (
456
460
for node in bt.iter_all_entries():
457
461
# Node is made up of:
458
462
# (index, key, value, [references])
459
refs_as_tuples = static_tuple.as_tuples(node[3])
466
refs_as_tuples = None
468
refs_as_tuples = static_tuple.as_tuples(refs)
460
469
as_tuple = (tuple(node[1]), node[2], refs_as_tuples)
461
470
self.outf.write('%s\n' % (as_tuple,))
1423
1432
branch_location = tree.branch.base
1424
1433
self.add_cleanup(tree.unlock)
1425
1434
# get rid of the final '/' and be ready for display
1426
branch_location = urlutils.unescape_for_display(branch_location[:-1],
1435
branch_location = urlutils.unescape_for_display(
1436
branch_location.rstrip('/'),
1428
1438
existing_pending_merges = tree.get_parent_ids()[1:]
1429
1439
if master is None:
1944
1954
help='Use this command to compare files.',
1957
RegistryOption('format',
1958
help='Diff format to use.',
1959
lazy_registry=('bzrlib.diff', 'format_registry'),
1960
value_switches=False, title='Diff format'),
1948
1962
aliases = ['di', 'dif']
1949
1963
encoding_type = 'exact'
1951
1965
@display_command
1952
1966
def run(self, revision=None, file_list=None, diff_options=None,
1953
prefix=None, old=None, new=None, using=None):
1954
from bzrlib.diff import get_trees_and_branches_to_diff, show_diff_trees
1967
prefix=None, old=None, new=None, using=None, format=None):
1968
from bzrlib.diff import (get_trees_and_branches_to_diff,
1956
1971
if (prefix is None) or (prefix == '0'):
1957
1972
# diff -p0 format
1971
1986
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1972
1987
' one or two revision specifiers')
1989
if using is not None and format is not None:
1990
raise errors.BzrCommandError('--using and --format are mutually '
1974
1993
(old_tree, new_tree,
1975
1994
old_branch, new_branch,
1976
1995
specific_files, extra_trees) = get_trees_and_branches_to_diff(
1979
1998
specific_files=specific_files,
1980
1999
external_diff_options=diff_options,
1981
2000
old_label=old_label, new_label=new_label,
1982
extra_trees=extra_trees, using=using)
2001
extra_trees=extra_trees, using=using,
1985
2005
class cmd_deleted(Command):
2433
2453
raise errors.BzrCommandError(
2434
2454
"bzr %s doesn't accept two revisions in different"
2435
2455
" branches." % command_name)
2436
rev1 = start_spec.in_history(branch)
2456
if start_spec.spec is None:
2457
# Avoid loading all the history.
2458
rev1 = RevisionInfo(branch, None, None)
2460
rev1 = start_spec.in_history(branch)
2437
2461
# Avoid loading all of history when we know a missing
2438
2462
# end of range means the last revision ...
2439
2463
if end_spec.spec is None:
3126
3150
'(use --file "%(f)s" to take commit message from that file)'
3127
3151
% { 'f': message })
3128
3152
ui.ui_factory.show_warning(warning_msg)
3154
message = message.replace('\r\n', '\n')
3155
message = message.replace('\r', '\n')
3157
raise errors.BzrCommandError(
3158
"please specify either --message or --file")
3130
3160
def get_message(commit_obj):
3131
3161
"""Callback to get commit message"""
3132
my_message = message
3133
if my_message is not None and '\r' in my_message:
3134
my_message = my_message.replace('\r\n', '\n')
3135
my_message = my_message.replace('\r', '\n')
3136
if my_message is None and not file:
3137
t = make_commit_message_template_encoded(tree,
3163
my_message = codecs.open(
3164
file, 'rt', osutils.get_user_encoding()).read()
3165
elif message is not None:
3166
my_message = message
3168
# No message supplied: make one up.
3169
# text is the status of the tree
3170
text = make_commit_message_template_encoded(tree,
3138
3171
selected_list, diff=show_diff,
3139
3172
output_encoding=osutils.get_user_encoding())
3173
# start_message is the template generated from hooks
3174
# XXX: Warning - looks like hooks return unicode,
3175
# make_commit_message_template_encoded returns user encoding.
3176
# We probably want to be using edit_commit_message instead to
3140
3178
start_message = generate_commit_message_template(commit_obj)
3141
my_message = edit_commit_message_encoded(t,
3179
my_message = edit_commit_message_encoded(text,
3142
3180
start_message=start_message)
3143
3181
if my_message is None:
3144
3182
raise errors.BzrCommandError("please specify a commit"
3145
3183
" message with either --message or --file")
3146
elif my_message and file:
3147
raise errors.BzrCommandError(
3148
"please specify either --message or --file")
3150
my_message = codecs.open(file, 'rt',
3151
osutils.get_user_encoding()).read()
3152
3184
if my_message == "":
3153
3185
raise errors.BzrCommandError("empty commit message specified")
3154
3186
return my_message
3166
3198
timezone=offset,
3167
3199
exclude=safe_relpath_files(tree, exclude))
3168
3200
except PointlessCommit:
3169
# FIXME: This should really happen before the file is read in;
3170
# perhaps prepare the commit; get the message; then actually commit
3171
3201
raise errors.BzrCommandError("No changes to commit."
3172
3202
" Use --unchanged to commit anyhow.")
3173
3203
except ConflictsInTree:
4053
4083
def run(self, file_list=None, merge_type=None, show_base=False,
4054
4084
reprocess=False):
4085
from bzrlib.conflicts import restore
4055
4086
if merge_type is None:
4056
4087
merge_type = _mod_merge.Merge3Merger
4057
4088
tree, file_list = tree_files(file_list)
5260
5291
To rename a tag (change the name but keep it on the same revsion), run ``bzr
5261
5292
tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
5294
If no tag name is specified it will be determined through the
5295
'automatic_tag_name' hook. This can e.g. be used to automatically tag
5296
upstream releases by reading configure.ac. See ``bzr help hooks`` for
5264
5300
_see_also = ['commit', 'tags']
5265
takes_args = ['tag_name']
5301
takes_args = ['tag_name?']
5266
5302
takes_options = [
5267
5303
Option('delete',
5268
5304
help='Delete this tag rather than placing it.',
5299
5337
revision_id = revision[0].as_revision_id(branch)
5301
5339
revision_id = branch.last_revision()
5340
if tag_name is None:
5341
tag_name = branch.automatic_tag_name(revision_id)
5342
if tag_name is None:
5343
raise errors.BzrCommandError(
5344
"Please specify a tag name.")
5302
5345
if (not force) and branch.tags.has_tag(tag_name):
5303
5346
raise errors.TagAlreadyExists(tag_name)
5304
5347
branch.tags.set_tag(tag_name, revision_id)
5740
5783
self.outf.write(" <no hooks installed>\n")
5786
class cmd_remove_branch(Command):
5789
This will remove the branch from the specified location but
5790
will keep any working tree or repository in place.
5794
Remove the branch at repo/trunk::
5796
bzr remove-branch repo/trunk
5800
takes_args = ["location?"]
5802
aliases = ["rmbranch"]
5804
def run(self, location=None):
5805
if location is None:
5807
branch = Branch.open_containing(location)[0]
5808
branch.bzrdir.destroy_branch()
5743
5811
class cmd_shelve(Command):
5744
5812
"""Temporarily set aside some changes from the current tree.
5928
5996
self.outf.write('%s %s\n' % (path, location))
5931
# these get imported and then picked up by the scan for cmd_*
5932
# TODO: Some more consistent way to split command definitions across files;
5933
# we do need to load at least some information about them to know of
5934
# aliases. ideally we would avoid loading the implementation until the
5935
# details were needed.
5936
from bzrlib.cmd_version_info import cmd_version_info
5937
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
5938
from bzrlib.bundle.commands import (
5941
from bzrlib.foreign import cmd_dpush
5942
from bzrlib.sign_my_commits import cmd_sign_my_commits
5999
def _register_lazy_builtins():
6000
# register lazy builtins from other modules; called at startup and should
6001
# be only called once.
6002
for (name, aliases, module_name) in [
6003
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6004
('cmd_dpush', [], 'bzrlib.foreign'),
6005
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6006
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6007
('cmd_conflicts', [], 'bzrlib.conflicts'),
6008
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6010
builtin_command_registry.register_lazy(name, aliases, module_name)