997
666
location can be accessed.
1000
_see_also = ['pull', 'update', 'working-trees']
1001
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
669
takes_options = ['remember', 'overwrite', 'verbose',
1002
670
Option('create-prefix',
1003
671
help='Create the path leading up to the branch '
1004
'if it does not already exist.'),
672
'if it does not already exist'),
1005
673
Option('directory',
1006
help='Branch to push from, '
1007
'rather than the one containing the working directory.',
674
help='branch to push from, '
675
'rather than the one containing the working directory',
1011
679
Option('use-existing-dir',
1012
680
help='By default push will fail if the target'
1013
681
' directory exists, but does not already'
1014
' have a control directory. This flag will'
682
' have a control directory. This flag will'
1015
683
' allow push to proceed.'),
1017
help='Create a stacked branch that references the public location '
1018
'of the parent branch.'),
1019
Option('stacked-on',
1020
help='Create a stacked branch that refers to another branch '
1021
'for the commit history. Only the work not present in the '
1022
'referenced branch is included in the branch created.',
1025
685
takes_args = ['location?']
1026
686
encoding_type = 'replace'
1028
688
def run(self, location=None, remember=False, overwrite=False,
1029
create_prefix=False, verbose=False, revision=None,
1030
use_existing_dir=False, directory=None, stacked_on=None,
1032
from bzrlib.push import _show_push_branch
1034
# Get the source branch and revision_id
689
create_prefix=False, verbose=False,
690
use_existing_dir=False,
692
# FIXME: Way too big! Put this into a function called from the
1035
694
if directory is None:
1037
696
br_from = Branch.open_containing(directory)[0]
1038
revision = _get_one_revision('push', revision)
1039
if revision is not None:
1040
revision_id = revision.in_history(br_from).rev_id
1044
# Get the stacked_on branch, if any
1045
if stacked_on is not None:
1046
stacked_on = urlutils.normalize_url(stacked_on)
1048
parent_url = br_from.get_parent()
1050
parent = Branch.open(parent_url)
1051
stacked_on = parent.get_public_branch()
1053
# I considered excluding non-http url's here, thus forcing
1054
# 'public' branches only, but that only works for some
1055
# users, so it's best to just depend on the user spotting an
1056
# error by the feedback given to them. RBC 20080227.
1057
stacked_on = parent_url
1059
raise errors.BzrCommandError(
1060
"Could not determine branch to refer to.")
1062
# Get the destination location
697
stored_loc = br_from.get_push_location()
1063
698
if location is None:
1064
stored_loc = br_from.get_push_location()
1065
699
if stored_loc is None:
1066
raise errors.BzrCommandError(
1067
"No push location known or specified.")
700
raise errors.BzrCommandError("No push location known or specified.")
1069
702
display_url = urlutils.unescape_for_display(stored_loc,
1070
703
self.outf.encoding)
1071
self.outf.write("Using saved push location: %s\n" % display_url)
704
self.outf.write("Using saved location: %s\n" % display_url)
1072
705
location = stored_loc
1074
_show_push_branch(br_from, revision_id, location, self.outf,
1075
verbose=verbose, overwrite=overwrite, remember=remember,
1076
stacked_on=stacked_on, create_prefix=create_prefix,
1077
use_existing_dir=use_existing_dir)
707
to_transport = transport.get_transport(location)
708
location_url = to_transport.base
710
br_to = repository_to = dir_to = None
712
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
713
except errors.NotBranchError:
714
pass # Didn't find anything
716
# If we can open a branch, use its direct repository, otherwise see
717
# if there is a repository without a branch.
719
br_to = dir_to.open_branch()
720
except errors.NotBranchError:
721
# Didn't find a branch, can we find a repository?
723
repository_to = dir_to.find_repository()
724
except errors.NoRepositoryPresent:
727
# Found a branch, so we must have found a repository
728
repository_to = br_to.repository
732
# The destination doesn't exist; create it.
733
# XXX: Refactor the create_prefix/no_create_prefix code into a
734
# common helper function
736
to_transport.mkdir('.')
737
except errors.FileExists:
738
if not use_existing_dir:
739
raise errors.BzrCommandError("Target directory %s"
740
" already exists, but does not have a valid .bzr"
741
" directory. Supply --use-existing-dir to push"
742
" there anyway." % location)
743
except errors.NoSuchFile:
744
if not create_prefix:
745
raise errors.BzrCommandError("Parent directory of %s"
747
"\nYou may supply --create-prefix to create all"
748
" leading parent directories."
751
cur_transport = to_transport
752
needed = [cur_transport]
753
# Recurse upwards until we can create a directory successfully
755
new_transport = cur_transport.clone('..')
756
if new_transport.base == cur_transport.base:
757
raise errors.BzrCommandError("Failed to create path"
761
new_transport.mkdir('.')
762
except errors.NoSuchFile:
763
needed.append(new_transport)
764
cur_transport = new_transport
768
# Now we only need to create child directories
770
cur_transport = needed.pop()
771
cur_transport.mkdir('.')
773
# Now the target directory exists, but doesn't have a .bzr
774
# directory. So we need to create it, along with any work to create
775
# all of the dependent branches, etc.
776
dir_to = br_from.bzrdir.clone(location_url,
777
revision_id=br_from.last_revision())
778
br_to = dir_to.open_branch()
779
# TODO: Some more useful message about what was copied
780
note('Created new branch.')
781
# We successfully created the target, remember it
782
if br_from.get_push_location() is None or remember:
783
br_from.set_push_location(br_to.base)
784
elif repository_to is None:
785
# we have a bzrdir but no branch or repository
786
# XXX: Figure out what to do other than complain.
787
raise errors.BzrCommandError("At %s you have a valid .bzr control"
788
" directory, but not a branch or repository. This is an"
789
" unsupported configuration. Please move the target directory"
790
" out of the way and try again."
793
# We have a repository but no branch, copy the revisions, and then
795
last_revision_id = br_from.last_revision()
796
repository_to.fetch(br_from.repository,
797
revision_id=last_revision_id)
798
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
799
note('Created new branch.')
800
if br_from.get_push_location() is None or remember:
801
br_from.set_push_location(br_to.base)
802
else: # We have a valid to branch
803
# We were able to connect to the remote location, so remember it
804
# we don't need to successfully push because of possible divergence.
805
if br_from.get_push_location() is None or remember:
806
br_from.set_push_location(br_to.base)
807
old_rh = br_to.revision_history()
810
tree_to = dir_to.open_workingtree()
811
except errors.NotLocalUrl:
812
warning('This transport does not update the working '
813
'tree of: %s' % (br_to.base,))
814
push_result = br_from.push(br_to, overwrite)
815
except errors.NoWorkingTree:
816
push_result = br_from.push(br_to, overwrite)
820
push_result = br_from.push(tree_to.branch, overwrite)
824
except errors.DivergedBranches:
825
raise errors.BzrCommandError('These branches have diverged.'
826
' Try using "merge" and then "push".')
827
if push_result is not None:
828
push_result.report(self.outf)
830
new_rh = br_to.revision_history()
833
from bzrlib.log import show_changed_revisions
834
show_changed_revisions(br_to, old_rh, new_rh,
837
# we probably did a clone rather than a push, so a message was
1080
842
class cmd_branch(Command):
1324
1048
"""Show information about a working tree, branch or repository.
1326
1050
This command will show all known locations and formats associated to the
1327
tree, branch or repository.
1329
In verbose mode, statistical information is included with each report.
1330
To see extended statistic information, use a verbosity level of 2 or
1331
higher by specifying the verbose option multiple times, e.g. -vv.
1051
tree, branch or repository. Statistical information is included with
1333
1054
Branches and working trees will also report any missing revisions.
1337
Display information on the format and related locations:
1341
Display the above together with extended format information and
1342
basic statistics (like the number of files in the working tree and
1343
number of revisions in the branch and repository):
1347
Display the above together with number of committers to the branch:
1351
_see_also = ['revno', 'working-trees', 'repositories']
1352
1056
takes_args = ['location?']
1353
1057
takes_options = ['verbose']
1354
encoding_type = 'replace'
1356
1059
@display_command
1357
1060
def run(self, location=None, verbose=False):
1359
noise_level = get_verbosity_level()
1362
1061
from bzrlib.info import show_bzrdir_info
1363
1062
show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1364
verbose=noise_level, outfile=self.outf)
1367
1066
class cmd_remove(Command):
1368
"""Remove files or directories.
1370
This makes bzr stop tracking changes to the specified files. bzr will delete
1371
them if they can easily be recovered using revert. If no options or
1372
parameters are given bzr will scan for files that are being tracked by bzr
1373
but missing in your tree and stop tracking them for you.
1067
"""Make a file unversioned.
1069
This makes bzr stop tracking changes to a versioned file. It does
1070
not delete the working copy.
1072
You can specify one or more files, and/or --new. If you specify --new,
1073
only 'added' files will be removed. If you specify both, then new files
1074
in the specified directories will be removed. If the directories are
1075
also new, they will also be removed.
1375
1077
takes_args = ['file*']
1376
takes_options = ['verbose',
1377
Option('new', help='Only remove files that have never been committed.'),
1378
RegistryOption.from_kwargs('file-deletion-strategy',
1379
'The file deletion mode to be used.',
1380
title='Deletion Strategy', value_switches=True, enum_switch=False,
1381
safe='Only delete files if they can be'
1382
' safely recovered (default).',
1383
keep="Don't delete any files.",
1384
force='Delete all the specified files, even if they can not be '
1385
'recovered and even if they are non-empty directories.')]
1386
aliases = ['rm', 'del']
1078
takes_options = ['verbose', Option('new', help='remove newly-added files')]
1387
1080
encoding_type = 'replace'
1389
def run(self, file_list, verbose=False, new=False,
1390
file_deletion_strategy='safe'):
1082
def run(self, file_list, verbose=False, new=False):
1391
1083
tree, file_list = tree_files(file_list)
1393
if file_list is not None:
1394
file_list = [f for f in file_list]
1398
# Heuristics should probably all move into tree.remove_smart or
1401
added = tree.changes_from(tree.basis_tree(),
1402
specific_files=file_list).added
1403
file_list = sorted([f[0] for f in added], reverse=True)
1404
if len(file_list) == 0:
1405
raise errors.BzrCommandError('No matching files.')
1406
elif file_list is None:
1407
# missing files show up in iter_changes(basis) as
1408
# versioned-with-no-kind.
1410
for change in tree.iter_changes(tree.basis_tree()):
1411
# Find paths in the working tree that have no kind:
1412
if change[1][1] is not None and change[6][1] is None:
1413
missing.append(change[1][1])
1414
file_list = sorted(missing, reverse=True)
1415
file_deletion_strategy = 'keep'
1416
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1417
keep_files=file_deletion_strategy=='keep',
1418
force=file_deletion_strategy=='force')
1085
if file_list is None:
1086
raise errors.BzrCommandError('Specify one or more files to'
1087
' remove, or use --new.')
1089
added = tree.changes_from(tree.basis_tree(),
1090
specific_files=file_list).added
1091
file_list = sorted([f[0] for f in added], reverse=True)
1092
if len(file_list) == 0:
1093
raise errors.BzrCommandError('No matching files.')
1094
tree.remove(file_list, verbose=verbose, to_file=self.outf)
1423
1097
class cmd_file_id(Command):
1922
1528
self.outf.write(tree.basedir + '\n')
1925
def _parse_limit(limitstring):
1927
return int(limitstring)
1929
msg = "The limit argument must be an integer."
1930
raise errors.BzrCommandError(msg)
1933
def _parse_levels(s):
1937
msg = "The levels argument must be an integer."
1938
raise errors.BzrCommandError(msg)
1941
1531
class cmd_log(Command):
1942
"""Show historical log for a branch or subset of a branch.
1944
log is bzr's default tool for exploring the history of a branch.
1945
The branch to use is taken from the first parameter. If no parameters
1946
are given, the branch containing the working directory is logged.
1947
Here are some simple examples::
1949
bzr log log the current branch
1950
bzr log foo.py log a file in its branch
1951
bzr log http://server/branch log a branch on a server
1953
The filtering, ordering and information shown for each revision can
1954
be controlled as explained below. By default, all revisions are
1955
shown sorted (topologically) so that newer revisions appear before
1956
older ones and descendants always appear before ancestors. If displayed,
1957
merged revisions are shown indented under the revision in which they
1962
The log format controls how information about each revision is
1963
displayed. The standard log formats are called ``long``, ``short``
1964
and ``line``. The default is long. See ``bzr help log-formats``
1965
for more details on log formats.
1967
The following options can be used to control what information is
1970
-l N display a maximum of N revisions
1971
-n N display N levels of revisions (0 for all, 1 for collapsed)
1972
-v display a status summary (delta) for each revision
1973
-p display a diff (patch) for each revision
1974
--show-ids display revision-ids (and file-ids), not just revnos
1976
Note that the default number of levels to display is a function of the
1977
log format. If the -n option is not used, the standard log formats show
1978
just the top level (mainline).
1980
Status summaries are shown using status flags like A, M, etc. To see
1981
the changes explained using words like ``added`` and ``modified``
1982
instead, use the -vv option.
1986
To display revisions from oldest to newest, use the --forward option.
1987
In most cases, using this option will have little impact on the total
1988
time taken to produce a log, though --forward does not incrementally
1989
display revisions like --reverse does when it can.
1991
:Revision filtering:
1993
The -r option can be used to specify what revision or range of revisions
1994
to filter against. The various forms are shown below::
1996
-rX display revision X
1997
-rX.. display revision X and later
1998
-r..Y display up to and including revision Y
1999
-rX..Y display from X to Y inclusive
2001
See ``bzr help revisionspec`` for details on how to specify X and Y.
2002
Some common examples are given below::
2004
-r-1 show just the tip
2005
-r-10.. show the last 10 mainline revisions
2006
-rsubmit:.. show what's new on this branch
2007
-rancestor:path.. show changes since the common ancestor of this
2008
branch and the one at location path
2009
-rdate:yesterday.. show changes since yesterday
2011
When logging a range of revisions using -rX..Y, log starts at
2012
revision Y and searches back in history through the primary
2013
("left-hand") parents until it finds X. When logging just the
2014
top level (using -n1), an error is reported if X is not found
2015
along the way. If multi-level logging is used (-n0), X may be
2016
a nested merge revision and the log will be truncated accordingly.
2020
If parameters are given and the first one is not a branch, the log
2021
will be filtered to show only those revisions that changed the
2022
nominated files or directories.
2024
Filenames are interpreted within their historical context. To log a
2025
deleted file, specify a revision range so that the file existed at
2026
the end or start of the range.
2028
Historical context is also important when interpreting pathnames of
2029
renamed files/directories. Consider the following example:
2031
* revision 1: add tutorial.txt
2032
* revision 2: modify tutorial.txt
2033
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
2037
* ``bzr log guide.txt`` will log the file added in revision 1
2039
* ``bzr log tutorial.txt`` will log the new file added in revision 3
2041
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2042
the original file in revision 2.
2044
* ``bzr log -r2 -p guide.txt`` will display an error message as there
2045
was no file called guide.txt in revision 2.
2047
Renames are always followed by log. By design, there is no need to
2048
explicitly ask for this (and no way to stop logging a file back
2049
until it was last renamed).
2053
The --message option can be used for finding revisions that match a
2054
regular expression in a commit message.
2058
GUI tools and IDEs are often better at exploring history than command
2059
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
2060
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2061
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2063
Web interfaces are often better at exploring history than command line
2064
tools, particularly for branches on servers. You may prefer Loggerhead
2065
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
2067
You may find it useful to add the aliases below to ``bazaar.conf``::
2071
top = log -l10 --line
2074
``bzr tip`` will then show the latest revision while ``bzr top``
2075
will show the last 10 mainline revisions. To see the details of a
2076
particular revision X, ``bzr show -rX``.
2078
If you are interested in looking deeper into a particular merge X,
2079
use ``bzr log -n0 -rX``.
2081
``bzr log -v`` on a branch with lots of history is currently
2082
very slow. A fix for this issue is currently under development.
2083
With or without that fix, it is recommended that a revision range
2084
be given when using the -v option.
2086
bzr has a generic full-text matching plugin, bzr-search, that can be
2087
used to find revisions matching user names, commit messages, etc.
2088
Among other features, this plugin can find all revisions containing
2089
a list of words but not others.
2091
When exploring non-mainline history on large projects with deep
2092
history, the performance of log can be greatly improved by installing
2093
the historycache plugin. This plugin buffers historical information
2094
trading disk space for faster speed.
1532
"""Show log of a branch, file, or directory.
1534
By default show the log of the branch containing the working directory.
1536
To request a range of logs, you can use the command -r begin..end
1537
-r revision requests a specific revision, -r ..end or -r begin.. are
1543
bzr log -r -10.. http://server/branch
2096
takes_args = ['file*']
2097
_see_also = ['log-formats', 'revisionspec']
2100
help='Show from oldest to newest.'),
2102
custom_help('verbose',
2103
help='Show files changed in each revision.'),
2107
type=bzrlib.option._parse_revision_str,
2109
help='Show just the specified revision.'
2110
' See also "help revisionspec".'),
2114
help='Number of levels to display - 0 for all, 1 for flat.',
2116
type=_parse_levels),
2119
help='Show revisions whose message matches this '
2120
'regular expression.',
2124
help='Limit the output to the first N revisions.',
2129
help='Show changes made in each revision as a patch.'),
2130
Option('include-merges',
2131
help='Show merged revisions like --levels 0 does.'),
1546
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1548
takes_args = ['location?']
1549
takes_options = [Option('forward',
1550
help='show from oldest to newest'),
1554
help='show files changed in each revision'),
1555
'show-ids', 'revision',
1559
help='show revisions whose message matches this regexp',
2133
1562
encoding_type = 'replace'
2135
1564
@display_command
2136
def run(self, file_list=None, timezone='original',
1565
def run(self, location=None, timezone='original',
2138
1567
show_ids=False,
2142
1570
log_format=None,
2147
include_merges=False):
2148
from bzrlib.log import (
2150
make_log_request_dict,
2151
_get_info_for_log_files,
1572
from bzrlib.log import show_log
1573
assert message is None or isinstance(message, basestring), \
1574
"invalid message argument %r" % message
2153
1575
direction = (forward and 'forward') or 'reverse'
2158
raise errors.BzrCommandError(
2159
'--levels and --include-merges are mutually exclusive')
2161
if change is not None:
2163
raise errors.RangeInChangeOption()
2164
if revision is not None:
2165
raise errors.BzrCommandError(
2166
'--revision and --change are mutually exclusive')
2171
filter_by_dir = False
2173
# find the file ids to log and check for directory filtering
2174
b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2176
for relpath, file_id, kind in file_info_list:
1580
# find the file id to log:
1582
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
1586
tree = b.basis_tree()
1587
file_id = tree.path2id(fp)
2177
1588
if file_id is None:
2178
1589
raise errors.BzrCommandError(
2179
"Path unknown at end or start of revision range: %s" %
2181
# If the relpath is the top of the tree, we log everything
2186
file_ids.append(file_id)
2187
filter_by_dir = filter_by_dir or (
2188
kind in ['directory', 'tree-reference'])
1590
"Path does not have any revision history: %s" %
2191
# FIXME ? log the current subdir only RBC 20060203
1594
# FIXME ? log the current subdir only RBC 20060203
2192
1595
if revision is not None \
2193
1596
and len(revision) > 0 and revision[0].get_branch():
2194
1597
location = revision[0].get_branch()
2197
1600
dir, relpath = bzrdir.BzrDir.open_containing(location)
2198
1601
b = dir.open_branch()
2199
rev1, rev2 = _get_revision_range(revision, b, self.name())
2201
# Decide on the type of delta & diff filtering to use
2202
# TODO: add an --all-files option to make this configurable & consistent
2210
diff_type = 'partial'
2216
# Build the log formatter
1605
if revision is None:
1608
elif len(revision) == 1:
1609
rev1 = rev2 = revision[0].in_history(b).revno
1610
elif len(revision) == 2:
1611
if revision[1].get_branch() != revision[0].get_branch():
1612
# b is taken from revision[0].get_branch(), and
1613
# show_log will use its revision_history. Having
1614
# different branches will lead to weird behaviors.
1615
raise errors.BzrCommandError(
1616
"Log doesn't accept two revisions in different"
1618
if revision[0].spec is None:
1619
# missing begin-range means first revision
1622
rev1 = revision[0].in_history(b).revno
1624
if revision[1].spec is None:
1625
# missing end-range means last known revision
1628
rev2 = revision[1].in_history(b).revno
1630
raise errors.BzrCommandError(
1631
'bzr log --revision takes one or two values.')
1633
# By this point, the revision numbers are converted to the +ve
1634
# form if they were supplied in the -ve form, so we can do
1635
# this comparison in relative safety
1637
(rev2, rev1) = (rev1, rev2)
2217
1639
if log_format is None:
2218
1640
log_format = log.log_formatter_registry.get_default(b)
2219
1642
lf = log_format(show_ids=show_ids, to_file=self.outf,
2220
show_timezone=timezone,
2221
delta_format=get_verbosity_level(),
2223
show_advice=levels is None)
2225
# Choose the algorithm for doing the logging. It's annoying
2226
# having multiple code paths like this but necessary until
2227
# the underlying repository format is faster at generating
2228
# deltas or can provide everything we need from the indices.
2229
# The default algorithm - match-using-deltas - works for
2230
# multiple files and directories and is faster for small
2231
# amounts of history (200 revisions say). However, it's too
2232
# slow for logging a single file in a repository with deep
2233
# history, i.e. > 10K revisions. In the spirit of "do no
2234
# evil when adding features", we continue to use the
2235
# original algorithm - per-file-graph - for the "single
2236
# file that isn't a directory without showing a delta" case.
2237
partial_history = revision and b.repository._format.supports_chks
2238
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2239
or delta_type or partial_history)
2241
# Build the LogRequest and execute it
2242
if len(file_ids) == 0:
2244
rqst = make_log_request_dict(
2245
direction=direction, specific_fileids=file_ids,
2246
start_revision=rev1, end_revision=rev2, limit=limit,
2247
message_search=message, delta_type=delta_type,
2248
diff_type=diff_type, _match_using_deltas=match_using_deltas)
2249
Logger(b, rqst).show(lf)
1643
show_timezone=timezone)
1649
direction=direction,
1650
start_revision=rev1,
2254
def _get_revision_range(revisionspec_list, branch, command_name):
2255
"""Take the input of a revision option and turn it into a revision range.
2257
It returns RevisionInfo objects which can be used to obtain the rev_id's
2258
of the desired revisions. It does some user input validations.
2260
if revisionspec_list is None:
2263
elif len(revisionspec_list) == 1:
2264
rev1 = rev2 = revisionspec_list[0].in_history(branch)
2265
elif len(revisionspec_list) == 2:
2266
start_spec = revisionspec_list[0]
2267
end_spec = revisionspec_list[1]
2268
if end_spec.get_branch() != start_spec.get_branch():
2269
# b is taken from revision[0].get_branch(), and
2270
# show_log will use its revision_history. Having
2271
# different branches will lead to weird behaviors.
2272
raise errors.BzrCommandError(
2273
"bzr %s doesn't accept two revisions in different"
2274
" branches." % command_name)
2275
rev1 = start_spec.in_history(branch)
2276
# Avoid loading all of history when we know a missing
2277
# end of range means the last revision ...
2278
if end_spec.spec is None:
2279
last_revno, last_revision_id = branch.last_revision_info()
2280
rev2 = RevisionInfo(branch, last_revno, last_revision_id)
2282
rev2 = end_spec.in_history(branch)
2284
raise errors.BzrCommandError(
2285
'bzr %s --revision takes one or two values.' % command_name)
2289
def _revision_range_to_revid_range(revision_range):
2292
if revision_range[0] is not None:
2293
rev_id1 = revision_range[0].rev_id
2294
if revision_range[1] is not None:
2295
rev_id2 = revision_range[1].rev_id
2296
return rev_id1, rev_id2
2298
1657
def get_log_format(long=False, short=False, line=False, default='long'):
2299
1658
log_format = default
3243
2318
takes_args = ['testspecs*']
3244
2319
takes_options = ['verbose',
3246
help='Stop when one test fails.',
2321
help='stop when one test fails',
3247
2322
short_name='1',
2324
Option('keep-output',
2325
help='keep output directories when tests fail'),
3249
2326
Option('transport',
3250
2327
help='Use a different transport by default '
3251
2328
'throughout the test suite.',
3252
2329
type=get_transport_type),
3254
help='Run the benchmarks rather than selftests.'),
2330
Option('benchmark', help='run the bzr benchmarks.'),
3255
2331
Option('lsprof-timed',
3256
help='Generate lsprof output for benchmarked'
2332
help='generate lsprof output for benchmarked'
3257
2333
' sections of code.'),
3258
2334
Option('cache-dir', type=str,
3259
help='Cache intermediate benchmark output in this '
2335
help='a directory to cache intermediate'
2336
' benchmark steps'),
2337
Option('clean-output',
2338
help='clean temporary tests directories'
2339
' without running tests'),
3261
2340
Option('first',
3262
help='Run all tests, but run specified tests first.',
2341
help='run all tests, but run specified tests first',
3263
2342
short_name='f',
3266
help='List the tests instead of running them.'),
3267
RegistryOption('parallel',
3268
help="Run the test suite in parallel.",
3269
lazy_registry=('bzrlib.tests', 'parallel_registry'),
3270
value_switches=False,
3272
Option('randomize', type=str, argname="SEED",
3273
help='Randomize the order of tests using the given'
3274
' seed or "now" for the current time.'),
3275
Option('exclude', type=str, argname="PATTERN",
3277
help='Exclude tests that match this regular'
3280
help='Output test progress via subunit.'),
3281
Option('strict', help='Fail on missing dependencies or '
3283
Option('load-list', type=str, argname='TESTLISTFILE',
3284
help='Load a test id list from a text file.'),
3285
ListOption('debugflag', type=str, short_name='E',
3286
help='Turn on a selftest debug flag.'),
3287
ListOption('starting-with', type=str, argname='TESTID',
3288
param_name='starting_with', short_name='s',
3290
'Load only the tests starting with TESTID.'),
2344
Option('numbered-dirs',
2345
help='use numbered dirs for TestCaseInTempDir'),
3292
2347
encoding_type = 'replace'
3295
Command.__init__(self)
3296
self.additional_selftest_args = {}
3298
def run(self, testspecs_list=None, verbose=False, one=False,
3299
transport=None, benchmark=None,
3300
lsprof_timed=None, cache_dir=None,
3301
first=False, list_only=False,
3302
randomize=None, exclude=None, strict=False,
3303
load_list=None, debugflag=None, starting_with=None, subunit=False,
2349
def run(self, testspecs_list=None, verbose=None, one=False,
2350
keep_output=False, transport=None, benchmark=None,
2351
lsprof_timed=None, cache_dir=None, clean_output=False,
2352
first=False, numbered_dirs=None):
3305
2354
from bzrlib.tests import selftest
3306
2355
import bzrlib.benchmarks as benchmarks
3307
2356
from bzrlib.benchmarks import tree_creator
3309
# Make deprecation warnings visible, unless -Werror is set
3310
symbol_versioning.activate_deprecation_warnings(override=False)
2359
from bzrlib.tests import clean_selftest_output
2360
clean_selftest_output()
2363
if numbered_dirs is None and sys.platform == 'win32':
2364
numbered_dirs = True
3312
2366
if cache_dir is not None:
3313
2367
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2368
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2369
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
3314
2371
if testspecs_list is not None:
3315
2372
pattern = '|'.join(testspecs_list)
3320
from bzrlib.tests import SubUnitBzrRunner
3322
raise errors.BzrCommandError("subunit not available. subunit "
3323
"needs to be installed to use --subunit.")
3324
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3326
self.additional_selftest_args.setdefault(
3327
'suite_decorators', []).append(parallel)
3329
2376
test_suite_factory = benchmarks.test_suite
3330
# Unless user explicitly asks for quiet, be verbose in benchmarks
3331
verbose = not is_quiet()
3332
2379
# TODO: should possibly lock the history file...
3333
2380
benchfile = open(".perf_history", "at", buffering=1)
3335
2382
test_suite_factory = None
3336
2385
benchfile = None
3338
selftest_kwargs = {"verbose": verbose,
3340
"stop_on_failure": one,
3341
"transport": transport,
3342
"test_suite_factory": test_suite_factory,
3343
"lsprof_timed": lsprof_timed,
3344
"bench_history": benchfile,
3345
"matching_tests_first": first,
3346
"list_only": list_only,
3347
"random_seed": randomize,
3348
"exclude_pattern": exclude,
3350
"load_list": load_list,
3351
"debug_flags": debugflag,
3352
"starting_with": starting_with
3354
selftest_kwargs.update(self.additional_selftest_args)
3355
result = selftest(**selftest_kwargs)
2387
result = selftest(verbose=verbose,
2389
stop_on_failure=one,
2390
keep_output=keep_output,
2391
transport=transport,
2392
test_suite_factory=test_suite_factory,
2393
lsprof_timed=lsprof_timed,
2394
bench_history=benchfile,
2395
matching_tests_first=first,
2396
numbered_dirs=numbered_dirs,
3357
2399
if benchfile is not None:
3358
2400
benchfile.close()
2402
info('tests passed')
2404
info('tests failed')
3359
2405
return int(not result)
3362
2408
class cmd_version(Command):
3363
2409
"""Show version of bzr."""
3365
encoding_type = 'replace'
3367
Option("short", help="Print just the version number."),
3370
2411
@display_command
3371
def run(self, short=False):
3372
2413
from bzrlib.version import show_version
3374
self.outf.write(bzrlib.version_string + '\n')
3376
show_version(to_file=self.outf)
3379
2417
class cmd_rocks(Command):
3451
2478
directory, where they can be reviewed (with bzr diff), tested, and then
3452
2479
committed to record the result of the merge.
2483
To merge the latest revision from bzr.dev:
2484
bzr merge ../bzr.dev
2486
To merge changes up to and including revision 82 from bzr.dev:
2487
bzr merge -r 82 ../bzr.dev
2489
To merge the changes introduced by 82, without previous changes:
2490
bzr merge -r 81..82 ../bzr.dev
3454
2492
merge refuses to run if there are any uncommitted changes, unless
3455
2493
--force is given.
3458
To merge the latest revision from bzr.dev::
3460
bzr merge ../bzr.dev
3462
To merge changes up to and including revision 82 from bzr.dev::
3464
bzr merge -r 82 ../bzr.dev
3466
To merge the changes introduced by 82, without previous changes::
3468
bzr merge -r 81..82 ../bzr.dev
3470
To apply a merge directive contained in /tmp/merge:
3472
bzr merge /tmp/merge
3475
encoding_type = 'exact'
3476
_see_also = ['update', 'remerge', 'status-flags', 'send']
3477
takes_args = ['location?']
3482
help='Merge even if the destination tree has uncommitted changes.'),
2495
takes_args = ['branch?']
2496
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
3486
2497
Option('show-base', help="Show base revision text in "
3488
2499
Option('uncommitted', help='Apply uncommitted changes'
3489
' from a working copy, instead of branch changes.'),
2500
' from a working copy, instead of branch changes'),
3490
2501
Option('pull', help='If the destination is already'
3491
2502
' completely merged into the source, pull from the'
3492
' source rather than merging. When this happens,'
2503
' source rather than merging. When this happens,'
3493
2504
' you do not need to commit the result.'),
3494
2505
Option('directory',
3495
help='Branch to merge into, '
3496
'rather than the one containing the working directory.',
3500
Option('preview', help='Instead of merging, show a diff of the merge.')
2506
help='Branch to merge into, '
2507
'rather than the one containing the working directory',
3503
def run(self, location=None, revision=None, force=False,
3504
merge_type=None, show_base=False, reprocess=None, remember=False,
2513
def run(self, branch=None, revision=None, force=False, merge_type=None,
2514
show_base=False, reprocess=False, remember=False,
3505
2515
uncommitted=False, pull=False,
3506
2516
directory=None,
2518
from bzrlib.tag import _merge_tags_if_possible
2519
other_revision_id = None
3509
2520
if merge_type is None:
3510
2521
merge_type = _mod_merge.Merge3Merger
3512
2523
if directory is None: directory = u'.'
3513
possible_transports = []
3515
allow_pending = True
3516
verified = 'inapplicable'
2524
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2525
# inventory. Because merge is a mutating operation, it really
2526
# should be a lock_write() for the whole cmd_merge operation.
2527
# However, cmd_merge open's its own tree in _merge_helper, which
2528
# means if we lock here, the later lock_write() will always block.
2529
# Either the merge helper code should be updated to take a tree,
2530
# (What about tree.merge_from_branch?)
3517
2531
tree = WorkingTree.open_containing(directory)[0]
3519
# die as quickly as possible if there are uncommitted changes
3521
basis_tree = tree.revision_tree(tree.last_revision())
3522
except errors.NoSuchRevision:
3523
basis_tree = tree.basis_tree()
3525
changes = tree.changes_from(basis_tree)
3526
if changes.has_changed():
3527
raise errors.UncommittedChanges(tree)
3529
view_info = _get_view_info_for_change_reporter(tree)
3530
2532
change_reporter = delta._ChangeReporter(
3531
unversioned_filter=tree.is_ignored, view_info=view_info)
3534
pb = ui.ui_factory.nested_progress_bar()
3535
cleanups.append(pb.finished)
3537
cleanups.append(tree.unlock)
3538
if location is not None:
3540
mergeable = bundle.read_mergeable_from_url(location,
3541
possible_transports=possible_transports)
3542
except errors.NotABundle:
2533
unversioned_filter=tree.is_ignored)
2535
if branch is not None:
2537
mergeable = bundle.read_mergeable_from_url(
2539
except errors.NotABundle:
2540
pass # Continue on considering this url a Branch
2542
if revision is not None:
2543
raise errors.BzrCommandError(
2544
'Cannot use -r with merge directives or bundles')
2545
other_revision_id = mergeable.install_revisions(
2546
tree.branch.repository)
2547
revision = [RevisionSpec.from_string(
2548
'revid:' + other_revision_id)]
2550
if revision is None \
2551
or len(revision) < 1 or revision[0].needs_branch():
2552
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2554
if revision is None or len(revision) < 1:
2557
other = [branch, None]
2560
other = [branch, -1]
2561
other_branch, path = Branch.open_containing(branch)
2564
raise errors.BzrCommandError('Cannot use --uncommitted and'
2565
' --revision at the same time.')
2566
branch = revision[0].get_branch() or branch
2567
if len(revision) == 1:
2569
if other_revision_id is not None:
3546
raise errors.BzrCommandError('Cannot use --uncommitted'
3547
' with bundles or merge directives.')
3549
if revision is not None:
3550
raise errors.BzrCommandError(
3551
'Cannot use -r with merge directives or bundles')
3552
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3555
if merger is None and uncommitted:
3556
if revision is not None and len(revision) > 0:
3557
raise errors.BzrCommandError('Cannot use --uncommitted and'
3558
' --revision at the same time.')
3559
location = self._select_branch_location(tree, location)[0]
3560
other_tree, other_path = WorkingTree.open_containing(location)
3561
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
3563
allow_pending = False
3564
if other_path != '':
3565
merger.interesting_files = [other_path]
3568
merger, allow_pending = self._get_merger_from_branch(tree,
3569
location, revision, remember, possible_transports, pb)
3571
merger.merge_type = merge_type
3572
merger.reprocess = reprocess
3573
merger.show_base = show_base
3574
self.sanity_check_merger(merger)
3575
if (merger.base_rev_id == merger.other_rev_id and
3576
merger.other_rev_id is not None):
3577
note('Nothing to do.')
2574
other_branch, path = Branch.open_containing(branch)
2575
revno = revision[0].in_history(other_branch).revno
2576
other = [branch, revno]
2578
assert len(revision) == 2
2579
if None in revision:
2580
raise errors.BzrCommandError(
2581
"Merge doesn't permit empty revision specifier.")
2582
base_branch, path = Branch.open_containing(branch)
2583
branch1 = revision[1].get_branch() or branch
2584
other_branch, path1 = Branch.open_containing(branch1)
2585
if revision[0].get_branch() is not None:
2586
# then path was obtained from it, and is None.
2589
base = [branch, revision[0].in_history(base_branch).revno]
2590
other = [branch1, revision[1].in_history(other_branch).revno]
2592
if ((tree.branch.get_parent() is None or remember) and
2593
other_branch is not None):
2594
tree.branch.set_parent(other_branch.base)
2596
# pull tags now... it's a bit inconsistent to do it ahead of copying
2597
# the history but that's done inside the merge code
2598
if other_branch is not None:
2599
_merge_tags_if_possible(other_branch, tree.branch)
2602
interesting_files = [path]
2604
interesting_files = None
2605
pb = ui.ui_factory.nested_progress_bar()
2608
conflict_count = _merge_helper(
2609
other, base, other_rev_id=other_revision_id,
2610
check_clean=(not force),
2611
merge_type=merge_type,
2612
reprocess=reprocess,
2613
show_base=show_base,
2616
pb=pb, file_list=interesting_files,
2617
change_reporter=change_reporter)
2620
if conflict_count != 0:
3580
if merger.interesting_files is not None:
3581
raise errors.BzrCommandError('Cannot pull individual files')
3582
if (merger.base_rev_id == tree.last_revision()):
3583
result = tree.pull(merger.other_branch, False,
3584
merger.other_rev_id)
3585
result.report(self.outf)
3587
merger.check_basis(False)
3589
return self._do_preview(merger)
3591
return self._do_merge(merger, change_reporter, allow_pending,
3594
for cleanup in reversed(cleanups):
3597
def _do_preview(self, merger):
3598
from bzrlib.diff import show_diff_trees
3599
tree_merger = merger.make_merger()
3600
tt = tree_merger.make_preview_transform()
3602
result_tree = tt.get_preview_tree()
3603
show_diff_trees(merger.this_tree, result_tree, self.outf,
3604
old_label='', new_label='')
3608
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3609
merger.change_reporter = change_reporter
3610
conflict_count = merger.do_merge()
3612
merger.set_pending()
3613
if verified == 'failed':
3614
warning('Preview patch does not match changes')
3615
if conflict_count != 0:
3620
def sanity_check_merger(self, merger):
3621
if (merger.show_base and
3622
not merger.merge_type is _mod_merge.Merge3Merger):
3623
raise errors.BzrCommandError("Show-base is not supported for this"
3624
" merge type. %s" % merger.merge_type)
3625
if merger.reprocess is None:
3626
if merger.show_base:
3627
merger.reprocess = False
3629
# Use reprocess if the merger supports it
3630
merger.reprocess = merger.merge_type.supports_reprocess
3631
if merger.reprocess and not merger.merge_type.supports_reprocess:
3632
raise errors.BzrCommandError("Conflict reduction is not supported"
3633
" for merge type %s." %
3635
if merger.reprocess and merger.show_base:
3636
raise errors.BzrCommandError("Cannot do conflict reduction and"
3639
def _get_merger_from_branch(self, tree, location, revision, remember,
3640
possible_transports, pb):
3641
"""Produce a merger from a location, assuming it refers to a branch."""
3642
from bzrlib.tag import _merge_tags_if_possible
3643
# find the branch locations
3644
other_loc, user_location = self._select_branch_location(tree, location,
3646
if revision is not None and len(revision) == 2:
3647
base_loc, _unused = self._select_branch_location(tree,
3648
location, revision, 0)
3650
base_loc = other_loc
3652
other_branch, other_path = Branch.open_containing(other_loc,
3653
possible_transports)
3654
if base_loc == other_loc:
3655
base_branch = other_branch
3657
base_branch, base_path = Branch.open_containing(base_loc,
3658
possible_transports)
3659
# Find the revision ids
3660
if revision is None or len(revision) < 1 or revision[-1] is None:
3661
other_revision_id = _mod_revision.ensure_null(
3662
other_branch.last_revision())
3664
other_revision_id = revision[-1].as_revision_id(other_branch)
3665
if (revision is not None and len(revision) == 2
3666
and revision[0] is not None):
3667
base_revision_id = revision[0].as_revision_id(base_branch)
3669
base_revision_id = None
3670
# Remember where we merge from
3671
if ((remember or tree.branch.get_submit_branch() is None) and
3672
user_location is not None):
3673
tree.branch.set_submit_branch(other_branch.base)
3674
_merge_tags_if_possible(other_branch, tree.branch)
3675
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3676
other_revision_id, base_revision_id, other_branch, base_branch)
3677
if other_path != '':
3678
allow_pending = False
3679
merger.interesting_files = [other_path]
3681
allow_pending = True
3682
return merger, allow_pending
3684
def _select_branch_location(self, tree, user_location, revision=None,
3686
"""Select a branch location, according to possible inputs.
3688
If provided, branches from ``revision`` are preferred. (Both
3689
``revision`` and ``index`` must be supplied.)
3691
Otherwise, the ``location`` parameter is used. If it is None, then the
3692
``submit`` or ``parent`` location is used, and a note is printed.
3694
:param tree: The working tree to select a branch for merging into
3695
:param location: The location entered by the user
3696
:param revision: The revision parameter to the command
3697
:param index: The index to use for the revision parameter. Negative
3698
indices are permitted.
3699
:return: (selected_location, user_location). The default location
3700
will be the user-entered location.
3702
if (revision is not None and index is not None
3703
and revision[index] is not None):
3704
branch = revision[index].get_branch()
3705
if branch is not None:
3706
return branch, branch
3707
if user_location is None:
3708
location = self._get_remembered(tree, 'Merging from')
3710
location = user_location
3711
return location, user_location
3713
def _get_remembered(self, tree, verb_string):
2624
except errors.AmbiguousBase, e:
2625
m = ("sorry, bzr can't determine the right merge base yet\n"
2626
"candidates are:\n "
2627
+ "\n ".join(e.bases)
2629
"please specify an explicit base with -r,\n"
2630
"and (if you want) report this to the bzr developers\n")
2633
# TODO: move up to common parent; this isn't merge-specific anymore.
2634
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3714
2635
"""Use tree.branch's parent if none was supplied.
3716
2637
Report if the remembered location was used.
3718
stored_location = tree.branch.get_submit_branch()
3719
stored_location_type = "submit"
3720
if stored_location is None:
3721
stored_location = tree.branch.get_parent()
3722
stored_location_type = "parent"
2639
if supplied_location is not None:
2640
return supplied_location
2641
stored_location = tree.branch.get_parent()
3723
2642
mutter("%s", stored_location)
3724
2643
if stored_location is None:
3725
2644
raise errors.BzrCommandError("No location specified or remembered")
3726
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3727
note(u"%s remembered %s location %s", verb_string,
3728
stored_location_type, display_url)
2645
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2646
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3729
2647
return stored_location
3931
2819
takes_args = ['context?']
3932
2820
aliases = ['s-c']
3935
2823
@display_command
3936
2824
def run(self, context=None):
3937
2825
import shellcomplete
3938
2826
shellcomplete.shellcomplete(context)
2829
class cmd_fetch(Command):
2830
"""Copy in history from another branch but don't merge it.
2832
This is an internal method used for pull and merge.
2835
takes_args = ['from_branch', 'to_branch']
2836
def run(self, from_branch, to_branch):
2837
from bzrlib.fetch import Fetcher
2838
from_b = Branch.open(from_branch)
2839
to_b = Branch.open(to_branch)
2840
Fetcher(to_b, from_b)
3941
2843
class cmd_missing(Command):
3942
2844
"""Show unmerged/unpulled revisions between two branches.
3944
2846
OTHER_BRANCH may be local or remote.
3946
To filter on a range of revisions, you can use the command -r begin..end
3947
-r revision requests a specific revision, -r ..end or -r begin.. are
3952
Determine the missing revisions between this and the branch at the
3953
remembered pull location::
3957
Determine the missing revisions between this and another branch::
3959
bzr missing http://server/branch
3961
Determine the missing revisions up to a specific revision on the other
3964
bzr missing -r ..-10
3966
Determine the missing revisions up to a specific revision on this
3969
bzr missing --my-revision ..-10
3972
_see_also = ['merge', 'pull']
3973
2848
takes_args = ['other_branch?']
3975
Option('reverse', 'Reverse the order of revisions.'),
3977
'Display changes in the local branch only.'),
3978
Option('this' , 'Same as --mine-only.'),
3979
Option('theirs-only',
3980
'Display changes in the remote branch only.'),
3981
Option('other', 'Same as --theirs-only.'),
3985
custom_help('revision',
3986
help='Filter on other branch revisions (inclusive). '
3987
'See "help revisionspec" for details.'),
3988
Option('my-revision',
3989
type=_parse_revision_str,
3990
help='Filter on local branch revisions (inclusive). '
3991
'See "help revisionspec" for details.'),
3992
Option('include-merges',
3993
'Show all revisions in addition to the mainline ones.'),
2849
takes_options = [Option('reverse', 'Reverse the order of revisions'),
2851
'Display changes in the local branch only'),
2852
Option('theirs-only',
2853
'Display changes in the remote branch only'),
3995
2858
encoding_type = 'replace'
3997
2860
@display_command
3998
2861
def run(self, other_branch=None, reverse=False, mine_only=False,
4000
log_format=None, long=False, short=False, line=False,
4001
show_ids=False, verbose=False, this=False, other=False,
4002
include_merges=False, revision=None, my_revision=None):
4003
from bzrlib.missing import find_unmerged, iter_log_revisions
4012
# TODO: We should probably check that we don't have mine-only and
4013
# theirs-only set, but it gets complicated because we also have
4014
# this and other which could be used.
2862
theirs_only=False, log_format=None, long=False, short=False, line=False,
2863
show_ids=False, verbose=False):
2864
from bzrlib.missing import find_unmerged, iter_log_data
2865
from bzrlib.log import log_formatter
4021
2866
local_branch = Branch.open_containing(u".")[0]
4022
2867
parent = local_branch.get_parent()
4023
2868
if other_branch is None:
4024
2869
other_branch = parent
4025
2870
if other_branch is None:
4026
raise errors.BzrCommandError("No peer location known"
2871
raise errors.BzrCommandError("No peer location known or specified.")
4028
2872
display_url = urlutils.unescape_for_display(parent,
4029
2873
self.outf.encoding)
4030
message("Using saved parent location: "
4031
+ display_url + "\n")
2874
print "Using last location: " + display_url
4033
2876
remote_branch = Branch.open(other_branch)
4034
2877
if remote_branch.base == local_branch.base:
4035
2878
remote_branch = local_branch
4037
local_revid_range = _revision_range_to_revid_range(
4038
_get_revision_range(my_revision, local_branch,
4041
remote_revid_range = _revision_range_to_revid_range(
4042
_get_revision_range(revision,
4043
remote_branch, self.name()))
4045
2879
local_branch.lock_read()
4047
2881
remote_branch.lock_read()
4049
local_extra, remote_extra = find_unmerged(
4050
local_branch, remote_branch, restrict,
4051
backward=not reverse,
4052
include_merges=include_merges,
4053
local_revid_range=local_revid_range,
4054
remote_revid_range=remote_revid_range)
4056
if log_format is None:
4057
registry = log.log_formatter_registry
4058
log_format = registry.get_default(local_branch)
2883
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2884
if (log_format is None):
2885
log_format = log.log_formatter_registry.get_default(
4059
2887
lf = log_format(to_file=self.outf,
4060
2888
show_ids=show_ids,
4061
2889
show_timezone='original')
2890
if reverse is False:
2891
local_extra.reverse()
2892
remote_extra.reverse()
4064
2893
if local_extra and not theirs_only:
4065
message("You have %d extra revision(s):\n" %
4067
for revision in iter_log_revisions(local_extra,
4068
local_branch.repository,
4070
lf.log_revision(revision)
2894
print "You have %d extra revision(s):" % len(local_extra)
2895
for data in iter_log_data(local_extra, local_branch.repository,
4071
2898
printed_local = True
4074
2900
printed_local = False
4076
2901
if remote_extra and not mine_only:
4077
2902
if printed_local is True:
4079
message("You are missing %d revision(s):\n" %
4081
for revision in iter_log_revisions(remote_extra,
4082
remote_branch.repository,
4084
lf.log_revision(revision)
2904
print "You are missing %d revision(s):" % len(remote_extra)
2905
for data in iter_log_data(remote_extra, remote_branch.repository,
2908
if not remote_extra and not local_extra:
2910
print "Branches are up to date."
4085
2912
status_code = 1
4087
if mine_only and not local_extra:
4088
# We checked local, and found nothing extra
4089
message('This branch is up to date.\n')
4090
elif theirs_only and not remote_extra:
4091
# We checked remote, and found nothing extra
4092
message('Other branch is up to date.\n')
4093
elif not (mine_only or theirs_only or local_extra or
4095
# We checked both branches, and neither one had extra
4097
message("Branches are up to date.\n")
4099
2914
remote_branch.unlock()
4762
3438
self.outf.writelines(directive.to_lines())
4764
3440
message = directive.to_email(mail_to, branch, sign)
4765
s = SMTPConnection(branch.get_config())
4766
s.send_email(message)
4769
class cmd_send(Command):
4770
"""Mail or create a merge-directive for submitting changes.
4772
A merge directive provides many things needed for requesting merges:
4774
* A machine-readable description of the merge to perform
4776
* An optional patch that is a preview of the changes requested
4778
* An optional bundle of revision data, so that the changes can be applied
4779
directly from the merge directive, without retrieving data from a
4782
If --no-bundle is specified, then public_branch is needed (and must be
4783
up-to-date), so that the receiver can perform the merge using the
4784
public_branch. The public_branch is always included if known, so that
4785
people can check it later.
4787
The submit branch defaults to the parent, but can be overridden. Both
4788
submit branch and public branch will be remembered if supplied.
4790
If a public_branch is known for the submit_branch, that public submit
4791
branch is used in the merge instructions. This means that a local mirror
4792
can be used as your actual submit branch, once you have set public_branch
4795
Mail is sent using your preferred mail program. This should be transparent
4796
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4797
If the preferred client can't be found (or used), your editor will be used.
4799
To use a specific mail program, set the mail_client configuration option.
4800
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4801
specific clients are "claws", "evolution", "kmail", "mutt", and
4802
"thunderbird"; generic options are "default", "editor", "emacsclient",
4803
"mapi", and "xdg-email". Plugins may also add supported clients.
4805
If mail is being sent, a to address is required. This can be supplied
4806
either on the commandline, by setting the submit_to configuration
4807
option in the branch itself or the child_submit_to configuration option
4808
in the submit branch.
4810
Two formats are currently supported: "4" uses revision bundle format 4 and
4811
merge directive format 2. It is significantly faster and smaller than
4812
older formats. It is compatible with Bazaar 0.19 and later. It is the
4813
default. "0.9" uses revision bundle format 0.9 and merge directive
4814
format 1. It is compatible with Bazaar 0.12 - 0.18.
4816
The merge directives created by bzr send may be applied using bzr merge or
4817
bzr pull by specifying a file containing a merge directive as the location.
4820
encoding_type = 'exact'
4822
_see_also = ['merge', 'pull']
4824
takes_args = ['submit_branch?', 'public_branch?']
4828
help='Do not include a bundle in the merge directive.'),
4829
Option('no-patch', help='Do not include a preview patch in the merge'
4832
help='Remember submit and public branch.'),
4834
help='Branch to generate the submission from, '
4835
'rather than the one containing the working directory.',
4838
Option('output', short_name='o',
4839
help='Write merge directive to this file; '
4840
'use - for stdout.',
4842
Option('mail-to', help='Mail the request to this address.',
4846
Option('body', help='Body for the email.', type=unicode),
4847
RegistryOption('format',
4848
help='Use the specified output format.',
4849
lazy_registry=('bzrlib.send', 'format_registry'))
4852
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4853
no_patch=False, revision=None, remember=False, output=None,
4854
format=None, mail_to=None, message=None, body=None, **kwargs):
4855
from bzrlib.send import send
4856
return send(submit_branch, revision, public_branch, remember,
4857
format, no_bundle, no_patch, output,
4858
kwargs.get('from', '.'), mail_to, message, body,
4862
class cmd_bundle_revisions(cmd_send):
4863
"""Create a merge-directive for submitting changes.
4865
A merge directive provides many things needed for requesting merges:
4867
* A machine-readable description of the merge to perform
4869
* An optional patch that is a preview of the changes requested
4871
* An optional bundle of revision data, so that the changes can be applied
4872
directly from the merge directive, without retrieving data from a
4875
If --no-bundle is specified, then public_branch is needed (and must be
4876
up-to-date), so that the receiver can perform the merge using the
4877
public_branch. The public_branch is always included if known, so that
4878
people can check it later.
4880
The submit branch defaults to the parent, but can be overridden. Both
4881
submit branch and public branch will be remembered if supplied.
4883
If a public_branch is known for the submit_branch, that public submit
4884
branch is used in the merge instructions. This means that a local mirror
4885
can be used as your actual submit branch, once you have set public_branch
4888
Two formats are currently supported: "4" uses revision bundle format 4 and
4889
merge directive format 2. It is significantly faster and smaller than
4890
older formats. It is compatible with Bazaar 0.19 and later. It is the
4891
default. "0.9" uses revision bundle format 0.9 and merge directive
4892
format 1. It is compatible with Bazaar 0.12 - 0.18.
4897
help='Do not include a bundle in the merge directive.'),
4898
Option('no-patch', help='Do not include a preview patch in the merge'
4901
help='Remember submit and public branch.'),
4903
help='Branch to generate the submission from, '
4904
'rather than the one containing the working directory.',
4907
Option('output', short_name='o', help='Write directive to this file.',
4910
RegistryOption('format',
4911
help='Use the specified output format.',
4912
lazy_registry=('bzrlib.send', 'format_registry')),
4914
aliases = ['bundle']
4916
_see_also = ['send', 'merge']
4920
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4921
no_patch=False, revision=None, remember=False, output=None,
4922
format=None, **kwargs):
4925
from bzrlib.send import send
4926
return send(submit_branch, revision, public_branch, remember,
4927
format, no_bundle, no_patch, output,
4928
kwargs.get('from', '.'), None, None, None,
3442
server = branch.get_config().get_user_option('smtp_server')
3444
server = 'localhost'
3446
s.sendmail(message['From'], message['To'], message.as_string())
4932
3449
class cmd_tag(Command):
4933
"""Create, remove or modify a tag naming a revision.
3450
"""Create a tag naming a revision.
4935
3452
Tags give human-meaningful names to revisions. Commands that take a -r
4936
3453
(--revision) option can be given -rtag:X, where X is any previously
4995
3508
class cmd_tags(Command):
4998
This command shows a table of tag names and the revisions they reference.
3511
This tag shows a table of tag names and the revisions they reference.
5002
3514
takes_options = [
5003
3515
Option('directory',
5004
help='Branch whose tags should be displayed.',
3516
help='Branch whose tags should be displayed',
5005
3517
short_name='d',
5008
RegistryOption.from_kwargs('sort',
5009
'Sort tags by different criteria.', title='Sorting',
5010
alpha='Sort tags lexicographically (default).',
5011
time='Sort tags chronologically.',
5017
3522
@display_command
5024
3526
branch, relpath = Branch.open_containing(directory)
5026
tags = branch.tags.get_tag_dict().items()
5033
graph = branch.repository.get_graph()
5034
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5035
revid1, revid2 = rev1.rev_id, rev2.rev_id
5036
# only show revisions between revid1 and revid2 (inclusive)
5037
tags = [(tag, revid) for tag, revid in tags if
5038
graph.is_between(revid, revid1, revid2)]
5043
elif sort == 'time':
5045
for tag, revid in tags:
5047
revobj = branch.repository.get_revision(revid)
5048
except errors.NoSuchRevision:
5049
timestamp = sys.maxint # place them at the end
5051
timestamp = revobj.timestamp
5052
timestamps[revid] = timestamp
5053
tags.sort(key=lambda x: timestamps[x[1]])
5055
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5056
for index, (tag, revid) in enumerate(tags):
5058
revno = branch.revision_id_to_dotted_revno(revid)
5059
if isinstance(revno, tuple):
5060
revno = '.'.join(map(str, revno))
5061
except errors.NoSuchRevision:
5062
# Bad tag data/merges can lead to tagged revisions
5063
# which are not in this branch. Fail gracefully ...
5065
tags[index] = (tag, revno)
5066
for tag, revspec in tags:
5067
self.outf.write('%-20s %s\n' % (tag, revspec))
5070
class cmd_reconfigure(Command):
5071
"""Reconfigure the type of a bzr directory.
5073
A target configuration must be specified.
5075
For checkouts, the bind-to location will be auto-detected if not specified.
5076
The order of preference is
5077
1. For a lightweight checkout, the current bound location.
5078
2. For branches that used to be checkouts, the previously-bound location.
5079
3. The push location.
5080
4. The parent location.
5081
If none of these is available, --bind-to must be specified.
5084
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5085
takes_args = ['location?']
5087
RegistryOption.from_kwargs(
5089
title='Target type',
5090
help='The type to reconfigure the directory to.',
5091
value_switches=True, enum_switch=False,
5092
branch='Reconfigure to be an unbound branch with no working tree.',
5093
tree='Reconfigure to be an unbound branch with a working tree.',
5094
checkout='Reconfigure to be a bound branch with a working tree.',
5095
lightweight_checkout='Reconfigure to be a lightweight'
5096
' checkout (with no local history).',
5097
standalone='Reconfigure to be a standalone branch '
5098
'(i.e. stop using shared repository).',
5099
use_shared='Reconfigure to use a shared repository.',
5100
with_trees='Reconfigure repository to create '
5101
'working trees on branches by default.',
5102
with_no_trees='Reconfigure repository to not create '
5103
'working trees on branches by default.'
5105
Option('bind-to', help='Branch to bind checkout to.', type=str),
5107
help='Perform reconfiguration even if local changes'
5111
def run(self, location=None, target_type=None, bind_to=None, force=False):
5112
directory = bzrdir.BzrDir.open(location)
5113
if target_type is None:
5114
raise errors.BzrCommandError('No target configuration specified')
5115
elif target_type == 'branch':
5116
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5117
elif target_type == 'tree':
5118
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5119
elif target_type == 'checkout':
5120
reconfiguration = reconfigure.Reconfigure.to_checkout(
5122
elif target_type == 'lightweight-checkout':
5123
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5125
elif target_type == 'use-shared':
5126
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5127
elif target_type == 'standalone':
5128
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5129
elif target_type == 'with-trees':
5130
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5132
elif target_type == 'with-no-trees':
5133
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5135
reconfiguration.apply(force)
5138
class cmd_switch(Command):
5139
"""Set the branch of a checkout and update.
5141
For lightweight checkouts, this changes the branch being referenced.
5142
For heavyweight checkouts, this checks that there are no local commits
5143
versus the current bound branch, then it makes the local branch a mirror
5144
of the new location and binds to it.
5146
In both cases, the working tree is updated and uncommitted changes
5147
are merged. The user can commit or revert these as they desire.
5149
Pending merges need to be committed or reverted before using switch.
5151
The path to the branch to switch to can be specified relative to the parent
5152
directory of the current branch. For example, if you are currently in a
5153
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5156
Bound branches use the nickname of its master branch unless it is set
5157
locally, in which case switching will update the the local nickname to be
5161
takes_args = ['to_location']
5162
takes_options = [Option('force',
5163
help='Switch even if local commits will be lost.')
5166
def run(self, to_location, force=False):
5167
from bzrlib import switch
5169
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5171
branch = control_dir.open_branch()
5172
had_explicit_nick = branch.get_config().has_explicit_nickname()
5173
except errors.NotBranchError:
5174
had_explicit_nick = False
5176
to_branch = Branch.open(to_location)
5177
except errors.NotBranchError:
5178
this_url = self._get_branch_location(control_dir)
5179
to_branch = Branch.open(
5180
urlutils.join(this_url, '..', to_location))
5181
switch.switch(control_dir, to_branch, force)
5182
if had_explicit_nick:
5183
branch = control_dir.open_branch() #get the new branch!
5184
branch.nick = to_branch.nick
5185
note('Switched to branch: %s',
5186
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5188
def _get_branch_location(self, control_dir):
5189
"""Return location of branch for this control dir."""
5191
this_branch = control_dir.open_branch()
5192
# This may be a heavy checkout, where we want the master branch
5193
master_location = this_branch.get_bound_location()
5194
if master_location is not None:
5195
return master_location
5196
# If not, use a local sibling
5197
return this_branch.base
5198
except errors.NotBranchError:
5199
format = control_dir.find_branch_format()
5200
if getattr(format, 'get_reference', None) is not None:
5201
return format.get_reference(control_dir)
5203
return control_dir.root_transport.base
5206
class cmd_view(Command):
5207
"""Manage filtered views.
5209
Views provide a mask over the tree so that users can focus on
5210
a subset of a tree when doing their work. After creating a view,
5211
commands that support a list of files - status, diff, commit, etc -
5212
effectively have that list of files implicitly given each time.
5213
An explicit list of files can still be given but those files
5214
must be within the current view.
5216
In most cases, a view has a short life-span: it is created to make
5217
a selected change and is deleted once that change is committed.
5218
At other times, you may wish to create one or more named views
5219
and switch between them.
5221
To disable the current view without deleting it, you can switch to
5222
the pseudo view called ``off``. This can be useful when you need
5223
to see the whole tree for an operation or two (e.g. merge) but
5224
want to switch back to your view after that.
5227
To define the current view::
5229
bzr view file1 dir1 ...
5231
To list the current view::
5235
To delete the current view::
5239
To disable the current view without deleting it::
5241
bzr view --switch off
5243
To define a named view and switch to it::
5245
bzr view --name view-name file1 dir1 ...
5247
To list a named view::
5249
bzr view --name view-name
5251
To delete a named view::
5253
bzr view --name view-name --delete
5255
To switch to a named view::
5257
bzr view --switch view-name
5259
To list all views defined::
5263
To delete all views::
5265
bzr view --delete --all
5269
takes_args = ['file*']
5272
help='Apply list or delete action to all views.',
5275
help='Delete the view.',
5278
help='Name of the view to define, list or delete.',
5282
help='Name of the view to switch to.',
5287
def run(self, file_list,
5293
tree, file_list = tree_files(file_list, apply_view=False)
5294
current_view, view_dict = tree.views.get_view_info()
5299
raise errors.BzrCommandError(
5300
"Both --delete and a file list specified")
5302
raise errors.BzrCommandError(
5303
"Both --delete and --switch specified")
5305
tree.views.set_view_info(None, {})
5306
self.outf.write("Deleted all views.\n")
5308
raise errors.BzrCommandError("No current view to delete")
5310
tree.views.delete_view(name)
5311
self.outf.write("Deleted '%s' view.\n" % name)
5314
raise errors.BzrCommandError(
5315
"Both --switch and a file list specified")
5317
raise errors.BzrCommandError(
5318
"Both --switch and --all specified")
5319
elif switch == 'off':
5320
if current_view is None:
5321
raise errors.BzrCommandError("No current view to disable")
5322
tree.views.set_view_info(None, view_dict)
5323
self.outf.write("Disabled '%s' view.\n" % (current_view))
5325
tree.views.set_view_info(switch, view_dict)
5326
view_str = views.view_display_str(tree.views.lookup_view())
5327
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5330
self.outf.write('Views defined:\n')
5331
for view in sorted(view_dict):
5332
if view == current_view:
5336
view_str = views.view_display_str(view_dict[view])
5337
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5339
self.outf.write('No views defined.\n')
5342
# No name given and no current view set
5345
raise errors.BzrCommandError(
5346
"Cannot change the 'off' pseudo view")
5347
tree.views.set_view(name, sorted(file_list))
5348
view_str = views.view_display_str(tree.views.lookup_view())
5349
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
3527
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3528
self.outf.write('%-20s %s\n' % (tag_name, target))
3531
# command-line interpretation helper for merge-related commands
3532
def _merge_helper(other_revision, base_revision,
3533
check_clean=True, ignore_zero=False,
3534
this_dir=None, backup_files=False,
3536
file_list=None, show_base=False, reprocess=False,
3539
change_reporter=None,
3541
"""Merge changes into a tree.
3544
list(path, revno) Base for three-way merge.
3545
If [None, None] then a base will be automatically determined.
3547
list(path, revno) Other revision for three-way merge.
3549
Directory to merge changes into; '.' by default.
3551
If true, this_dir must have no uncommitted changes before the
3553
ignore_zero - If true, suppress the "zero conflicts" message when
3554
there are no conflicts; should be set when doing something we expect
3555
to complete perfectly.
3556
file_list - If supplied, merge only changes to selected files.
3558
All available ancestors of other_revision and base_revision are
3559
automatically pulled into the branch.
3561
The revno may be -1 to indicate the last revision on the branch, which is
3564
This function is intended for use from the command line; programmatic
3565
clients might prefer to call merge.merge_inner(), which has less magic
3568
# Loading it late, so that we don't always have to import bzrlib.merge
3569
if merge_type is None:
3570
merge_type = _mod_merge.Merge3Merger
3571
if this_dir is None:
3573
this_tree = WorkingTree.open_containing(this_dir)[0]
3574
if show_base and not merge_type is _mod_merge.Merge3Merger:
3575
raise errors.BzrCommandError("Show-base is not supported for this merge"
3576
" type. %s" % merge_type)
3577
if reprocess and not merge_type.supports_reprocess:
3578
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3579
" type %s." % merge_type)
3580
if reprocess and show_base:
3581
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3582
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3583
# only want to take out a lock_tree_write() if we don't have to pull
3584
# any ancestry. But merge might fetch ancestry in the middle, in
3585
# which case we would need a lock_write().
3586
# Because we cannot upgrade locks, for now we live with the fact that
3587
# the tree will be locked multiple times during a merge. (Maybe
3588
# read-only some of the time, but it means things will get read
3591
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3592
pb=pb, change_reporter=change_reporter)
3593
merger.pp = ProgressPhase("Merge phase", 5, pb)
3594
merger.pp.next_phase()
3595
merger.check_basis(check_clean)
3596
if other_rev_id is not None:
3597
merger.set_other_revision(other_rev_id, this_tree.branch)
5353
# No name given and no current view set
5354
self.outf.write('No current view.\n')
5356
view_str = views.view_display_str(tree.views.lookup_view(name))
5357
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5360
class cmd_hooks(Command):
5366
for hook_key in sorted(hooks.known_hooks.keys()):
5367
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5368
self.outf.write("%s:\n" % type(some_hooks).__name__)
5369
for hook_name, hook_point in sorted(some_hooks.items()):
5370
self.outf.write(" %s:\n" % (hook_name,))
5371
found_hooks = list(hook_point)
5373
for hook in found_hooks:
5374
self.outf.write(" %s\n" %
5375
(some_hooks.get_hook_name(hook),))
5377
self.outf.write(" <no hooks installed>\n")
5380
class cmd_shelve(Command):
5381
"""Temporarily set aside some changes from the current tree.
5383
Shelve allows you to temporarily put changes you've made "on the shelf",
5384
ie. out of the way, until a later time when you can bring them back from
5385
the shelf with the 'unshelve' command. The changes are stored alongside
5386
your working tree, and so they aren't propagated along with your branch nor
5387
will they survive its deletion.
5389
If shelve --list is specified, previously-shelved changes are listed.
5391
Shelve is intended to help separate several sets of changes that have
5392
been inappropriately mingled. If you just want to get rid of all changes
5393
and you don't need to restore them later, use revert. If you want to
5394
shelve all text changes at once, use shelve --all.
5396
If filenames are specified, only the changes to those files will be
5397
shelved. Other files will be left untouched.
5399
If a revision is specified, changes since that revision will be shelved.
5401
You can put multiple items on the shelf, and by default, 'unshelve' will
5402
restore the most recently shelved changes.
5405
takes_args = ['file*']
5409
Option('all', help='Shelve all changes.'),
5411
RegistryOption('writer', 'Method to use for writing diffs.',
5412
bzrlib.option.diff_writer_registry,
5413
value_switches=True, enum_switch=False),
5415
Option('list', help='List shelved changes.'),
5417
help='Destroy removed changes instead of shelving them.'),
5419
_see_also = ['unshelve']
5421
def run(self, revision=None, all=False, file_list=None, message=None,
5422
writer=None, list=False, destroy=False):
5424
return self.run_for_list()
5425
from bzrlib.shelf_ui import Shelver
5427
writer = bzrlib.option.diff_writer_registry.get()
5429
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5430
message, destroy=destroy).run()
5431
except errors.UserAbort:
3599
merger.set_other(other_revision)
3600
merger.pp.next_phase()
3601
merger.set_base(base_revision)
3602
if merger.base_rev_id == merger.other_rev_id:
3603
note('Nothing to do.')
5434
def run_for_list(self):
5435
tree = WorkingTree.open_containing('.')[0]
5438
manager = tree.get_shelf_manager()
5439
shelves = manager.active_shelves()
5440
if len(shelves) == 0:
5441
note('No shelved changes.')
3605
if file_list is None:
3606
if pull and merger.base_rev_id == merger.this_rev_id:
3607
# FIXME: deduplicate with pull
3608
result = merger.this_tree.pull(merger.this_branch,
3609
False, merger.other_rev_id)
3610
if result.old_revid == result.new_revid:
3611
note('No revisions to pull.')
3613
note('Now on revision %d.' % result.new_revno)
5443
for shelf_id in reversed(shelves):
5444
message = manager.get_metadata(shelf_id).get('message')
5446
message = '<no message>'
5447
self.outf.write('%3d: %s\n' % (shelf_id, message))
5453
class cmd_unshelve(Command):
5454
"""Restore shelved changes.
5456
By default, the most recently shelved changes are restored. However if you
5457
specify a shelf by id those changes will be restored instead. This works
5458
best when the changes don't depend on each other.
5461
takes_args = ['shelf_id?']
5463
RegistryOption.from_kwargs(
5464
'action', help="The action to perform.",
5465
enum_switch=False, value_switches=True,
5466
apply="Apply changes and remove from the shelf.",
5467
dry_run="Show changes, but do not apply or remove them.",
5468
delete_only="Delete changes without applying them."
5471
_see_also = ['shelve']
5473
def run(self, shelf_id=None, action='apply'):
5474
from bzrlib.shelf_ui import Unshelver
5475
Unshelver.from_args(shelf_id, action).run()
5478
class cmd_clean_tree(Command):
5479
"""Remove unwanted files from working tree.
5481
By default, only unknown files, not ignored files, are deleted. Versioned
5482
files are never deleted.
5484
Another class is 'detritus', which includes files emitted by bzr during
5485
normal operations and selftests. (The value of these files decreases with
5488
If no options are specified, unknown files are deleted. Otherwise, option
5489
flags are respected, and may be combined.
5491
To check what clean-tree will do, use --dry-run.
5493
takes_options = [Option('ignored', help='Delete all ignored files.'),
5494
Option('detritus', help='Delete conflict files, merge'
5495
' backups, and failed selftest dirs.'),
5497
help='Delete files unknown to bzr (default).'),
5498
Option('dry-run', help='Show files to delete instead of'
5500
Option('force', help='Do not prompt before deleting.')]
5501
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5503
from bzrlib.clean_tree import clean_tree
5504
if not (unknown or ignored or detritus):
5508
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5509
dry_run=dry_run, no_prompt=force)
5512
class cmd_reference(Command):
5513
"""list, view and set branch locations for nested trees.
5515
If no arguments are provided, lists the branch locations for nested trees.
5516
If one argument is provided, display the branch location for that tree.
5517
If two arguments are provided, set the branch location for that tree.
5522
takes_args = ['path?', 'location?']
5524
def run(self, path=None, location=None):
5526
if path is not None:
5528
tree, branch, relpath =(
5529
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5530
if path is not None:
5533
tree = branch.basis_tree()
5535
info = branch._get_all_reference_info().iteritems()
5536
self._display_reference_info(tree, branch, info)
5538
file_id = tree.path2id(path)
5540
raise errors.NotVersionedError(path)
5541
if location is None:
5542
info = [(file_id, branch.get_reference_info(file_id))]
5543
self._display_reference_info(tree, branch, info)
5545
branch.set_reference_info(file_id, path, location)
5547
def _display_reference_info(self, tree, branch, info):
5549
for file_id, (path, location) in info:
5551
path = tree.id2path(file_id)
5552
except errors.NoSuchId:
5554
ref_list.append((path, location))
5555
for path, location in sorted(ref_list):
5556
self.outf.write('%s %s\n' % (path, location))
3615
merger.backup_files = backup_files
3616
merger.merge_type = merge_type
3617
merger.set_interesting_files(file_list)
3618
merger.show_base = show_base
3619
merger.reprocess = reprocess
3620
conflicts = merger.do_merge()
3621
if file_list is None:
3622
merger.set_pending()
3629
merge = _merge_helper
5559
3632
# these get imported and then picked up by the scan for cmd_*
5560
3633
# TODO: Some more consistent way to split command definitions across files;
5561
# we do need to load at least some information about them to know of
3634
# we do need to load at least some information about them to know of
5562
3635
# aliases. ideally we would avoid loading the implementation until the
5563
3636
# details were needed.
5564
3637
from bzrlib.cmd_version_info import cmd_version_info
5565
3638
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
5566
from bzrlib.bundle.commands import (
5569
from bzrlib.foreign import cmd_dpush
3639
from bzrlib.bundle.commands import cmd_bundle_revisions
5570
3640
from bzrlib.sign_my_commits import cmd_sign_my_commits
5571
from bzrlib.weave_commands import cmd_versionedfile_list, \
3641
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
5572
3642
cmd_weave_plan_merge, cmd_weave_merge_text