663
1060
_see_also = ['pull', 'update', 'working-trees']
664
takes_options = ['remember', 'overwrite', 'verbose',
1061
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
665
1062
Option('create-prefix',
666
1063
help='Create the path leading up to the branch '
667
'if it does not already exist'),
1064
'if it does not already exist.'),
668
1065
Option('directory',
669
help='branch to push from, '
670
'rather than the one containing the working directory',
1066
help='Branch to push from, '
1067
'rather than the one containing the working directory.',
674
1071
Option('use-existing-dir',
675
1072
help='By default push will fail if the target'
676
1073
' directory exists, but does not already'
677
' have a control directory. This flag will'
1074
' have a control directory. This flag will'
678
1075
' allow push to proceed.'),
1077
help='Create a stacked branch that references the public location '
1078
'of the parent branch.'),
1079
Option('stacked-on',
1080
help='Create a stacked branch that refers to another branch '
1081
'for the commit history. Only the work not present in the '
1082
'referenced branch is included in the branch created.',
1085
help='Refuse to push if there are uncommitted changes in'
1086
' the working tree, --no-strict disables the check.'),
680
1088
takes_args = ['location?']
681
1089
encoding_type = 'replace'
683
1091
def run(self, location=None, remember=False, overwrite=False,
684
create_prefix=False, verbose=False,
685
use_existing_dir=False,
687
# FIXME: Way too big! Put this into a function called from the
1092
create_prefix=False, verbose=False, revision=None,
1093
use_existing_dir=False, directory=None, stacked_on=None,
1094
stacked=False, strict=None):
1095
from bzrlib.push import _show_push_branch
689
1097
if directory is None:
691
br_from = Branch.open_containing(directory)[0]
692
stored_loc = br_from.get_push_location()
1099
# Get the source branch
1101
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1103
strict = br_from.get_config().get_user_option_as_bool('push_strict')
1104
if strict is None: strict = True # default value
1105
# Get the tip's revision_id
1106
revision = _get_one_revision('push', revision)
1107
if revision is not None:
1108
revision_id = revision.in_history(br_from).rev_id
1111
if strict and tree is not None and revision_id is None:
1112
if (tree.has_changes(tree.basis_tree())
1113
or len(tree.get_parent_ids()) > 1):
1114
raise errors.UncommittedChanges(
1115
tree, more='Use --no-strict to force the push.')
1116
if tree.last_revision() != tree.branch.last_revision():
1117
# The tree has lost sync with its branch, there is little
1118
# chance that the user is aware of it but he can still force
1119
# the push with --no-strict
1120
raise errors.OutOfDateTree(
1121
tree, more='Use --no-strict to force the push.')
1123
# Get the stacked_on branch, if any
1124
if stacked_on is not None:
1125
stacked_on = urlutils.normalize_url(stacked_on)
1127
parent_url = br_from.get_parent()
1129
parent = Branch.open(parent_url)
1130
stacked_on = parent.get_public_branch()
1132
# I considered excluding non-http url's here, thus forcing
1133
# 'public' branches only, but that only works for some
1134
# users, so it's best to just depend on the user spotting an
1135
# error by the feedback given to them. RBC 20080227.
1136
stacked_on = parent_url
1138
raise errors.BzrCommandError(
1139
"Could not determine branch to refer to.")
1141
# Get the destination location
693
1142
if location is None:
1143
stored_loc = br_from.get_push_location()
694
1144
if stored_loc is None:
695
raise errors.BzrCommandError("No push location known or specified.")
1145
raise errors.BzrCommandError(
1146
"No push location known or specified.")
697
1148
display_url = urlutils.unescape_for_display(stored_loc,
698
1149
self.outf.encoding)
699
self.outf.write("Using saved location: %s\n" % display_url)
1150
self.outf.write("Using saved push location: %s\n" % display_url)
700
1151
location = stored_loc
702
to_transport = transport.get_transport(location)
704
br_to = repository_to = dir_to = None
706
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
707
except errors.NotBranchError:
708
pass # Didn't find anything
710
# If we can open a branch, use its direct repository, otherwise see
711
# if there is a repository without a branch.
713
br_to = dir_to.open_branch()
714
except errors.NotBranchError:
715
# Didn't find a branch, can we find a repository?
717
repository_to = dir_to.find_repository()
718
except errors.NoRepositoryPresent:
721
# Found a branch, so we must have found a repository
722
repository_to = br_to.repository
726
# The destination doesn't exist; create it.
727
# XXX: Refactor the create_prefix/no_create_prefix code into a
728
# common helper function
730
to_transport.mkdir('.')
731
except errors.FileExists:
732
if not use_existing_dir:
733
raise errors.BzrCommandError("Target directory %s"
734
" already exists, but does not have a valid .bzr"
735
" directory. Supply --use-existing-dir to push"
736
" there anyway." % location)
737
except errors.NoSuchFile:
738
if not create_prefix:
739
raise errors.BzrCommandError("Parent directory of %s"
741
"\nYou may supply --create-prefix to create all"
742
" leading parent directories."
745
_create_prefix(to_transport)
747
# Now the target directory exists, but doesn't have a .bzr
748
# directory. So we need to create it, along with any work to create
749
# all of the dependent branches, etc.
750
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
751
revision_id=br_from.last_revision())
752
br_to = dir_to.open_branch()
753
# TODO: Some more useful message about what was copied
754
note('Created new branch.')
755
# We successfully created the target, remember it
756
if br_from.get_push_location() is None or remember:
757
br_from.set_push_location(br_to.base)
758
elif repository_to is None:
759
# we have a bzrdir but no branch or repository
760
# XXX: Figure out what to do other than complain.
761
raise errors.BzrCommandError("At %s you have a valid .bzr control"
762
" directory, but not a branch or repository. This is an"
763
" unsupported configuration. Please move the target directory"
764
" out of the way and try again."
767
# We have a repository but no branch, copy the revisions, and then
769
last_revision_id = br_from.last_revision()
770
repository_to.fetch(br_from.repository,
771
revision_id=last_revision_id)
772
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
773
note('Created new branch.')
774
if br_from.get_push_location() is None or remember:
775
br_from.set_push_location(br_to.base)
776
else: # We have a valid to branch
777
# We were able to connect to the remote location, so remember it
778
# we don't need to successfully push because of possible divergence.
779
if br_from.get_push_location() is None or remember:
780
br_from.set_push_location(br_to.base)
781
old_rh = br_to.revision_history()
784
tree_to = dir_to.open_workingtree()
785
except errors.NotLocalUrl:
786
warning("This transport does not update the working "
787
"tree of: %s. See 'bzr help working-trees' for "
788
"more information." % br_to.base)
789
push_result = br_from.push(br_to, overwrite)
790
except errors.NoWorkingTree:
791
push_result = br_from.push(br_to, overwrite)
795
push_result = br_from.push(tree_to.branch, overwrite)
799
except errors.DivergedBranches:
800
raise errors.BzrCommandError('These branches have diverged.'
801
' Try using "merge" and then "push".')
802
if push_result is not None:
803
push_result.report(self.outf)
805
new_rh = br_to.revision_history()
808
from bzrlib.log import show_changed_revisions
809
show_changed_revisions(br_to, old_rh, new_rh,
812
# we probably did a clone rather than a push, so a message was
1153
_show_push_branch(br_from, revision_id, location, self.outf,
1154
verbose=verbose, overwrite=overwrite, remember=remember,
1155
stacked_on=stacked_on, create_prefix=create_prefix,
1156
use_existing_dir=use_existing_dir)
817
1159
class cmd_branch(Command):
818
"""Create a new copy of a branch.
1160
"""Create a new branch that is a copy of an existing branch.
820
1162
If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
821
1163
be used. In other words, "branch ../foo/bar" will attempt to create ./bar.
1563
2035
raise errors.BzrCommandError(msg)
2038
def _parse_levels(s):
2042
msg = "The levels argument must be an integer."
2043
raise errors.BzrCommandError(msg)
1566
2046
class cmd_log(Command):
1567
"""Show log of a branch, file, or directory.
1569
By default show the log of the branch containing the working directory.
1571
To request a range of logs, you can use the command -r begin..end
1572
-r revision requests a specific revision, -r ..end or -r begin.. are
1578
bzr log -r -10.. http://server/branch
2047
"""Show historical log for a branch or subset of a branch.
2049
log is bzr's default tool for exploring the history of a branch.
2050
The branch to use is taken from the first parameter. If no parameters
2051
are given, the branch containing the working directory is logged.
2052
Here are some simple examples::
2054
bzr log log the current branch
2055
bzr log foo.py log a file in its branch
2056
bzr log http://server/branch log a branch on a server
2058
The filtering, ordering and information shown for each revision can
2059
be controlled as explained below. By default, all revisions are
2060
shown sorted (topologically) so that newer revisions appear before
2061
older ones and descendants always appear before ancestors. If displayed,
2062
merged revisions are shown indented under the revision in which they
2067
The log format controls how information about each revision is
2068
displayed. The standard log formats are called ``long``, ``short``
2069
and ``line``. The default is long. See ``bzr help log-formats``
2070
for more details on log formats.
2072
The following options can be used to control what information is
2075
-l N display a maximum of N revisions
2076
-n N display N levels of revisions (0 for all, 1 for collapsed)
2077
-v display a status summary (delta) for each revision
2078
-p display a diff (patch) for each revision
2079
--show-ids display revision-ids (and file-ids), not just revnos
2081
Note that the default number of levels to display is a function of the
2082
log format. If the -n option is not used, the standard log formats show
2083
just the top level (mainline).
2085
Status summaries are shown using status flags like A, M, etc. To see
2086
the changes explained using words like ``added`` and ``modified``
2087
instead, use the -vv option.
2091
To display revisions from oldest to newest, use the --forward option.
2092
In most cases, using this option will have little impact on the total
2093
time taken to produce a log, though --forward does not incrementally
2094
display revisions like --reverse does when it can.
2096
:Revision filtering:
2098
The -r option can be used to specify what revision or range of revisions
2099
to filter against. The various forms are shown below::
2101
-rX display revision X
2102
-rX.. display revision X and later
2103
-r..Y display up to and including revision Y
2104
-rX..Y display from X to Y inclusive
2106
See ``bzr help revisionspec`` for details on how to specify X and Y.
2107
Some common examples are given below::
2109
-r-1 show just the tip
2110
-r-10.. show the last 10 mainline revisions
2111
-rsubmit:.. show what's new on this branch
2112
-rancestor:path.. show changes since the common ancestor of this
2113
branch and the one at location path
2114
-rdate:yesterday.. show changes since yesterday
2116
When logging a range of revisions using -rX..Y, log starts at
2117
revision Y and searches back in history through the primary
2118
("left-hand") parents until it finds X. When logging just the
2119
top level (using -n1), an error is reported if X is not found
2120
along the way. If multi-level logging is used (-n0), X may be
2121
a nested merge revision and the log will be truncated accordingly.
2125
If parameters are given and the first one is not a branch, the log
2126
will be filtered to show only those revisions that changed the
2127
nominated files or directories.
2129
Filenames are interpreted within their historical context. To log a
2130
deleted file, specify a revision range so that the file existed at
2131
the end or start of the range.
2133
Historical context is also important when interpreting pathnames of
2134
renamed files/directories. Consider the following example:
2136
* revision 1: add tutorial.txt
2137
* revision 2: modify tutorial.txt
2138
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
2142
* ``bzr log guide.txt`` will log the file added in revision 1
2144
* ``bzr log tutorial.txt`` will log the new file added in revision 3
2146
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2147
the original file in revision 2.
2149
* ``bzr log -r2 -p guide.txt`` will display an error message as there
2150
was no file called guide.txt in revision 2.
2152
Renames are always followed by log. By design, there is no need to
2153
explicitly ask for this (and no way to stop logging a file back
2154
until it was last renamed).
2158
The --message option can be used for finding revisions that match a
2159
regular expression in a commit message.
2163
GUI tools and IDEs are often better at exploring history than command
2164
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
2165
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2166
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2168
Web interfaces are often better at exploring history than command line
2169
tools, particularly for branches on servers. You may prefer Loggerhead
2170
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
2172
You may find it useful to add the aliases below to ``bazaar.conf``::
2176
top = log -l10 --line
2179
``bzr tip`` will then show the latest revision while ``bzr top``
2180
will show the last 10 mainline revisions. To see the details of a
2181
particular revision X, ``bzr show -rX``.
2183
If you are interested in looking deeper into a particular merge X,
2184
use ``bzr log -n0 -rX``.
2186
``bzr log -v`` on a branch with lots of history is currently
2187
very slow. A fix for this issue is currently under development.
2188
With or without that fix, it is recommended that a revision range
2189
be given when using the -v option.
2191
bzr has a generic full-text matching plugin, bzr-search, that can be
2192
used to find revisions matching user names, commit messages, etc.
2193
Among other features, this plugin can find all revisions containing
2194
a list of words but not others.
2196
When exploring non-mainline history on large projects with deep
2197
history, the performance of log can be greatly improved by installing
2198
the historycache plugin. This plugin buffers historical information
2199
trading disk space for faster speed.
1581
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1583
takes_args = ['location?']
1584
takes_options = [Option('forward',
1585
help='show from oldest to newest'),
1589
help='show files changed in each revision'),
1590
'show-ids', 'revision',
1594
help='show revisions whose message matches this regexp',
1597
help='limit the output to the first N revisions',
2201
takes_args = ['file*']
2202
_see_also = ['log-formats', 'revisionspec']
2205
help='Show from oldest to newest.'),
2207
custom_help('verbose',
2208
help='Show files changed in each revision.'),
2212
type=bzrlib.option._parse_revision_str,
2214
help='Show just the specified revision.'
2215
' See also "help revisionspec".'),
2219
help='Number of levels to display - 0 for all, 1 for flat.',
2221
type=_parse_levels),
2224
help='Show revisions whose message matches this '
2225
'regular expression.',
2229
help='Limit the output to the first N revisions.',
2234
help='Show changes made in each revision as a patch.'),
2235
Option('include-merges',
2236
help='Show merged revisions like --levels 0 does.'),
1600
2238
encoding_type = 'replace'
1602
2240
@display_command
1603
def run(self, location=None, timezone='original',
2241
def run(self, file_list=None, timezone='original',
1605
2243
show_ids=False,
1608
2247
log_format=None,
1611
from bzrlib.log import show_log
1612
assert message is None or isinstance(message, basestring), \
1613
"invalid message argument %r" % message
2252
include_merges=False):
2253
from bzrlib.log import (
2255
make_log_request_dict,
2256
_get_info_for_log_files,
1614
2258
direction = (forward and 'forward') or 'reverse'
1619
# find the file id to log:
1621
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
1625
tree = b.basis_tree()
1626
file_id = tree.path2id(fp)
1628
raise errors.BzrCommandError(
1629
"Path does not have any revision history: %s" %
1633
# FIXME ? log the current subdir only RBC 20060203
1634
if revision is not None \
1635
and len(revision) > 0 and revision[0].get_branch():
1636
location = revision[0].get_branch()
1639
dir, relpath = bzrdir.BzrDir.open_containing(location)
1640
b = dir.open_branch()
2263
raise errors.BzrCommandError(
2264
'--levels and --include-merges are mutually exclusive')
2266
if change is not None:
2268
raise errors.RangeInChangeOption()
2269
if revision is not None:
2270
raise errors.BzrCommandError(
2271
'--revision and --change are mutually exclusive')
2276
filter_by_dir = False
1644
if revision is None:
1647
elif len(revision) == 1:
1648
rev1 = rev2 = revision[0].in_history(b)
1649
elif len(revision) == 2:
1650
if revision[1].get_branch() != revision[0].get_branch():
1651
# b is taken from revision[0].get_branch(), and
1652
# show_log will use its revision_history. Having
1653
# different branches will lead to weird behaviors.
1654
raise errors.BzrCommandError(
1655
"Log doesn't accept two revisions in different"
1657
rev1 = revision[0].in_history(b)
1658
rev2 = revision[1].in_history(b)
1660
raise errors.BzrCommandError(
1661
'bzr log --revision takes one or two values.')
2280
# find the file ids to log and check for directory filtering
2281
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2282
revision, file_list)
2283
for relpath, file_id, kind in file_info_list:
2285
raise errors.BzrCommandError(
2286
"Path unknown at end or start of revision range: %s" %
2288
# If the relpath is the top of the tree, we log everything
2293
file_ids.append(file_id)
2294
filter_by_dir = filter_by_dir or (
2295
kind in ['directory', 'tree-reference'])
2298
# FIXME ? log the current subdir only RBC 20060203
2299
if revision is not None \
2300
and len(revision) > 0 and revision[0].get_branch():
2301
location = revision[0].get_branch()
2304
dir, relpath = bzrdir.BzrDir.open_containing(location)
2305
b = dir.open_branch()
2307
rev1, rev2 = _get_revision_range(revision, b, self.name())
2309
# Decide on the type of delta & diff filtering to use
2310
# TODO: add an --all-files option to make this configurable & consistent
2318
diff_type = 'partial'
2322
# Build the log formatter
1663
2323
if log_format is None:
1664
2324
log_format = log.log_formatter_registry.get_default(b)
1666
2325
lf = log_format(show_ids=show_ids, to_file=self.outf,
1667
show_timezone=timezone)
1673
direction=direction,
1674
start_revision=rev1,
2326
show_timezone=timezone,
2327
delta_format=get_verbosity_level(),
2329
show_advice=levels is None)
2331
# Choose the algorithm for doing the logging. It's annoying
2332
# having multiple code paths like this but necessary until
2333
# the underlying repository format is faster at generating
2334
# deltas or can provide everything we need from the indices.
2335
# The default algorithm - match-using-deltas - works for
2336
# multiple files and directories and is faster for small
2337
# amounts of history (200 revisions say). However, it's too
2338
# slow for logging a single file in a repository with deep
2339
# history, i.e. > 10K revisions. In the spirit of "do no
2340
# evil when adding features", we continue to use the
2341
# original algorithm - per-file-graph - for the "single
2342
# file that isn't a directory without showing a delta" case.
2343
partial_history = revision and b.repository._format.supports_chks
2344
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2345
or delta_type or partial_history)
2347
# Build the LogRequest and execute it
2348
if len(file_ids) == 0:
2350
rqst = make_log_request_dict(
2351
direction=direction, specific_fileids=file_ids,
2352
start_revision=rev1, end_revision=rev2, limit=limit,
2353
message_search=message, delta_type=delta_type,
2354
diff_type=diff_type, _match_using_deltas=match_using_deltas)
2355
Logger(b, rqst).show(lf)
2361
def _get_revision_range(revisionspec_list, branch, command_name):
2362
"""Take the input of a revision option and turn it into a revision range.
2364
It returns RevisionInfo objects which can be used to obtain the rev_id's
2365
of the desired revisions. It does some user input validations.
2367
if revisionspec_list is None:
2370
elif len(revisionspec_list) == 1:
2371
rev1 = rev2 = revisionspec_list[0].in_history(branch)
2372
elif len(revisionspec_list) == 2:
2373
start_spec = revisionspec_list[0]
2374
end_spec = revisionspec_list[1]
2375
if end_spec.get_branch() != start_spec.get_branch():
2376
# b is taken from revision[0].get_branch(), and
2377
# show_log will use its revision_history. Having
2378
# different branches will lead to weird behaviors.
2379
raise errors.BzrCommandError(
2380
"bzr %s doesn't accept two revisions in different"
2381
" branches." % command_name)
2382
rev1 = start_spec.in_history(branch)
2383
# Avoid loading all of history when we know a missing
2384
# end of range means the last revision ...
2385
if end_spec.spec is None:
2386
last_revno, last_revision_id = branch.last_revision_info()
2387
rev2 = RevisionInfo(branch, last_revno, last_revision_id)
2389
rev2 = end_spec.in_history(branch)
2391
raise errors.BzrCommandError(
2392
'bzr %s --revision takes one or two values.' % command_name)
2396
def _revision_range_to_revid_range(revision_range):
2399
if revision_range[0] is not None:
2400
rev_id1 = revision_range[0].rev_id
2401
if revision_range[1] is not None:
2402
rev_id2 = revision_range[1].rev_id
2403
return rev_id1, rev_id2
1682
2405
def get_log_format(long=False, short=False, line=False, default='long'):
1683
2406
log_format = default
2093
2929
# XXX: verbose currently does nothing
2095
_see_also = ['bugs', 'uncommit']
2931
_see_also = ['add', 'bugs', 'hooks', 'uncommit']
2096
2932
takes_args = ['selected*']
2097
takes_options = ['message', 'verbose',
2099
help='commit even if nothing has changed'),
2100
Option('file', type=str,
2103
help='file containing commit message'),
2105
help="refuse to commit if there are unknown "
2106
"files in the working tree."),
2107
ListOption('fixes', type=str,
2108
help="mark a bug as being fixed by this "
2111
help="perform a local only commit in a bound "
2112
"branch. Such commits are not pushed to "
2113
"the master branch until a normal commit "
2934
ListOption('exclude', type=str, short_name='x',
2935
help="Do not consider changes made to a given path."),
2936
Option('message', type=unicode,
2938
help="Description of the new revision."),
2941
help='Commit even if nothing has changed.'),
2942
Option('file', type=str,
2945
help='Take commit message from this file.'),
2947
help="Refuse to commit if there are unknown "
2948
"files in the working tree."),
2949
ListOption('fixes', type=str,
2950
help="Mark a bug as being fixed by this revision "
2951
"(see \"bzr help bugs\")."),
2952
ListOption('author', type=unicode,
2953
help="Set the author's name, if it's different "
2954
"from the committer."),
2956
help="Perform a local commit in a bound "
2957
"branch. Local commits are not pushed to "
2958
"the master branch until a normal commit "
2962
help='When no message is supplied, show the diff along'
2963
' with the status summary in the message editor.'),
2117
2965
aliases = ['ci', 'checkin']
2119
def _get_bug_fix_properties(self, fixes, branch):
2967
def _iter_bug_fix_urls(self, fixes, branch):
2121
2968
# Configure the properties for bug fixing attributes.
2122
2969
for fixed_bug in fixes:
2123
2970
tokens = fixed_bug.split(':')
2124
2971
if len(tokens) != 2:
2125
2972
raise errors.BzrCommandError(
2126
"Invalid bug %s. Must be in the form of 'tag:id'. "
2127
"Commit refused." % fixed_bug)
2973
"Invalid bug %s. Must be in the form of 'tracker:id'. "
2974
"See \"bzr help bugs\" for more information on this "
2975
"feature.\nCommit refused." % fixed_bug)
2128
2976
tag, bug_id = tokens
2130
bug_url = bugtracker.get_bug_url(tag, branch, bug_id)
2978
yield bugtracker.get_bug_url(tag, branch, bug_id)
2131
2979
except errors.UnknownBugTrackerAbbreviation:
2132
2980
raise errors.BzrCommandError(
2133
2981
'Unrecognized bug %s. Commit refused.' % fixed_bug)
2134
except errors.MalformedBugIdentifier:
2982
except errors.MalformedBugIdentifier, e:
2135
2983
raise errors.BzrCommandError(
2136
"Invalid bug identifier for %s. Commit refused."
2138
properties.append('%s fixed' % bug_url)
2139
return '\n'.join(properties)
2984
"%s\nCommit refused." % (str(e),))
2141
def run(self, message=None, file=None, verbose=True, selected_list=None,
2142
unchanged=False, strict=False, local=False, fixes=None):
2143
from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
2144
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
2146
from bzrlib.msgeditor import edit_commit_message, \
2147
make_commit_message_template
2986
def run(self, message=None, file=None, verbose=False, selected_list=None,
2987
unchanged=False, strict=False, local=False, fixes=None,
2988
author=None, show_diff=False, exclude=None):
2989
from bzrlib.errors import (
2994
from bzrlib.msgeditor import (
2995
edit_commit_message_encoded,
2996
generate_commit_message_template,
2997
make_commit_message_template_encoded
2149
3000
# TODO: Need a blackbox test for invoking the external editor; may be
2150
3001
# slightly problematic to run this cross-platform.
2152
# TODO: do more checks that the commit will succeed before
3003
# TODO: do more checks that the commit will succeed before
2153
3004
# spending the user's valuable time typing a commit message.
2155
3006
properties = {}
2394
3377
takes_args = ['testspecs*']
2395
3378
takes_options = ['verbose',
2397
help='stop when one test fails',
3380
help='Stop when one test fails.',
2398
3381
short_name='1',
2400
Option('keep-output',
2401
help='keep output directories when tests fail'),
2402
3383
Option('transport',
2403
3384
help='Use a different transport by default '
2404
3385
'throughout the test suite.',
2405
3386
type=get_transport_type),
2406
Option('benchmark', help='run the bzr benchmarks.'),
3388
help='Run the benchmarks rather than selftests.'),
2407
3389
Option('lsprof-timed',
2408
help='generate lsprof output for benchmarked'
3390
help='Generate lsprof output for benchmarked'
2409
3391
' sections of code.'),
2410
3392
Option('cache-dir', type=str,
2411
help='a directory to cache intermediate'
2412
' benchmark steps'),
2413
Option('clean-output',
2414
help='clean temporary tests directories'
2415
' without running tests'),
3393
help='Cache intermediate benchmark output in this '
2416
3395
Option('first',
2417
help='run all tests, but run specified tests first',
3396
help='Run all tests, but run specified tests first.',
2418
3397
short_name='f',
2420
Option('numbered-dirs',
2421
help='use numbered dirs for TestCaseInTempDir'),
2422
3399
Option('list-only',
2423
help='list the tests instead of running them'),
3400
help='List the tests instead of running them.'),
3401
RegistryOption('parallel',
3402
help="Run the test suite in parallel.",
3403
lazy_registry=('bzrlib.tests', 'parallel_registry'),
3404
value_switches=False,
2424
3406
Option('randomize', type=str, argname="SEED",
2425
help='randomize the order of tests using the given'
2426
' seed or "now" for the current time'),
3407
help='Randomize the order of tests using the given'
3408
' seed or "now" for the current time.'),
2427
3409
Option('exclude', type=str, argname="PATTERN",
2428
3410
short_name='x',
2429
help='exclude tests that match this regular'
3411
help='Exclude tests that match this regular'
3414
help='Output test progress via subunit.'),
3415
Option('strict', help='Fail on missing dependencies or '
3417
Option('load-list', type=str, argname='TESTLISTFILE',
3418
help='Load a test id list from a text file.'),
3419
ListOption('debugflag', type=str, short_name='E',
3420
help='Turn on a selftest debug flag.'),
3421
ListOption('starting-with', type=str, argname='TESTID',
3422
param_name='starting_with', short_name='s',
3424
'Load only the tests starting with TESTID.'),
2432
3426
encoding_type = 'replace'
2434
def run(self, testspecs_list=None, verbose=None, one=False,
2435
keep_output=False, transport=None, benchmark=None,
2436
lsprof_timed=None, cache_dir=None, clean_output=False,
2437
first=False, numbered_dirs=None, list_only=False,
2438
randomize=None, exclude=None):
3429
Command.__init__(self)
3430
self.additional_selftest_args = {}
3432
def run(self, testspecs_list=None, verbose=False, one=False,
3433
transport=None, benchmark=None,
3434
lsprof_timed=None, cache_dir=None,
3435
first=False, list_only=False,
3436
randomize=None, exclude=None, strict=False,
3437
load_list=None, debugflag=None, starting_with=None, subunit=False,
2440
3439
from bzrlib.tests import selftest
2441
3440
import bzrlib.benchmarks as benchmarks
2442
3441
from bzrlib.benchmarks import tree_creator
2445
from bzrlib.tests import clean_selftest_output
2446
clean_selftest_output()
2449
warning("notice: selftest --keep-output "
2450
"is no longer supported; "
2451
"test output is always removed")
2453
if numbered_dirs is None and sys.platform == 'win32':
2454
numbered_dirs = True
3443
# Make deprecation warnings visible, unless -Werror is set
3444
symbol_versioning.activate_deprecation_warnings(override=False)
2456
3446
if cache_dir is not None:
2457
3447
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2458
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2459
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
2461
3448
if testspecs_list is not None:
2462
3449
pattern = '|'.join(testspecs_list)
3454
from bzrlib.tests import SubUnitBzrRunner
3456
raise errors.BzrCommandError("subunit not available. subunit "
3457
"needs to be installed to use --subunit.")
3458
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3460
self.additional_selftest_args.setdefault(
3461
'suite_decorators', []).append(parallel)
2466
3463
test_suite_factory = benchmarks.test_suite
3464
# Unless user explicitly asks for quiet, be verbose in benchmarks
3465
verbose = not is_quiet()
2469
3466
# TODO: should possibly lock the history file...
2470
3467
benchfile = open(".perf_history", "at", buffering=1)
2472
3469
test_suite_factory = None
2475
3470
benchfile = None
2477
result = selftest(verbose=verbose,
2479
stop_on_failure=one,
2480
transport=transport,
2481
test_suite_factory=test_suite_factory,
2482
lsprof_timed=lsprof_timed,
2483
bench_history=benchfile,
2484
matching_tests_first=first,
2485
numbered_dirs=numbered_dirs,
2486
list_only=list_only,
2487
random_seed=randomize,
2488
exclude_pattern=exclude
3472
selftest_kwargs = {"verbose": verbose,
3474
"stop_on_failure": one,
3475
"transport": transport,
3476
"test_suite_factory": test_suite_factory,
3477
"lsprof_timed": lsprof_timed,
3478
"bench_history": benchfile,
3479
"matching_tests_first": first,
3480
"list_only": list_only,
3481
"random_seed": randomize,
3482
"exclude_pattern": exclude,
3484
"load_list": load_list,
3485
"debug_flags": debugflag,
3486
"starting_with": starting_with
3488
selftest_kwargs.update(self.additional_selftest_args)
3489
result = selftest(**selftest_kwargs)
2491
3491
if benchfile is not None:
2492
3492
benchfile.close()
2494
info('tests passed')
2496
info('tests failed')
2497
3493
return int(not result)
2500
3496
class cmd_version(Command):
2501
3497
"""Show version of bzr."""
3499
encoding_type = 'replace'
3501
Option("short", help="Print just the version number."),
2503
3504
@display_command
3505
def run(self, short=False):
2505
3506
from bzrlib.version import show_version
3508
self.outf.write(bzrlib.version_string + '\n')
3510
show_version(to_file=self.outf)
2509
3513
class cmd_rocks(Command):
2568
3585
directory, where they can be reviewed (with bzr diff), tested, and then
2569
3586
committed to record the result of the merge.
2573
To merge the latest revision from bzr.dev:
2574
bzr merge ../bzr.dev
2576
To merge changes up to and including revision 82 from bzr.dev:
2577
bzr merge -r 82 ../bzr.dev
2579
To merge the changes introduced by 82, without previous changes:
2580
bzr merge -r 81..82 ../bzr.dev
2582
3588
merge refuses to run if there are any uncommitted changes, unless
2583
3589
--force is given.
3591
To select only some changes to merge, use "merge -i", which will prompt
3592
you to apply each diff hunk and file change, similar to "shelve".
3595
To merge the latest revision from bzr.dev::
3597
bzr merge ../bzr.dev
3599
To merge changes up to and including revision 82 from bzr.dev::
3601
bzr merge -r 82 ../bzr.dev
3603
To merge the changes introduced by 82, without previous changes::
3605
bzr merge -r 81..82 ../bzr.dev
3607
To apply a merge directive contained in /tmp/merge:
3609
bzr merge /tmp/merge
2586
_see_also = ['update', 'remerge', 'status-flags']
2587
takes_args = ['branch?']
2588
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
3612
encoding_type = 'exact'
3613
_see_also = ['update', 'remerge', 'status-flags', 'send']
3614
takes_args = ['location?']
3619
help='Merge even if the destination tree has uncommitted changes.'),
2589
3623
Option('show-base', help="Show base revision text in "
2591
3625
Option('uncommitted', help='Apply uncommitted changes'
2592
' from a working copy, instead of branch changes'),
3626
' from a working copy, instead of branch changes.'),
2593
3627
Option('pull', help='If the destination is already'
2594
3628
' completely merged into the source, pull from the'
2595
' source rather than merging. When this happens,'
3629
' source rather than merging. When this happens,'
2596
3630
' you do not need to commit the result.'),
2597
3631
Option('directory',
2598
help='Branch to merge into, '
2599
'rather than the one containing the working directory',
3632
help='Branch to merge into, '
3633
'rather than the one containing the working directory.',
3637
Option('preview', help='Instead of merging, show a diff of the'
3639
Option('interactive', help='Select changes interactively.',
2605
def run(self, branch=None, revision=None, force=False, merge_type=None,
2606
show_base=False, reprocess=False, remember=False,
3643
def run(self, location=None, revision=None, force=False,
3644
merge_type=None, show_base=False, reprocess=None, remember=False,
2607
3645
uncommitted=False, pull=False,
2608
3646
directory=None,
2610
from bzrlib.tag import _merge_tags_if_possible
2611
other_revision_id = None
2612
3650
if merge_type is None:
2613
3651
merge_type = _mod_merge.Merge3Merger
2615
3653
if directory is None: directory = u'.'
2616
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2617
# inventory. Because merge is a mutating operation, it really
2618
# should be a lock_write() for the whole cmd_merge operation.
2619
# However, cmd_merge open's its own tree in _merge_helper, which
2620
# means if we lock here, the later lock_write() will always block.
2621
# Either the merge helper code should be updated to take a tree,
2622
# (What about tree.merge_from_branch?)
3654
possible_transports = []
3656
allow_pending = True
3657
verified = 'inapplicable'
2623
3658
tree = WorkingTree.open_containing(directory)[0]
3660
# die as quickly as possible if there are uncommitted changes
3662
basis_tree = tree.revision_tree(tree.last_revision())
3663
except errors.NoSuchRevision:
3664
basis_tree = tree.basis_tree()
3666
if tree.has_changes(basis_tree):
3667
raise errors.UncommittedChanges(tree)
3669
view_info = _get_view_info_for_change_reporter(tree)
2624
3670
change_reporter = delta._ChangeReporter(
2625
unversioned_filter=tree.is_ignored)
2627
if branch is not None:
2629
mergeable = bundle.read_mergeable_from_url(
2631
except errors.NotABundle:
2632
pass # Continue on considering this url a Branch
2634
if revision is not None:
2635
raise errors.BzrCommandError(
2636
'Cannot use -r with merge directives or bundles')
2637
other_revision_id = mergeable.install_revisions(
2638
tree.branch.repository)
2639
revision = [RevisionSpec.from_string(
2640
'revid:' + other_revision_id)]
2642
if revision is None \
2643
or len(revision) < 1 or revision[0].needs_branch():
2644
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2646
if revision is None or len(revision) < 1:
2649
other = [branch, None]
2652
other = [branch, -1]
2653
other_branch, path = Branch.open_containing(branch)
2656
raise errors.BzrCommandError('Cannot use --uncommitted and'
2657
' --revision at the same time.')
2658
branch = revision[0].get_branch() or branch
2659
if len(revision) == 1:
2661
if other_revision_id is not None:
3671
unversioned_filter=tree.is_ignored, view_info=view_info)
3674
pb = ui.ui_factory.nested_progress_bar()
3675
cleanups.append(pb.finished)
3677
cleanups.append(tree.unlock)
3678
if location is not None:
3680
mergeable = bundle.read_mergeable_from_url(location,
3681
possible_transports=possible_transports)
3682
except errors.NotABundle:
2666
other_branch, path = Branch.open_containing(branch)
2667
revno = revision[0].in_history(other_branch).revno
2668
other = [branch, revno]
2670
assert len(revision) == 2
2671
if None in revision:
2672
raise errors.BzrCommandError(
2673
"Merge doesn't permit empty revision specifier.")
2674
base_branch, path = Branch.open_containing(branch)
2675
branch1 = revision[1].get_branch() or branch
2676
other_branch, path1 = Branch.open_containing(branch1)
2677
if revision[0].get_branch() is not None:
2678
# then path was obtained from it, and is None.
2681
base = [branch, revision[0].in_history(base_branch).revno]
2682
other = [branch1, revision[1].in_history(other_branch).revno]
2684
if ((tree.branch.get_parent() is None or remember) and
2685
other_branch is not None):
2686
tree.branch.set_parent(other_branch.base)
2688
# pull tags now... it's a bit inconsistent to do it ahead of copying
2689
# the history but that's done inside the merge code
2690
if other_branch is not None:
2691
_merge_tags_if_possible(other_branch, tree.branch)
2694
interesting_files = [path]
2696
interesting_files = None
2697
pb = ui.ui_factory.nested_progress_bar()
2700
conflict_count = _merge_helper(
2701
other, base, other_rev_id=other_revision_id,
2702
check_clean=(not force),
2703
merge_type=merge_type,
2704
reprocess=reprocess,
2705
show_base=show_base,
2708
pb=pb, file_list=interesting_files,
2709
change_reporter=change_reporter)
2712
if conflict_count != 0:
3686
raise errors.BzrCommandError('Cannot use --uncommitted'
3687
' with bundles or merge directives.')
3689
if revision is not None:
3690
raise errors.BzrCommandError(
3691
'Cannot use -r with merge directives or bundles')
3692
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3695
if merger is None and uncommitted:
3696
if revision is not None and len(revision) > 0:
3697
raise errors.BzrCommandError('Cannot use --uncommitted and'
3698
' --revision at the same time.')
3699
merger = self.get_merger_from_uncommitted(tree, location, pb,
3701
allow_pending = False
3704
merger, allow_pending = self._get_merger_from_branch(tree,
3705
location, revision, remember, possible_transports, pb)
3707
merger.merge_type = merge_type
3708
merger.reprocess = reprocess
3709
merger.show_base = show_base
3710
self.sanity_check_merger(merger)
3711
if (merger.base_rev_id == merger.other_rev_id and
3712
merger.other_rev_id is not None):
3713
note('Nothing to do.')
2716
except errors.AmbiguousBase, e:
2717
m = ("sorry, bzr can't determine the right merge base yet\n"
2718
"candidates are:\n "
2719
+ "\n ".join(e.bases)
2721
"please specify an explicit base with -r,\n"
2722
"and (if you want) report this to the bzr developers\n")
2725
# TODO: move up to common parent; this isn't merge-specific anymore.
2726
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3716
if merger.interesting_files is not None:
3717
raise errors.BzrCommandError('Cannot pull individual files')
3718
if (merger.base_rev_id == tree.last_revision()):
3719
result = tree.pull(merger.other_branch, False,
3720
merger.other_rev_id)
3721
result.report(self.outf)
3723
merger.check_basis(False)
3725
return self._do_preview(merger, cleanups)
3727
return self._do_interactive(merger, cleanups)
3729
return self._do_merge(merger, change_reporter, allow_pending,
3732
for cleanup in reversed(cleanups):
3735
def _get_preview(self, merger, cleanups):
3736
tree_merger = merger.make_merger()
3737
tt = tree_merger.make_preview_transform()
3738
cleanups.append(tt.finalize)
3739
result_tree = tt.get_preview_tree()
3742
def _do_preview(self, merger, cleanups):
3743
from bzrlib.diff import show_diff_trees
3744
result_tree = self._get_preview(merger, cleanups)
3745
show_diff_trees(merger.this_tree, result_tree, self.outf,
3746
old_label='', new_label='')
3748
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3749
merger.change_reporter = change_reporter
3750
conflict_count = merger.do_merge()
3752
merger.set_pending()
3753
if verified == 'failed':
3754
warning('Preview patch does not match changes')
3755
if conflict_count != 0:
3760
def _do_interactive(self, merger, cleanups):
3761
"""Perform an interactive merge.
3763
This works by generating a preview tree of the merge, then using
3764
Shelver to selectively remove the differences between the working tree
3765
and the preview tree.
3767
from bzrlib import shelf_ui
3768
result_tree = self._get_preview(merger, cleanups)
3769
writer = bzrlib.option.diff_writer_registry.get()
3770
shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
3771
reporter=shelf_ui.ApplyReporter(),
3772
diff_writer=writer(sys.stdout))
3775
def sanity_check_merger(self, merger):
3776
if (merger.show_base and
3777
not merger.merge_type is _mod_merge.Merge3Merger):
3778
raise errors.BzrCommandError("Show-base is not supported for this"
3779
" merge type. %s" % merger.merge_type)
3780
if merger.reprocess is None:
3781
if merger.show_base:
3782
merger.reprocess = False
3784
# Use reprocess if the merger supports it
3785
merger.reprocess = merger.merge_type.supports_reprocess
3786
if merger.reprocess and not merger.merge_type.supports_reprocess:
3787
raise errors.BzrCommandError("Conflict reduction is not supported"
3788
" for merge type %s." %
3790
if merger.reprocess and merger.show_base:
3791
raise errors.BzrCommandError("Cannot do conflict reduction and"
3794
def _get_merger_from_branch(self, tree, location, revision, remember,
3795
possible_transports, pb):
3796
"""Produce a merger from a location, assuming it refers to a branch."""
3797
from bzrlib.tag import _merge_tags_if_possible
3798
# find the branch locations
3799
other_loc, user_location = self._select_branch_location(tree, location,
3801
if revision is not None and len(revision) == 2:
3802
base_loc, _unused = self._select_branch_location(tree,
3803
location, revision, 0)
3805
base_loc = other_loc
3807
other_branch, other_path = Branch.open_containing(other_loc,
3808
possible_transports)
3809
if base_loc == other_loc:
3810
base_branch = other_branch
3812
base_branch, base_path = Branch.open_containing(base_loc,
3813
possible_transports)
3814
# Find the revision ids
3815
other_revision_id = None
3816
base_revision_id = None
3817
if revision is not None:
3818
if len(revision) >= 1:
3819
other_revision_id = revision[-1].as_revision_id(other_branch)
3820
if len(revision) == 2:
3821
base_revision_id = revision[0].as_revision_id(base_branch)
3822
if other_revision_id is None:
3823
other_revision_id = _mod_revision.ensure_null(
3824
other_branch.last_revision())
3825
# Remember where we merge from
3826
if ((remember or tree.branch.get_submit_branch() is None) and
3827
user_location is not None):
3828
tree.branch.set_submit_branch(other_branch.base)
3829
_merge_tags_if_possible(other_branch, tree.branch)
3830
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3831
other_revision_id, base_revision_id, other_branch, base_branch)
3832
if other_path != '':
3833
allow_pending = False
3834
merger.interesting_files = [other_path]
3836
allow_pending = True
3837
return merger, allow_pending
3839
def get_merger_from_uncommitted(self, tree, location, pb, cleanups):
3840
"""Get a merger for uncommitted changes.
3842
:param tree: The tree the merger should apply to.
3843
:param location: The location containing uncommitted changes.
3844
:param pb: The progress bar to use for showing progress.
3845
:param cleanups: A list of operations to perform to clean up the
3846
temporary directories, unfinalized objects, etc.
3848
location = self._select_branch_location(tree, location)[0]
3849
other_tree, other_path = WorkingTree.open_containing(location)
3850
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree, pb)
3851
if other_path != '':
3852
merger.interesting_files = [other_path]
3855
def _select_branch_location(self, tree, user_location, revision=None,
3857
"""Select a branch location, according to possible inputs.
3859
If provided, branches from ``revision`` are preferred. (Both
3860
``revision`` and ``index`` must be supplied.)
3862
Otherwise, the ``location`` parameter is used. If it is None, then the
3863
``submit`` or ``parent`` location is used, and a note is printed.
3865
:param tree: The working tree to select a branch for merging into
3866
:param location: The location entered by the user
3867
:param revision: The revision parameter to the command
3868
:param index: The index to use for the revision parameter. Negative
3869
indices are permitted.
3870
:return: (selected_location, user_location). The default location
3871
will be the user-entered location.
3873
if (revision is not None and index is not None
3874
and revision[index] is not None):
3875
branch = revision[index].get_branch()
3876
if branch is not None:
3877
return branch, branch
3878
if user_location is None:
3879
location = self._get_remembered(tree, 'Merging from')
3881
location = user_location
3882
return location, user_location
3884
def _get_remembered(self, tree, verb_string):
2727
3885
"""Use tree.branch's parent if none was supplied.
2729
3887
Report if the remembered location was used.
2731
if supplied_location is not None:
2732
return supplied_location
2733
stored_location = tree.branch.get_parent()
3889
stored_location = tree.branch.get_submit_branch()
3890
stored_location_type = "submit"
3891
if stored_location is None:
3892
stored_location = tree.branch.get_parent()
3893
stored_location_type = "parent"
2734
3894
mutter("%s", stored_location)
2735
3895
if stored_location is None:
2736
3896
raise errors.BzrCommandError("No location specified or remembered")
2737
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2738
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3897
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3898
note(u"%s remembered %s location %s", verb_string,
3899
stored_location_type, display_url)
2739
3900
return stored_location
2913
4102
takes_args = ['context?']
2914
4103
aliases = ['s-c']
2917
4106
@display_command
2918
4107
def run(self, context=None):
2919
4108
import shellcomplete
2920
4109
shellcomplete.shellcomplete(context)
2923
class cmd_fetch(Command):
2924
"""Copy in history from another branch but don't merge it.
2926
This is an internal method used for pull and merge.
2929
takes_args = ['from_branch', 'to_branch']
2930
def run(self, from_branch, to_branch):
2931
from bzrlib.fetch import Fetcher
2932
from_b = Branch.open(from_branch)
2933
to_b = Branch.open(to_branch)
2934
Fetcher(to_b, from_b)
2937
4112
class cmd_missing(Command):
2938
4113
"""Show unmerged/unpulled revisions between two branches.
2940
4115
OTHER_BRANCH may be local or remote.
4117
To filter on a range of revisions, you can use the command -r begin..end
4118
-r revision requests a specific revision, -r ..end or -r begin.. are
4123
Determine the missing revisions between this and the branch at the
4124
remembered pull location::
4128
Determine the missing revisions between this and another branch::
4130
bzr missing http://server/branch
4132
Determine the missing revisions up to a specific revision on the other
4135
bzr missing -r ..-10
4137
Determine the missing revisions up to a specific revision on this
4140
bzr missing --my-revision ..-10
2943
4143
_see_also = ['merge', 'pull']
2944
4144
takes_args = ['other_branch?']
2945
takes_options = [Option('reverse', 'Reverse the order of revisions'),
2947
'Display changes in the local branch only'),
2948
Option('this' , 'same as --mine-only'),
2949
Option('theirs-only',
2950
'Display changes in the remote branch only'),
2951
Option('other', 'same as --theirs-only'),
4146
Option('reverse', 'Reverse the order of revisions.'),
4148
'Display changes in the local branch only.'),
4149
Option('this' , 'Same as --mine-only.'),
4150
Option('theirs-only',
4151
'Display changes in the remote branch only.'),
4152
Option('other', 'Same as --theirs-only.'),
4156
custom_help('revision',
4157
help='Filter on other branch revisions (inclusive). '
4158
'See "help revisionspec" for details.'),
4159
Option('my-revision',
4160
type=_parse_revision_str,
4161
help='Filter on local branch revisions (inclusive). '
4162
'See "help revisionspec" for details.'),
4163
Option('include-merges',
4164
'Show all revisions in addition to the mainline ones.'),
2956
4166
encoding_type = 'replace'
2958
4168
@display_command
2959
4169
def run(self, other_branch=None, reverse=False, mine_only=False,
2960
theirs_only=False, log_format=None, long=False, short=False, line=False,
2961
show_ids=False, verbose=False, this=False, other=False):
4171
log_format=None, long=False, short=False, line=False,
4172
show_ids=False, verbose=False, this=False, other=False,
4173
include_merges=False, revision=None, my_revision=None):
2962
4174
from bzrlib.missing import find_unmerged, iter_log_revisions
2963
from bzrlib.log import log_formatter
4183
# TODO: We should probably check that we don't have mine-only and
4184
# theirs-only set, but it gets complicated because we also have
4185
# this and other which could be used.
2970
4192
local_branch = Branch.open_containing(u".")[0]
2971
4193
parent = local_branch.get_parent()
2972
4194
if other_branch is None:
2973
4195
other_branch = parent
2974
4196
if other_branch is None:
2975
raise errors.BzrCommandError("No peer location known or specified.")
4197
raise errors.BzrCommandError("No peer location known"
2976
4199
display_url = urlutils.unescape_for_display(parent,
2977
4200
self.outf.encoding)
2978
print "Using last location: " + display_url
4201
message("Using saved parent location: "
4202
+ display_url + "\n")
2980
4204
remote_branch = Branch.open(other_branch)
2981
4205
if remote_branch.base == local_branch.base:
2982
4206
remote_branch = local_branch
4208
local_revid_range = _revision_range_to_revid_range(
4209
_get_revision_range(my_revision, local_branch,
4212
remote_revid_range = _revision_range_to_revid_range(
4213
_get_revision_range(revision,
4214
remote_branch, self.name()))
2983
4216
local_branch.lock_read()
2985
4218
remote_branch.lock_read()
2987
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2988
if (log_format is None):
2989
log_format = log.log_formatter_registry.get_default(
4220
local_extra, remote_extra = find_unmerged(
4221
local_branch, remote_branch, restrict,
4222
backward=not reverse,
4223
include_merges=include_merges,
4224
local_revid_range=local_revid_range,
4225
remote_revid_range=remote_revid_range)
4227
if log_format is None:
4228
registry = log.log_formatter_registry
4229
log_format = registry.get_default(local_branch)
2991
4230
lf = log_format(to_file=self.outf,
2992
4231
show_ids=show_ids,
2993
4232
show_timezone='original')
2994
if reverse is False:
2995
local_extra.reverse()
2996
remote_extra.reverse()
2997
4235
if local_extra and not theirs_only:
2998
print "You have %d extra revision(s):" % len(local_extra)
2999
for revision in iter_log_revisions(local_extra,
4236
message("You have %d extra revision(s):\n" %
4238
for revision in iter_log_revisions(local_extra,
3000
4239
local_branch.repository,
3002
4241
lf.log_revision(revision)
3003
4242
printed_local = True
3005
4245
printed_local = False
3006
4247
if remote_extra and not mine_only:
3007
4248
if printed_local is True:
3009
print "You are missing %d revision(s):" % len(remote_extra)
3010
for revision in iter_log_revisions(remote_extra,
3011
remote_branch.repository,
4250
message("You are missing %d revision(s):\n" %
4252
for revision in iter_log_revisions(remote_extra,
4253
remote_branch.repository,
3013
4255
lf.log_revision(revision)
3014
if not remote_extra and not local_extra:
3016
print "Branches are up to date."
3018
4256
status_code = 1
4258
if mine_only and not local_extra:
4259
# We checked local, and found nothing extra
4260
message('This branch is up to date.\n')
4261
elif theirs_only and not remote_extra:
4262
# We checked remote, and found nothing extra
4263
message('Other branch is up to date.\n')
4264
elif not (mine_only or theirs_only or local_extra or
4266
# We checked both branches, and neither one had extra
4268
message("Branches are up to date.\n")
3020
4270
remote_branch.unlock()
3567
4941
s.send_email(message)
4944
class cmd_send(Command):
4945
"""Mail or create a merge-directive for submitting changes.
4947
A merge directive provides many things needed for requesting merges:
4949
* A machine-readable description of the merge to perform
4951
* An optional patch that is a preview of the changes requested
4953
* An optional bundle of revision data, so that the changes can be applied
4954
directly from the merge directive, without retrieving data from a
4957
If --no-bundle is specified, then public_branch is needed (and must be
4958
up-to-date), so that the receiver can perform the merge using the
4959
public_branch. The public_branch is always included if known, so that
4960
people can check it later.
4962
The submit branch defaults to the parent, but can be overridden. Both
4963
submit branch and public branch will be remembered if supplied.
4965
If a public_branch is known for the submit_branch, that public submit
4966
branch is used in the merge instructions. This means that a local mirror
4967
can be used as your actual submit branch, once you have set public_branch
4970
Mail is sent using your preferred mail program. This should be transparent
4971
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4972
If the preferred client can't be found (or used), your editor will be used.
4974
To use a specific mail program, set the mail_client configuration option.
4975
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4976
specific clients are "claws", "evolution", "kmail", "mutt", and
4977
"thunderbird"; generic options are "default", "editor", "emacsclient",
4978
"mapi", and "xdg-email". Plugins may also add supported clients.
4980
If mail is being sent, a to address is required. This can be supplied
4981
either on the commandline, by setting the submit_to configuration
4982
option in the branch itself or the child_submit_to configuration option
4983
in the submit branch.
4985
Two formats are currently supported: "4" uses revision bundle format 4 and
4986
merge directive format 2. It is significantly faster and smaller than
4987
older formats. It is compatible with Bazaar 0.19 and later. It is the
4988
default. "0.9" uses revision bundle format 0.9 and merge directive
4989
format 1. It is compatible with Bazaar 0.12 - 0.18.
4991
The merge directives created by bzr send may be applied using bzr merge or
4992
bzr pull by specifying a file containing a merge directive as the location.
4995
encoding_type = 'exact'
4997
_see_also = ['merge', 'pull']
4999
takes_args = ['submit_branch?', 'public_branch?']
5003
help='Do not include a bundle in the merge directive.'),
5004
Option('no-patch', help='Do not include a preview patch in the merge'
5007
help='Remember submit and public branch.'),
5009
help='Branch to generate the submission from, '
5010
'rather than the one containing the working directory.',
5013
Option('output', short_name='o',
5014
help='Write merge directive to this file; '
5015
'use - for stdout.',
5018
help='Refuse to send if there are uncommitted changes in'
5019
' the working tree, --no-strict disables the check.'),
5020
Option('mail-to', help='Mail the request to this address.',
5024
Option('body', help='Body for the email.', type=unicode),
5025
RegistryOption('format',
5026
help='Use the specified output format.',
5027
lazy_registry=('bzrlib.send', 'format_registry')),
5030
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5031
no_patch=False, revision=None, remember=False, output=None,
5032
format=None, mail_to=None, message=None, body=None,
5033
strict=None, **kwargs):
5034
from bzrlib.send import send
5035
return send(submit_branch, revision, public_branch, remember,
5036
format, no_bundle, no_patch, output,
5037
kwargs.get('from', '.'), mail_to, message, body,
5042
class cmd_bundle_revisions(cmd_send):
5043
"""Create a merge-directive for submitting changes.
5045
A merge directive provides many things needed for requesting merges:
5047
* A machine-readable description of the merge to perform
5049
* An optional patch that is a preview of the changes requested
5051
* An optional bundle of revision data, so that the changes can be applied
5052
directly from the merge directive, without retrieving data from a
5055
If --no-bundle is specified, then public_branch is needed (and must be
5056
up-to-date), so that the receiver can perform the merge using the
5057
public_branch. The public_branch is always included if known, so that
5058
people can check it later.
5060
The submit branch defaults to the parent, but can be overridden. Both
5061
submit branch and public branch will be remembered if supplied.
5063
If a public_branch is known for the submit_branch, that public submit
5064
branch is used in the merge instructions. This means that a local mirror
5065
can be used as your actual submit branch, once you have set public_branch
5068
Two formats are currently supported: "4" uses revision bundle format 4 and
5069
merge directive format 2. It is significantly faster and smaller than
5070
older formats. It is compatible with Bazaar 0.19 and later. It is the
5071
default. "0.9" uses revision bundle format 0.9 and merge directive
5072
format 1. It is compatible with Bazaar 0.12 - 0.18.
5077
help='Do not include a bundle in the merge directive.'),
5078
Option('no-patch', help='Do not include a preview patch in the merge'
5081
help='Remember submit and public branch.'),
5083
help='Branch to generate the submission from, '
5084
'rather than the one containing the working directory.',
5087
Option('output', short_name='o', help='Write directive to this file.',
5090
help='Refuse to bundle revisions if there are uncommitted'
5091
' changes in the working tree, --no-strict disables the check.'),
5093
RegistryOption('format',
5094
help='Use the specified output format.',
5095
lazy_registry=('bzrlib.send', 'format_registry')),
5097
aliases = ['bundle']
5099
_see_also = ['send', 'merge']
5103
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5104
no_patch=False, revision=None, remember=False, output=None,
5105
format=None, strict=None, **kwargs):
5108
from bzrlib.send import send
5109
return send(submit_branch, revision, public_branch, remember,
5110
format, no_bundle, no_patch, output,
5111
kwargs.get('from', '.'), None, None, None,
5112
self.outf, strict=strict)
3570
5115
class cmd_tag(Command):
3571
"""Create a tag naming a revision.
5116
"""Create, remove or modify a tag naming a revision.
3573
5118
Tags give human-meaningful names to revisions. Commands that take a -r
3574
5119
(--revision) option can be given -rtag:X, where X is any previously
3630
5178
class cmd_tags(Command):
3633
This tag shows a table of tag names and the revisions they reference.
5181
This command shows a table of tag names and the revisions they reference.
3636
5184
_see_also = ['tag']
3637
5185
takes_options = [
3638
5186
Option('directory',
3639
help='Branch whose tags should be displayed',
5187
help='Branch whose tags should be displayed.',
3640
5188
short_name='d',
5191
RegistryOption.from_kwargs('sort',
5192
'Sort tags by different criteria.', title='Sorting',
5193
alpha='Sort tags lexicographically (default).',
5194
time='Sort tags chronologically.',
3645
5200
@display_command
3649
5207
branch, relpath = Branch.open_containing(directory)
3650
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3651
self.outf.write('%-20s %s\n' % (tag_name, target))
3654
# command-line interpretation helper for merge-related commands
3655
def _merge_helper(other_revision, base_revision,
3656
check_clean=True, ignore_zero=False,
3657
this_dir=None, backup_files=False,
3659
file_list=None, show_base=False, reprocess=False,
3662
change_reporter=None,
3664
"""Merge changes into a tree.
3667
list(path, revno) Base for three-way merge.
3668
If [None, None] then a base will be automatically determined.
3670
list(path, revno) Other revision for three-way merge.
3672
Directory to merge changes into; '.' by default.
3674
If true, this_dir must have no uncommitted changes before the
3676
ignore_zero - If true, suppress the "zero conflicts" message when
3677
there are no conflicts; should be set when doing something we expect
3678
to complete perfectly.
3679
file_list - If supplied, merge only changes to selected files.
3681
All available ancestors of other_revision and base_revision are
3682
automatically pulled into the branch.
3684
The revno may be -1 to indicate the last revision on the branch, which is
3687
This function is intended for use from the command line; programmatic
3688
clients might prefer to call merge.merge_inner(), which has less magic
3691
# Loading it late, so that we don't always have to import bzrlib.merge
3692
if merge_type is None:
3693
merge_type = _mod_merge.Merge3Merger
3694
if this_dir is None:
3696
this_tree = WorkingTree.open_containing(this_dir)[0]
3697
if show_base and not merge_type is _mod_merge.Merge3Merger:
3698
raise errors.BzrCommandError("Show-base is not supported for this merge"
3699
" type. %s" % merge_type)
3700
if reprocess and not merge_type.supports_reprocess:
3701
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3702
" type %s." % merge_type)
3703
if reprocess and show_base:
3704
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3705
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3706
# only want to take out a lock_tree_write() if we don't have to pull
3707
# any ancestry. But merge might fetch ancestry in the middle, in
3708
# which case we would need a lock_write().
3709
# Because we cannot upgrade locks, for now we live with the fact that
3710
# the tree will be locked multiple times during a merge. (Maybe
3711
# read-only some of the time, but it means things will get read
3714
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3715
pb=pb, change_reporter=change_reporter)
3716
merger.pp = ProgressPhase("Merge phase", 5, pb)
3717
merger.pp.next_phase()
3718
merger.check_basis(check_clean)
3719
if other_rev_id is not None:
3720
merger.set_other_revision(other_rev_id, this_tree.branch)
3722
merger.set_other(other_revision)
3723
merger.pp.next_phase()
3724
merger.set_base(base_revision)
3725
if merger.base_rev_id == merger.other_rev_id:
3726
note('Nothing to do.')
5209
tags = branch.tags.get_tag_dict().items()
5216
graph = branch.repository.get_graph()
5217
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5218
revid1, revid2 = rev1.rev_id, rev2.rev_id
5219
# only show revisions between revid1 and revid2 (inclusive)
5220
tags = [(tag, revid) for tag, revid in tags if
5221
graph.is_between(revid, revid1, revid2)]
5224
elif sort == 'time':
5226
for tag, revid in tags:
5228
revobj = branch.repository.get_revision(revid)
5229
except errors.NoSuchRevision:
5230
timestamp = sys.maxint # place them at the end
5232
timestamp = revobj.timestamp
5233
timestamps[revid] = timestamp
5234
tags.sort(key=lambda x: timestamps[x[1]])
5236
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5237
for index, (tag, revid) in enumerate(tags):
5239
revno = branch.revision_id_to_dotted_revno(revid)
5240
if isinstance(revno, tuple):
5241
revno = '.'.join(map(str, revno))
5242
except errors.NoSuchRevision:
5243
# Bad tag data/merges can lead to tagged revisions
5244
# which are not in this branch. Fail gracefully ...
5246
tags[index] = (tag, revno)
5249
for tag, revspec in tags:
5250
self.outf.write('%-20s %s\n' % (tag, revspec))
5253
class cmd_reconfigure(Command):
5254
"""Reconfigure the type of a bzr directory.
5256
A target configuration must be specified.
5258
For checkouts, the bind-to location will be auto-detected if not specified.
5259
The order of preference is
5260
1. For a lightweight checkout, the current bound location.
5261
2. For branches that used to be checkouts, the previously-bound location.
5262
3. The push location.
5263
4. The parent location.
5264
If none of these is available, --bind-to must be specified.
5267
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5268
takes_args = ['location?']
5270
RegistryOption.from_kwargs(
5272
title='Target type',
5273
help='The type to reconfigure the directory to.',
5274
value_switches=True, enum_switch=False,
5275
branch='Reconfigure to be an unbound branch with no working tree.',
5276
tree='Reconfigure to be an unbound branch with a working tree.',
5277
checkout='Reconfigure to be a bound branch with a working tree.',
5278
lightweight_checkout='Reconfigure to be a lightweight'
5279
' checkout (with no local history).',
5280
standalone='Reconfigure to be a standalone branch '
5281
'(i.e. stop using shared repository).',
5282
use_shared='Reconfigure to use a shared repository.',
5283
with_trees='Reconfigure repository to create '
5284
'working trees on branches by default.',
5285
with_no_trees='Reconfigure repository to not create '
5286
'working trees on branches by default.'
5288
Option('bind-to', help='Branch to bind checkout to.', type=str),
5290
help='Perform reconfiguration even if local changes'
5292
Option('stacked-on',
5293
help='Reconfigure a branch to be stacked on another branch.',
5297
help='Reconfigure a branch to be unstacked. This '
5298
'may require copying substantial data into it.',
5302
def run(self, location=None, target_type=None, bind_to=None, force=False,
5305
directory = bzrdir.BzrDir.open(location)
5306
if stacked_on and unstacked:
5307
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5308
elif stacked_on is not None:
5309
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5311
reconfigure.ReconfigureUnstacked().apply(directory)
5312
# At the moment you can use --stacked-on and a different
5313
# reconfiguration shape at the same time; there seems no good reason
5315
if target_type is None:
5316
if stacked_on or unstacked:
5319
raise errors.BzrCommandError('No target configuration '
5321
elif target_type == 'branch':
5322
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5323
elif target_type == 'tree':
5324
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5325
elif target_type == 'checkout':
5326
reconfiguration = reconfigure.Reconfigure.to_checkout(
5328
elif target_type == 'lightweight-checkout':
5329
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5331
elif target_type == 'use-shared':
5332
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5333
elif target_type == 'standalone':
5334
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5335
elif target_type == 'with-trees':
5336
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5338
elif target_type == 'with-no-trees':
5339
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5341
reconfiguration.apply(force)
5344
class cmd_switch(Command):
5345
"""Set the branch of a checkout and update.
5347
For lightweight checkouts, this changes the branch being referenced.
5348
For heavyweight checkouts, this checks that there are no local commits
5349
versus the current bound branch, then it makes the local branch a mirror
5350
of the new location and binds to it.
5352
In both cases, the working tree is updated and uncommitted changes
5353
are merged. The user can commit or revert these as they desire.
5355
Pending merges need to be committed or reverted before using switch.
5357
The path to the branch to switch to can be specified relative to the parent
5358
directory of the current branch. For example, if you are currently in a
5359
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5362
Bound branches use the nickname of its master branch unless it is set
5363
locally, in which case switching will update the the local nickname to be
5367
takes_args = ['to_location']
5368
takes_options = [Option('force',
5369
help='Switch even if local commits will be lost.'),
5370
Option('create-branch', short_name='b',
5371
help='Create the target branch from this one before'
5372
' switching to it.'),
5375
def run(self, to_location, force=False, create_branch=False):
5376
from bzrlib import switch
5378
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5380
branch = control_dir.open_branch()
5381
had_explicit_nick = branch.get_config().has_explicit_nickname()
5382
except errors.NotBranchError:
5384
had_explicit_nick = False
5387
raise errors.BzrCommandError('cannot create branch without'
5389
if '/' not in to_location and '\\' not in to_location:
5390
# This path is meant to be relative to the existing branch
5391
this_url = self._get_branch_location(control_dir)
5392
to_location = urlutils.join(this_url, '..', to_location)
5393
to_branch = branch.bzrdir.sprout(to_location,
5394
possible_transports=[branch.bzrdir.root_transport],
5395
source_branch=branch).open_branch()
5397
# from_branch = control_dir.open_branch()
5398
# except errors.NotBranchError:
5399
# raise BzrCommandError('Cannot create a branch from this'
5400
# ' location when we cannot open this branch')
5401
# from_branch.bzrdir.sprout(
5405
to_branch = Branch.open(to_location)
5406
except errors.NotBranchError:
5407
this_url = self._get_branch_location(control_dir)
5408
to_branch = Branch.open(
5409
urlutils.join(this_url, '..', to_location))
5410
switch.switch(control_dir, to_branch, force)
5411
if had_explicit_nick:
5412
branch = control_dir.open_branch() #get the new branch!
5413
branch.nick = to_branch.nick
5414
note('Switched to branch: %s',
5415
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5417
def _get_branch_location(self, control_dir):
5418
"""Return location of branch for this control dir."""
5420
this_branch = control_dir.open_branch()
5421
# This may be a heavy checkout, where we want the master branch
5422
master_location = this_branch.get_bound_location()
5423
if master_location is not None:
5424
return master_location
5425
# If not, use a local sibling
5426
return this_branch.base
5427
except errors.NotBranchError:
5428
format = control_dir.find_branch_format()
5429
if getattr(format, 'get_reference', None) is not None:
5430
return format.get_reference(control_dir)
5432
return control_dir.root_transport.base
5435
class cmd_view(Command):
5436
"""Manage filtered views.
5438
Views provide a mask over the tree so that users can focus on
5439
a subset of a tree when doing their work. After creating a view,
5440
commands that support a list of files - status, diff, commit, etc -
5441
effectively have that list of files implicitly given each time.
5442
An explicit list of files can still be given but those files
5443
must be within the current view.
5445
In most cases, a view has a short life-span: it is created to make
5446
a selected change and is deleted once that change is committed.
5447
At other times, you may wish to create one or more named views
5448
and switch between them.
5450
To disable the current view without deleting it, you can switch to
5451
the pseudo view called ``off``. This can be useful when you need
5452
to see the whole tree for an operation or two (e.g. merge) but
5453
want to switch back to your view after that.
5456
To define the current view::
5458
bzr view file1 dir1 ...
5460
To list the current view::
5464
To delete the current view::
5468
To disable the current view without deleting it::
5470
bzr view --switch off
5472
To define a named view and switch to it::
5474
bzr view --name view-name file1 dir1 ...
5476
To list a named view::
5478
bzr view --name view-name
5480
To delete a named view::
5482
bzr view --name view-name --delete
5484
To switch to a named view::
5486
bzr view --switch view-name
5488
To list all views defined::
5492
To delete all views::
5494
bzr view --delete --all
5498
takes_args = ['file*']
5501
help='Apply list or delete action to all views.',
5504
help='Delete the view.',
5507
help='Name of the view to define, list or delete.',
5511
help='Name of the view to switch to.',
5516
def run(self, file_list,
5522
tree, file_list = tree_files(file_list, apply_view=False)
5523
current_view, view_dict = tree.views.get_view_info()
5528
raise errors.BzrCommandError(
5529
"Both --delete and a file list specified")
5531
raise errors.BzrCommandError(
5532
"Both --delete and --switch specified")
5534
tree.views.set_view_info(None, {})
5535
self.outf.write("Deleted all views.\n")
5537
raise errors.BzrCommandError("No current view to delete")
5539
tree.views.delete_view(name)
5540
self.outf.write("Deleted '%s' view.\n" % name)
5543
raise errors.BzrCommandError(
5544
"Both --switch and a file list specified")
5546
raise errors.BzrCommandError(
5547
"Both --switch and --all specified")
5548
elif switch == 'off':
5549
if current_view is None:
5550
raise errors.BzrCommandError("No current view to disable")
5551
tree.views.set_view_info(None, view_dict)
5552
self.outf.write("Disabled '%s' view.\n" % (current_view))
5554
tree.views.set_view_info(switch, view_dict)
5555
view_str = views.view_display_str(tree.views.lookup_view())
5556
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5559
self.outf.write('Views defined:\n')
5560
for view in sorted(view_dict):
5561
if view == current_view:
5565
view_str = views.view_display_str(view_dict[view])
5566
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5568
self.outf.write('No views defined.\n')
5571
# No name given and no current view set
5574
raise errors.BzrCommandError(
5575
"Cannot change the 'off' pseudo view")
5576
tree.views.set_view(name, sorted(file_list))
5577
view_str = views.view_display_str(tree.views.lookup_view())
5578
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5582
# No name given and no current view set
5583
self.outf.write('No current view.\n')
5585
view_str = views.view_display_str(tree.views.lookup_view(name))
5586
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5589
class cmd_hooks(Command):
5595
for hook_key in sorted(hooks.known_hooks.keys()):
5596
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5597
self.outf.write("%s:\n" % type(some_hooks).__name__)
5598
for hook_name, hook_point in sorted(some_hooks.items()):
5599
self.outf.write(" %s:\n" % (hook_name,))
5600
found_hooks = list(hook_point)
5602
for hook in found_hooks:
5603
self.outf.write(" %s\n" %
5604
(some_hooks.get_hook_name(hook),))
5606
self.outf.write(" <no hooks installed>\n")
5609
class cmd_shelve(Command):
5610
"""Temporarily set aside some changes from the current tree.
5612
Shelve allows you to temporarily put changes you've made "on the shelf",
5613
ie. out of the way, until a later time when you can bring them back from
5614
the shelf with the 'unshelve' command. The changes are stored alongside
5615
your working tree, and so they aren't propagated along with your branch nor
5616
will they survive its deletion.
5618
If shelve --list is specified, previously-shelved changes are listed.
5620
Shelve is intended to help separate several sets of changes that have
5621
been inappropriately mingled. If you just want to get rid of all changes
5622
and you don't need to restore them later, use revert. If you want to
5623
shelve all text changes at once, use shelve --all.
5625
If filenames are specified, only the changes to those files will be
5626
shelved. Other files will be left untouched.
5628
If a revision is specified, changes since that revision will be shelved.
5630
You can put multiple items on the shelf, and by default, 'unshelve' will
5631
restore the most recently shelved changes.
5634
takes_args = ['file*']
5638
Option('all', help='Shelve all changes.'),
5640
RegistryOption('writer', 'Method to use for writing diffs.',
5641
bzrlib.option.diff_writer_registry,
5642
value_switches=True, enum_switch=False),
5644
Option('list', help='List shelved changes.'),
5646
help='Destroy removed changes instead of shelving them.'),
5648
_see_also = ['unshelve']
5650
def run(self, revision=None, all=False, file_list=None, message=None,
5651
writer=None, list=False, destroy=False):
5653
return self.run_for_list()
5654
from bzrlib.shelf_ui import Shelver
5656
writer = bzrlib.option.diff_writer_registry.get()
5658
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5659
file_list, message, destroy=destroy)
5663
shelver.work_tree.unlock()
5664
except errors.UserAbort:
3728
if file_list is None:
3729
if pull and merger.base_rev_id == merger.this_rev_id:
3730
# FIXME: deduplicate with pull
3731
result = merger.this_tree.pull(merger.this_branch,
3732
False, merger.other_rev_id)
3733
if result.old_revid == result.new_revid:
3734
note('No revisions to pull.')
3736
note('Now on revision %d.' % result.new_revno)
5667
def run_for_list(self):
5668
tree = WorkingTree.open_containing('.')[0]
5671
manager = tree.get_shelf_manager()
5672
shelves = manager.active_shelves()
5673
if len(shelves) == 0:
5674
note('No shelved changes.')
3738
merger.backup_files = backup_files
3739
merger.merge_type = merge_type
3740
merger.set_interesting_files(file_list)
3741
merger.show_base = show_base
3742
merger.reprocess = reprocess
3743
conflicts = merger.do_merge()
3744
if file_list is None:
3745
merger.set_pending()
3751
def _create_prefix(cur_transport):
3752
needed = [cur_transport]
3753
# Recurse upwards until we can create a directory successfully
3755
new_transport = cur_transport.clone('..')
3756
if new_transport.base == cur_transport.base:
3757
raise errors.BzrCommandError("Failed to create path"
5676
for shelf_id in reversed(shelves):
5677
message = manager.get_metadata(shelf_id).get('message')
5679
message = '<no message>'
5680
self.outf.write('%3d: %s\n' % (shelf_id, message))
5686
class cmd_unshelve(Command):
5687
"""Restore shelved changes.
5689
By default, the most recently shelved changes are restored. However if you
5690
specify a shelf by id those changes will be restored instead. This works
5691
best when the changes don't depend on each other.
5694
takes_args = ['shelf_id?']
5696
RegistryOption.from_kwargs(
5697
'action', help="The action to perform.",
5698
enum_switch=False, value_switches=True,
5699
apply="Apply changes and remove from the shelf.",
5700
dry_run="Show changes, but do not apply or remove them.",
5701
delete_only="Delete changes without applying them."
5704
_see_also = ['shelve']
5706
def run(self, shelf_id=None, action='apply'):
5707
from bzrlib.shelf_ui import Unshelver
5708
unshelver = Unshelver.from_args(shelf_id, action)
3761
new_transport.mkdir('.')
3762
except errors.NoSuchFile:
3763
needed.append(new_transport)
3764
cur_transport = new_transport
5712
unshelver.tree.unlock()
5715
class cmd_clean_tree(Command):
5716
"""Remove unwanted files from working tree.
5718
By default, only unknown files, not ignored files, are deleted. Versioned
5719
files are never deleted.
5721
Another class is 'detritus', which includes files emitted by bzr during
5722
normal operations and selftests. (The value of these files decreases with
5725
If no options are specified, unknown files are deleted. Otherwise, option
5726
flags are respected, and may be combined.
5728
To check what clean-tree will do, use --dry-run.
5730
takes_options = [Option('ignored', help='Delete all ignored files.'),
5731
Option('detritus', help='Delete conflict files, merge'
5732
' backups, and failed selftest dirs.'),
5734
help='Delete files unknown to bzr (default).'),
5735
Option('dry-run', help='Show files to delete instead of'
5737
Option('force', help='Do not prompt before deleting.')]
5738
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5740
from bzrlib.clean_tree import clean_tree
5741
if not (unknown or ignored or detritus):
5745
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5746
dry_run=dry_run, no_prompt=force)
5749
class cmd_reference(Command):
5750
"""list, view and set branch locations for nested trees.
5752
If no arguments are provided, lists the branch locations for nested trees.
5753
If one argument is provided, display the branch location for that tree.
5754
If two arguments are provided, set the branch location for that tree.
5759
takes_args = ['path?', 'location?']
5761
def run(self, path=None, location=None):
5763
if path is not None:
5765
tree, branch, relpath =(
5766
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5767
if path is not None:
5770
tree = branch.basis_tree()
5772
info = branch._get_all_reference_info().iteritems()
5773
self._display_reference_info(tree, branch, info)
3768
# Now we only need to create child directories
3770
cur_transport = needed.pop()
3771
cur_transport.ensure_base()
3774
merge = _merge_helper
5775
file_id = tree.path2id(path)
5777
raise errors.NotVersionedError(path)
5778
if location is None:
5779
info = [(file_id, branch.get_reference_info(file_id))]
5780
self._display_reference_info(tree, branch, info)
5782
branch.set_reference_info(file_id, path, location)
5784
def _display_reference_info(self, tree, branch, info):
5786
for file_id, (path, location) in info:
5788
path = tree.id2path(file_id)
5789
except errors.NoSuchId:
5791
ref_list.append((path, location))
5792
for path, location in sorted(ref_list):
5793
self.outf.write('%s %s\n' % (path, location))
3777
5796
# these get imported and then picked up by the scan for cmd_*
3778
5797
# TODO: Some more consistent way to split command definitions across files;
3779
# we do need to load at least some information about them to know of
5798
# we do need to load at least some information about them to know of
3780
5799
# aliases. ideally we would avoid loading the implementation until the
3781
5800
# details were needed.
3782
5801
from bzrlib.cmd_version_info import cmd_version_info
3783
5802
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3784
from bzrlib.bundle.commands import cmd_bundle_revisions
5803
from bzrlib.bundle.commands import (
5806
from bzrlib.foreign import cmd_dpush
3785
5807
from bzrlib.sign_my_commits import cmd_sign_my_commits
3786
from bzrlib.weave_commands import cmd_versionedfile_list, cmd_weave_join, \
5808
from bzrlib.weave_commands import cmd_versionedfile_list, \
3787
5809
cmd_weave_plan_merge, cmd_weave_merge_text