17
17
"""builtin bzr commands"""
19
# DO NOT change this to cStringIO - it results in control files
21
# FIXIT! (Only deal with byte streams OR unicode at any one layer.)
24
from StringIO import StringIO
29
24
from bzrlib import BZRDIR
25
from bzrlib._merge_core import ApplyMerge3
30
26
from bzrlib.commands import Command, display_command
31
27
from bzrlib.branch import Branch
32
28
from bzrlib.revision import common_ancestor
34
30
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
35
31
NotBranchError, DivergedBranches, NotConflicted,
36
32
NoSuchFile, NoWorkingTree, FileInWrongBranch)
33
from bzrlib.log import show_one_log
37
34
from bzrlib.option import Option
38
35
from bzrlib.revisionspec import RevisionSpec
39
36
import bzrlib.trace
40
37
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
38
from bzrlib.transport.local import LocalTransport
41
39
from bzrlib.workingtree import WorkingTree
42
from bzrlib.log import show_one_log
45
42
def tree_files(file_list, default_branch=u'.'):
148
145
raise BzrCommandError('You must supply either --revision or a revision_id')
149
146
b = WorkingTree.open_containing(u'.')[0].branch
150
147
if revision_id is not None:
151
sys.stdout.write(b.get_revision_xml(revision_id))
148
sys.stdout.write(b.repository.get_revision_xml(revision_id))
152
149
elif revision is not None:
153
150
for rev in revision:
155
152
raise BzrCommandError('You cannot specify a NULL revision.')
156
153
revno, rev_id = rev.in_history(b)
157
sys.stdout.write(b.get_revision_xml(rev_id))
154
sys.stdout.write(b.repository.get_revision_xml(rev_id))
160
157
class cmd_revno(Command):
1424
1422
If arguments are given, they are regular expressions that say
1425
1423
which tests should run.
1425
If the global option '--no-plugins' is given, plugins are not loaded
1426
before running the selftests. This has two effects: features provided or
1427
modified by plugins will not be tested, and tests provided by plugins will
1432
bzr --no-plugins selftest -v
1427
1434
# TODO: --list should give a list of all available tests
1436
# NB: this is used from the class without creating an instance, which is
1437
# why it does not have a self parameter.
1438
def get_transport_type(typestring):
1439
"""Parse and return a transport specifier."""
1440
if typestring == "sftp":
1441
from bzrlib.transport.sftp import SFTPAbsoluteServer
1442
return SFTPAbsoluteServer
1443
if typestring == "memory":
1444
from bzrlib.transport.memory import MemoryServer
1446
msg = "No known transport type %s. Supported types are: sftp\n" %\
1448
raise BzrCommandError(msg)
1429
1451
takes_args = ['testspecs*']
1430
takes_options = ['verbose',
1452
takes_options = ['verbose',
1431
1453
Option('one', help='stop when one test fails'),
1432
1454
Option('keep-output',
1433
help='keep output directories when tests fail')
1455
help='keep output directories when tests fail'),
1457
help='Use a different transport by default '
1458
'throughout the test suite.',
1459
type=get_transport_type),
1436
1462
def run(self, testspecs_list=None, verbose=False, one=False,
1463
keep_output=False, transport=None):
1438
1464
import bzrlib.ui
1439
1465
from bzrlib.tests import selftest
1440
1466
# we don't want progress meters from the tests to go to the
1651
1678
raise BzrCommandError("Sorry, remerge only works after normal"
1652
1679
+ " merges. Not cherrypicking or"
1653
1680
+ "multi-merges.")
1681
repository = tree.branch.repository
1654
1682
base_revision = common_ancestor(tree.branch.last_revision(),
1655
pending_merges[0], tree.branch)
1656
base_tree = tree.branch.revision_tree(base_revision)
1657
other_tree = tree.branch.revision_tree(pending_merges[0])
1683
pending_merges[0], repository)
1684
base_tree = repository.revision_tree(base_revision)
1685
other_tree = repository.revision_tree(pending_merges[0])
1658
1686
interesting_ids = None
1659
1687
if file_list is not None:
1660
1688
interesting_ids = set()
1701
1729
aliases = ['merge-revert']
1703
1731
def run(self, revision=None, no_backup=False, file_list=None):
1704
from bzrlib.merge import merge_inner
1705
1732
from bzrlib.commands import parse_spec
1706
1733
if file_list is not None:
1707
1734
if len(file_list) == 0:
1708
1735
raise BzrCommandError("No files specified")
1739
tree, file_list = tree_files(file_list)
1711
1740
if revision is None:
1713
tree = WorkingTree.open_containing(u'.')[0]
1714
1741
# FIXME should be tree.last_revision
1715
1742
rev_id = tree.branch.last_revision()
1716
1743
elif len(revision) != 1:
1717
1744
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1719
tree, file_list = tree_files(file_list)
1720
1746
rev_id = revision[0].in_history(tree.branch).rev_id
1721
tree.revert(file_list, tree.branch.revision_tree(rev_id),
1747
tree.revert(file_list, tree.branch.repository.revision_tree(rev_id),
1725
1751
class cmd_assert_fail(Command):
1937
1957
b = WorkingTree.open_containing(u'.')[0].branch
1938
1958
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1939
1959
if revision_id is not None:
1940
b.sign_revision(revision_id, gpg_strategy)
1960
b.repository.sign_revision(revision_id, gpg_strategy)
1941
1961
elif revision is not None:
1942
1962
if len(revision) == 1:
1943
1963
revno, rev_id = revision[0].in_history(b)
1944
b.sign_revision(rev_id, gpg_strategy)
1964
b.repository.sign_revision(rev_id, gpg_strategy)
1945
1965
elif len(revision) == 2:
1946
1966
# are they both on rh- if so we can walk between them
1947
1967
# might be nice to have a range helper for arbitrary
1972
1993
In the future, uncommit will create a changeset, which can then
1996
TODO: jam 20060108 Add an option to allow uncommit to remove unreferenced
1997
information in 'branch-as-repostory' branches.
1998
TODO: jam 20060108 Add the ability for uncommit to remove unreferenced
1999
information in shared branches as well.
1975
takes_options = ['all', 'verbose', 'revision',
2001
takes_options = ['verbose', 'revision',
1976
2002
Option('dry-run', help='Don\'t actually make changes'),
1977
2003
Option('force', help='Say yes to all questions.')]
1978
2004
takes_args = ['location?']
1981
def run(self, location=None, all=False,
2007
def run(self, location=None,
1982
2008
dry_run=False, verbose=False,
1983
2009
revision=None, force=False):
1984
2010
from bzrlib.branch import Branch
2001
2027
for r in range(revno, b.revno()+1):
2002
2028
rev_id = b.get_rev_id(r)
2003
2029
lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2004
lf.show(r, b.get_revision(rev_id), None)
2030
lf.show(r, b.repository.get_revision(rev_id), None)
2007
2033
print 'Dry-run, pretending to remove the above revisions.'
2015
2041
print 'Canceled'
2018
uncommit(b, remove_files=all,
2019
dry_run=dry_run, verbose=verbose,
2044
uncommit(b, dry_run=dry_run, verbose=verbose,
2048
def merge(other_revision, base_revision,
2049
check_clean=True, ignore_zero=False,
2050
this_dir=None, backup_files=False, merge_type=ApplyMerge3,
2051
file_list=None, show_base=False, reprocess=False):
2052
"""Merge changes into a tree.
2055
list(path, revno) Base for three-way merge.
2056
If [None, None] then a base will be automatically determined.
2058
list(path, revno) Other revision for three-way merge.
2060
Directory to merge changes into; '.' by default.
2062
If true, this_dir must have no uncommitted changes before the
2064
ignore_zero - If true, suppress the "zero conflicts" message when
2065
there are no conflicts; should be set when doing something we expect
2066
to complete perfectly.
2067
file_list - If supplied, merge only changes to selected files.
2069
All available ancestors of other_revision and base_revision are
2070
automatically pulled into the branch.
2072
The revno may be -1 to indicate the last revision on the branch, which is
2075
This function is intended for use from the command line; programmatic
2076
clients might prefer to call merge.merge_inner(), which has less magic
2079
from bzrlib.merge import Merger, _MergeConflictHandler
2080
if this_dir is None:
2082
this_tree = WorkingTree.open_containing(this_dir)[0]
2083
if show_base and not merge_type is ApplyMerge3:
2084
raise BzrCommandError("Show-base is not supported for this merge"
2085
" type. %s" % merge_type)
2086
if reprocess and not merge_type is ApplyMerge3:
2087
raise BzrCommandError("Reprocess is not supported for this merge"
2088
" type. %s" % merge_type)
2089
if reprocess and show_base:
2090
raise BzrCommandError("Cannot reprocess and show base.")
2091
merger = Merger(this_tree.branch, this_tree=this_tree)
2092
merger.check_basis(check_clean)
2093
merger.set_other(other_revision)
2094
merger.set_base(base_revision)
2095
if merger.base_rev_id == merger.other_rev_id:
2096
note('Nothing to do.')
2098
merger.backup_files = backup_files
2099
merger.merge_type = merge_type
2100
merger.set_interesting_files(file_list)
2101
merger.show_base = show_base
2102
merger.reprocess = reprocess
2103
merger.conflict_handler = _MergeConflictHandler(merger.this_tree,
2106
ignore_zero=ignore_zero)
2107
conflicts = merger.do_merge()
2108
merger.set_pending()
2023
2112
# these get imported and then picked up by the scan for cmd_*
2024
2113
# TODO: Some more consistent way to split command definitions across files;
2025
2114
# we do need to load at least some information about them to know of