1111
1588
# Just using os.mkdir, since I don't
1112
1589
# believe that we want to create a bunch of
1113
1590
# locations if the user supplies an extended path
1114
# TODO: create-prefix
1116
to_transport.mkdir('.')
1117
except errors.FileExists:
1121
existing_bzrdir = bzrdir.BzrDir.open(location)
1592
to_transport.ensure_base()
1593
except errors.NoSuchFile:
1594
if not create_prefix:
1595
raise errors.BzrCommandError("Parent directory of %s"
1597
"\nYou may supply --create-prefix to create all"
1598
" leading parent directories."
1600
to_transport.create_prefix()
1603
a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1122
1604
except errors.NotBranchError:
1123
1605
# really a NotBzrDir error...
1124
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1606
create_branch = bzrdir.BzrDir.create_branch_convenience
1607
branch = create_branch(to_transport.base, format=format,
1608
possible_transports=[to_transport])
1609
a_bzrdir = branch.bzrdir
1126
1611
from bzrlib.transport.local import LocalTransport
1127
if existing_bzrdir.has_branch():
1612
if a_bzrdir.has_branch():
1128
1613
if (isinstance(to_transport, LocalTransport)
1129
and not existing_bzrdir.has_workingtree()):
1614
and not a_bzrdir.has_workingtree()):
1130
1615
raise errors.BranchExistsWithoutWorkingTree(location)
1131
1616
raise errors.AlreadyBranchError(location)
1133
existing_bzrdir.create_branch()
1134
existing_bzrdir.create_workingtree()
1617
branch = a_bzrdir.create_branch()
1618
a_bzrdir.create_workingtree()
1619
if append_revisions_only:
1621
branch.set_append_revisions_only(True)
1622
except errors.UpgradeRequired:
1623
raise errors.BzrCommandError('This branch format cannot be set'
1624
' to append-revisions-only. Try --experimental-branch6')
1626
from bzrlib.info import describe_layout, describe_format
1628
tree = a_bzrdir.open_workingtree(recommend_upgrade=False)
1629
except (errors.NoWorkingTree, errors.NotLocalUrl):
1631
repository = branch.repository
1632
layout = describe_layout(repository, branch, tree).lower()
1633
format = describe_format(a_bzrdir, repository, branch, tree)
1634
self.outf.write("Created a %s (format: %s)\n" % (layout, format))
1635
if repository.is_shared():
1636
#XXX: maybe this can be refactored into transport.path_or_url()
1637
url = repository.bzrdir.root_transport.external_url()
1639
url = urlutils.local_path_from_url(url)
1640
except errors.InvalidURL:
1642
self.outf.write("Using shared repository: %s\n" % url)
1137
1645
class cmd_init_repository(Command):
1138
1646
"""Create a shared repository to hold branches.
1140
New branches created under the repository directory will store their revisions
1141
in the repository, not in the branch directory, if the branch format supports
1147
bzr checkout --lightweight repo/trunk trunk-checkout
1648
New branches created under the repository directory will store their
1649
revisions in the repository, not in the branch directory.
1651
If the --no-trees option is used then the branches in the repository
1652
will not have working trees by default.
1655
Create a shared repositories holding just branches::
1657
bzr init-repo --no-trees repo
1660
Make a lightweight checkout elsewhere::
1662
bzr checkout --lightweight repo/trunk trunk-checkout
1151
takes_args = ["location"]
1667
_see_also = ['init', 'branch', 'checkout', 'repositories']
1668
takes_args = ["location"]
1152
1669
takes_options = [RegistryOption('format',
1153
help='Specify a format for this repository.'
1154
' Current formats are: default, knit,'
1155
' metaweave and weave. Default is knit;'
1156
' metaweave and weave are deprecated',
1157
registry=bzrdir.format_registry,
1158
converter=get_format_type,
1159
value_switches=True),
1161
help='Allows branches in repository to have'
1670
help='Specify a format for this repository. See'
1671
' "bzr help formats" for details.',
1672
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1673
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1674
value_switches=True, title='Repository format'),
1676
help='Branches in the repository will default to'
1677
' not having a working tree.'),
1163
1679
aliases = ["init-repo"]
1164
def run(self, location, format=None, trees=False):
1681
def run(self, location, format=None, no_trees=False):
1165
1682
if format is None:
1166
format = get_format_type('default')
1683
format = bzrdir.format_registry.make_bzrdir('default')
1168
1685
if location is None:
1171
1688
to_transport = transport.get_transport(location)
1173
to_transport.mkdir('.')
1174
except errors.FileExists:
1689
to_transport.ensure_base()
1177
1691
newdir = format.initialize_on_transport(to_transport)
1178
1692
repo = newdir.create_repository(shared=True)
1179
repo.set_make_working_trees(trees)
1693
repo.set_make_working_trees(not no_trees)
1695
from bzrlib.info import show_bzrdir_info
1696
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
1182
1699
class cmd_diff(Command):
1183
"""Show differences in the working tree or between revisions.
1185
If files are listed, only the changes in those files are listed.
1186
Otherwise, all changes for the tree are listed.
1700
"""Show differences in the working tree, between revisions or branches.
1702
If no arguments are given, all changes for the current tree are listed.
1703
If files are given, only the changes in those files are listed.
1704
Remote and multiple branches can be compared by using the --old and
1705
--new options. If not provided, the default for both is derived from
1706
the first argument, if any, or the current tree if no arguments are
1188
1709
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1189
1710
produces patches suitable for "patch -p1".
1193
Shows the difference in the working tree versus the last commit
1195
Difference between the working tree and revision 1
1197
Difference between revision 2 and revision 1
1198
bzr diff --diff-prefix old/:new/
1199
Same as 'bzr diff' but prefix paths with old/ and new/
1200
bzr diff bzr.mine bzr.dev
1201
Show the differences between the two working trees
1203
Show just the differences for 'foo.c'
1714
2 - unrepresentable changes
1719
Shows the difference in the working tree versus the last commit::
1723
Difference between the working tree and revision 1::
1727
Difference between revision 2 and revision 1::
1731
Difference between revision 2 and revision 1 for branch xxx::
1735
Show just the differences for file NEWS::
1739
Show the differences in working tree xxx for file NEWS::
1743
Show the differences from branch xxx to this working tree:
1747
Show the differences between two branches for file NEWS::
1749
bzr diff --old xxx --new yyy NEWS
1751
Same as 'bzr diff' but prefix paths with old/ and new/::
1753
bzr diff --prefix old/:new/
1205
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1206
# or a graphical diff.
1208
# TODO: Python difflib is not exactly the same as unidiff; should
1209
# either fix it up or prefer to use an external diff.
1211
# TODO: Selected-file diff is inefficient and doesn't show you
1214
# TODO: This probably handles non-Unix newlines poorly.
1755
_see_also = ['status']
1216
1756
takes_args = ['file*']
1217
takes_options = ['revision', 'diff-options',
1758
Option('diff-options', type=str,
1759
help='Pass these options to the external diff program.'),
1218
1760
Option('prefix', type=str,
1219
1761
short_name='p',
1220
help='Set prefixes to added to old and new filenames, as '
1221
'two values separated by a colon.'),
1762
help='Set prefixes added to old and new filenames, as '
1763
'two values separated by a colon. (eg "old/:new/").'),
1765
help='Branch/tree to compare from.',
1769
help='Branch/tree to compare to.',
1775
help='Use this command to compare files.',
1223
1779
aliases = ['di', 'dif']
1224
1780
encoding_type = 'exact'
1226
1782
@display_command
1227
1783
def run(self, revision=None, file_list=None, diff_options=None,
1229
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1784
prefix=None, old=None, new=None, using=None):
1785
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1231
1787
if (prefix is None) or (prefix == '0'):
1232
1788
# diff -p0 format
1355
1922
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)
1358
1941
class cmd_log(Command):
1359
"""Show log of a branch, file, or directory.
1361
By default show the log of the branch containing the working directory.
1363
To request a range of logs, you can use the command -r begin..end
1364
-r revision requests a specific revision, -r ..end or -r begin.. are
1370
bzr log -r -10.. http://server/branch
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.
1373
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1375
takes_args = ['location?']
1376
takes_options = [Option('forward',
1377
help='show from oldest to newest'),
1381
help='show files changed in each revision'),
1382
'show-ids', 'revision',
1387
help='show revisions whose message matches this regexp',
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.'),
1391
2133
encoding_type = 'replace'
1393
2135
@display_command
1394
def run(self, location=None, timezone='original',
2136
def run(self, file_list=None, timezone='original',
1396
2138
show_ids=False,
1399
2142
log_format=None,
1404
from bzrlib.log import log_formatter, show_log
1405
assert message is None or isinstance(message, basestring), \
1406
"invalid message argument %r" % message
2147
include_merges=False):
2148
from bzrlib.log import (
2150
make_log_request_dict,
2151
_get_info_for_log_files,
1407
2153
direction = (forward and 'forward') or 'reverse'
1412
# find the file id to log:
1414
dir, fp = bzrdir.BzrDir.open_containing(location)
1415
b = dir.open_branch()
1419
inv = dir.open_workingtree().inventory
1420
except (errors.NotBranchError, errors.NotLocalUrl):
1421
# either no tree, or is remote.
1422
inv = b.basis_tree().inventory
1423
file_id = inv.path2id(fp)
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:
1424
2177
if file_id is None:
1425
2178
raise errors.BzrCommandError(
1426
"Path does not have any revision history: %s" %
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'])
1430
# FIXME ? log the current subdir only RBC 20060203
2191
# FIXME ? log the current subdir only RBC 20060203
1431
2192
if revision is not None \
1432
2193
and len(revision) > 0 and revision[0].get_branch():
1433
2194
location = revision[0].get_branch()
2262
3457
default, use --remember. The value will only be saved if the remote
2263
3458
location can be accessed.
2267
To merge the latest revision from bzr.dev
2268
bzr merge ../bzr.dev
2270
To merge changes up to and including revision 82 from bzr.dev
2271
bzr merge -r 82 ../bzr.dev
2273
To merge the changes introduced by 82, without previous changes:
2274
bzr merge -r 81..82 ../bzr.dev
3460
The results of the merge are placed into the destination working
3461
directory, where they can be reviewed (with bzr diff), tested, and then
3462
committed to record the result of the merge.
2276
3464
merge refuses to run if there are any uncommitted changes, unless
2277
3465
--force is given.
2279
The following merge types are available:
3468
To merge the latest revision from bzr.dev::
3470
bzr merge ../bzr.dev
3472
To merge changes up to and including revision 82 from bzr.dev::
3474
bzr merge -r 82 ../bzr.dev
3476
To merge the changes introduced by 82, without previous changes::
3478
bzr merge -r 81..82 ../bzr.dev
3480
To apply a merge directive contained in /tmp/merge:
3482
bzr merge /tmp/merge
2281
takes_args = ['branch?']
2282
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2283
Option('show-base', help="Show base revision text in "
2285
Option('uncommitted', help='Apply uncommitted changes'
2286
' from a working copy, instead of branch changes'),
2287
Option('pull', help='If the destination is already'
2288
' completely merged into the source, pull from the'
2289
' source rather than merging. When this happens,'
2290
' you do not need to commit the result.'),
2294
from inspect import getdoc
2295
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2297
def run(self, branch=None, revision=None, force=False, merge_type=None,
2298
show_base=False, reprocess=False, remember=False,
2299
uncommitted=False, pull=False):
3485
encoding_type = 'exact'
3486
_see_also = ['update', 'remerge', 'status-flags', 'send']
3487
takes_args = ['location?']
3492
help='Merge even if the destination tree has uncommitted changes.'),
3496
Option('show-base', help="Show base revision text in "
3498
Option('uncommitted', help='Apply uncommitted changes'
3499
' from a working copy, instead of branch changes.'),
3500
Option('pull', help='If the destination is already'
3501
' completely merged into the source, pull from the'
3502
' source rather than merging. When this happens,'
3503
' you do not need to commit the result.'),
3505
help='Branch to merge into, '
3506
'rather than the one containing the working directory.',
3510
Option('preview', help='Instead of merging, show a diff of the merge.')
3513
def run(self, location=None, revision=None, force=False,
3514
merge_type=None, show_base=False, reprocess=None, remember=False,
3515
uncommitted=False, pull=False,
2300
3519
if merge_type is None:
2301
3520
merge_type = _mod_merge.Merge3Merger
2303
tree = WorkingTree.open_containing(u'.')[0]
2305
if branch is not None:
2307
reader = bundle.read_bundle_from_url(branch)
2308
except errors.NotABundle:
2309
pass # Continue on considering this url a Branch
2311
conflicts = merge_bundle(reader, tree, not force, merge_type,
2312
reprocess, show_base)
3522
if directory is None: directory = u'.'
3523
possible_transports = []
3525
allow_pending = True
3526
verified = 'inapplicable'
3527
tree = WorkingTree.open_containing(directory)[0]
3529
# die as quickly as possible if there are uncommitted changes
3531
basis_tree = tree.revision_tree(tree.last_revision())
3532
except errors.NoSuchRevision:
3533
basis_tree = tree.basis_tree()
3535
changes = tree.changes_from(basis_tree)
3536
if changes.has_changed():
3537
raise errors.UncommittedChanges(tree)
3539
view_info = _get_view_info_for_change_reporter(tree)
3540
change_reporter = delta._ChangeReporter(
3541
unversioned_filter=tree.is_ignored, view_info=view_info)
3544
pb = ui.ui_factory.nested_progress_bar()
3545
cleanups.append(pb.finished)
3547
cleanups.append(tree.unlock)
3548
if location is not None:
3550
mergeable = bundle.read_mergeable_from_url(location,
3551
possible_transports=possible_transports)
3552
except errors.NotABundle:
2318
if revision is None \
2319
or len(revision) < 1 or revision[0].needs_branch():
2320
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2322
if revision is None or len(revision) < 1:
2325
other = [branch, None]
2328
other = [branch, -1]
2329
other_branch, path = Branch.open_containing(branch)
2332
raise errors.BzrCommandError('Cannot use --uncommitted and'
2333
' --revision at the same time.')
2334
branch = revision[0].get_branch() or branch
2335
if len(revision) == 1:
2337
other_branch, path = Branch.open_containing(branch)
2338
revno = revision[0].in_history(other_branch).revno
2339
other = [branch, revno]
2341
assert len(revision) == 2
2342
if None in revision:
2343
raise errors.BzrCommandError(
2344
"Merge doesn't permit empty revision specifier.")
2345
base_branch, path = Branch.open_containing(branch)
2346
branch1 = revision[1].get_branch() or branch
2347
other_branch, path1 = Branch.open_containing(branch1)
2348
if revision[0].get_branch() is not None:
2349
# then path was obtained from it, and is None.
2352
base = [branch, revision[0].in_history(base_branch).revno]
2353
other = [branch1, revision[1].in_history(other_branch).revno]
2355
if tree.branch.get_parent() is None or remember:
2356
tree.branch.set_parent(other_branch.base)
2359
interesting_files = [path]
2361
interesting_files = None
2362
pb = ui.ui_factory.nested_progress_bar()
2365
conflict_count = _merge_helper(
2366
other, base, check_clean=(not force),
2367
merge_type=merge_type,
2368
reprocess=reprocess,
2369
show_base=show_base,
2371
pb=pb, file_list=interesting_files)
2374
if conflict_count != 0:
3556
raise errors.BzrCommandError('Cannot use --uncommitted'
3557
' with bundles or merge directives.')
3559
if revision is not None:
3560
raise errors.BzrCommandError(
3561
'Cannot use -r with merge directives or bundles')
3562
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3565
if merger is None and uncommitted:
3566
if revision is not None and len(revision) > 0:
3567
raise errors.BzrCommandError('Cannot use --uncommitted and'
3568
' --revision at the same time.')
3569
location = self._select_branch_location(tree, location)[0]
3570
other_tree, other_path = WorkingTree.open_containing(location)
3571
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
3573
allow_pending = False
3574
if other_path != '':
3575
merger.interesting_files = [other_path]
3578
merger, allow_pending = self._get_merger_from_branch(tree,
3579
location, revision, remember, possible_transports, pb)
3581
merger.merge_type = merge_type
3582
merger.reprocess = reprocess
3583
merger.show_base = show_base
3584
self.sanity_check_merger(merger)
3585
if (merger.base_rev_id == merger.other_rev_id and
3586
merger.other_rev_id is not None):
3587
note('Nothing to do.')
2378
except errors.AmbiguousBase, e:
2379
m = ("sorry, bzr can't determine the right merge base yet\n"
2380
"candidates are:\n "
2381
+ "\n ".join(e.bases)
2383
"please specify an explicit base with -r,\n"
2384
"and (if you want) report this to the bzr developers\n")
2387
# TODO: move up to common parent; this isn't merge-specific anymore.
2388
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3590
if merger.interesting_files is not None:
3591
raise errors.BzrCommandError('Cannot pull individual files')
3592
if (merger.base_rev_id == tree.last_revision()):
3593
result = tree.pull(merger.other_branch, False,
3594
merger.other_rev_id)
3595
result.report(self.outf)
3597
merger.check_basis(False)
3599
return self._do_preview(merger)
3601
return self._do_merge(merger, change_reporter, allow_pending,
3604
for cleanup in reversed(cleanups):
3607
def _do_preview(self, merger):
3608
from bzrlib.diff import show_diff_trees
3609
tree_merger = merger.make_merger()
3610
tt = tree_merger.make_preview_transform()
3612
result_tree = tt.get_preview_tree()
3613
show_diff_trees(merger.this_tree, result_tree, self.outf,
3614
old_label='', new_label='')
3618
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3619
merger.change_reporter = change_reporter
3620
conflict_count = merger.do_merge()
3622
merger.set_pending()
3623
if verified == 'failed':
3624
warning('Preview patch does not match changes')
3625
if conflict_count != 0:
3630
def sanity_check_merger(self, merger):
3631
if (merger.show_base and
3632
not merger.merge_type is _mod_merge.Merge3Merger):
3633
raise errors.BzrCommandError("Show-base is not supported for this"
3634
" merge type. %s" % merger.merge_type)
3635
if merger.reprocess is None:
3636
if merger.show_base:
3637
merger.reprocess = False
3639
# Use reprocess if the merger supports it
3640
merger.reprocess = merger.merge_type.supports_reprocess
3641
if merger.reprocess and not merger.merge_type.supports_reprocess:
3642
raise errors.BzrCommandError("Conflict reduction is not supported"
3643
" for merge type %s." %
3645
if merger.reprocess and merger.show_base:
3646
raise errors.BzrCommandError("Cannot do conflict reduction and"
3649
def _get_merger_from_branch(self, tree, location, revision, remember,
3650
possible_transports, pb):
3651
"""Produce a merger from a location, assuming it refers to a branch."""
3652
from bzrlib.tag import _merge_tags_if_possible
3653
# find the branch locations
3654
other_loc, user_location = self._select_branch_location(tree, location,
3656
if revision is not None and len(revision) == 2:
3657
base_loc, _unused = self._select_branch_location(tree,
3658
location, revision, 0)
3660
base_loc = other_loc
3662
other_branch, other_path = Branch.open_containing(other_loc,
3663
possible_transports)
3664
if base_loc == other_loc:
3665
base_branch = other_branch
3667
base_branch, base_path = Branch.open_containing(base_loc,
3668
possible_transports)
3669
# Find the revision ids
3670
if revision is None or len(revision) < 1 or revision[-1] is None:
3671
other_revision_id = _mod_revision.ensure_null(
3672
other_branch.last_revision())
3674
other_revision_id = revision[-1].as_revision_id(other_branch)
3675
if (revision is not None and len(revision) == 2
3676
and revision[0] is not None):
3677
base_revision_id = revision[0].as_revision_id(base_branch)
3679
base_revision_id = None
3680
# Remember where we merge from
3681
if ((remember or tree.branch.get_submit_branch() is None) and
3682
user_location is not None):
3683
tree.branch.set_submit_branch(other_branch.base)
3684
_merge_tags_if_possible(other_branch, tree.branch)
3685
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3686
other_revision_id, base_revision_id, other_branch, base_branch)
3687
if other_path != '':
3688
allow_pending = False
3689
merger.interesting_files = [other_path]
3691
allow_pending = True
3692
return merger, allow_pending
3694
def _select_branch_location(self, tree, user_location, revision=None,
3696
"""Select a branch location, according to possible inputs.
3698
If provided, branches from ``revision`` are preferred. (Both
3699
``revision`` and ``index`` must be supplied.)
3701
Otherwise, the ``location`` parameter is used. If it is None, then the
3702
``submit`` or ``parent`` location is used, and a note is printed.
3704
:param tree: The working tree to select a branch for merging into
3705
:param location: The location entered by the user
3706
:param revision: The revision parameter to the command
3707
:param index: The index to use for the revision parameter. Negative
3708
indices are permitted.
3709
:return: (selected_location, user_location). The default location
3710
will be the user-entered location.
3712
if (revision is not None and index is not None
3713
and revision[index] is not None):
3714
branch = revision[index].get_branch()
3715
if branch is not None:
3716
return branch, branch
3717
if user_location is None:
3718
location = self._get_remembered(tree, 'Merging from')
3720
location = user_location
3721
return location, user_location
3723
def _get_remembered(self, tree, verb_string):
2389
3724
"""Use tree.branch's parent if none was supplied.
2391
3726
Report if the remembered location was used.
2393
if supplied_location is not None:
2394
return supplied_location
2395
stored_location = tree.branch.get_parent()
3728
stored_location = tree.branch.get_submit_branch()
3729
stored_location_type = "submit"
3730
if stored_location is None:
3731
stored_location = tree.branch.get_parent()
3732
stored_location_type = "parent"
2396
3733
mutter("%s", stored_location)
2397
3734
if stored_location is None:
2398
3735
raise errors.BzrCommandError("No location specified or remembered")
2399
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2400
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3736
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3737
note(u"%s remembered %s location %s", verb_string,
3738
stored_location_type, display_url)
2401
3739
return stored_location
2985
4551
takes_options = [
2987
help='serve on stdin/out for use from inetd or sshd'),
4553
help='Serve on stdin/out for use from inetd or sshd.'),
4554
RegistryOption('protocol',
4555
help="Protocol to serve.",
4556
lazy_registry=('bzrlib.transport', 'transport_server_registry'),
4557
value_switches=True),
2989
help='listen for connections on nominated port of the form '
2990
'[hostname:]portnumber. Passing 0 as the port number will '
2991
'result in a dynamically allocated port.',
4559
help='Listen for connections on nominated port of the form '
4560
'[hostname:]portnumber. Passing 0 as the port number will '
4561
'result in a dynamically allocated port. The default port '
4562
'depends on the protocol.',
2993
4564
Option('directory',
2994
help='serve contents of directory',
4565
help='Serve contents of this directory.',
2996
4567
Option('allow-writes',
2997
help='By default the server is a readonly server. Supplying '
4568
help='By default the server is a readonly server. Supplying '
2998
4569
'--allow-writes enables write access to the contents of '
2999
'the served directory and below. '
4570
'the served directory and below.'
3003
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3004
from bzrlib.transport import smart
3005
from bzrlib.transport import get_transport
4574
def get_host_and_port(self, port):
4575
"""Return the host and port to run the smart server on.
4577
If 'port' is None, None will be returned for the host and port.
4579
If 'port' has a colon in it, the string before the colon will be
4580
interpreted as the host.
4582
:param port: A string of the port to run the server on.
4583
:return: A tuple of (host, port), where 'host' is a host name or IP,
4584
and port is an integer TCP/IP port.
4587
if port is not None:
4589
host, port = port.split(':')
4593
def run(self, port=None, inet=False, directory=None, allow_writes=False,
4595
from bzrlib.transport import get_transport, transport_server_registry
3006
4596
if directory is None:
3007
4597
directory = os.getcwd()
4598
if protocol is None:
4599
protocol = transport_server_registry.get()
4600
host, port = self.get_host_and_port(port)
3008
4601
url = urlutils.local_path_to_url(directory)
3009
4602
if not allow_writes:
3010
4603
url = 'readonly+' + url
3011
t = get_transport(url)
3013
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3014
elif port is not None:
3016
host, port = port.split(':')
3019
server = smart.SmartTCPServer(t, host=host, port=int(port))
3020
print 'listening on port: ', server.port
3023
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3027
# command-line interpretation helper for merge-related commands
3028
def _merge_helper(other_revision, base_revision,
3029
check_clean=True, ignore_zero=False,
3030
this_dir=None, backup_files=False,
3032
file_list=None, show_base=False, reprocess=False,
3034
pb=DummyProgress()):
3035
"""Merge changes into a tree.
3038
list(path, revno) Base for three-way merge.
3039
If [None, None] then a base will be automatically determined.
3041
list(path, revno) Other revision for three-way merge.
3043
Directory to merge changes into; '.' by default.
3045
If true, this_dir must have no uncommitted changes before the
3047
ignore_zero - If true, suppress the "zero conflicts" message when
3048
there are no conflicts; should be set when doing something we expect
3049
to complete perfectly.
3050
file_list - If supplied, merge only changes to selected files.
3052
All available ancestors of other_revision and base_revision are
3053
automatically pulled into the branch.
3055
The revno may be -1 to indicate the last revision on the branch, which is
3058
This function is intended for use from the command line; programmatic
3059
clients might prefer to call merge.merge_inner(), which has less magic
3062
# Loading it late, so that we don't always have to import bzrlib.merge
3063
if merge_type is None:
3064
merge_type = _mod_merge.Merge3Merger
3065
if this_dir is None:
3067
this_tree = WorkingTree.open_containing(this_dir)[0]
3068
if show_base and not merge_type is _mod_merge.Merge3Merger:
3069
raise errors.BzrCommandError("Show-base is not supported for this merge"
3070
" type. %s" % merge_type)
3071
if reprocess and not merge_type.supports_reprocess:
3072
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3073
" type %s." % merge_type)
3074
if reprocess and show_base:
3075
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3077
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3079
merger.pp = ProgressPhase("Merge phase", 5, pb)
3080
merger.pp.next_phase()
3081
merger.check_basis(check_clean)
3082
merger.set_other(other_revision)
3083
merger.pp.next_phase()
3084
merger.set_base(base_revision)
3085
if merger.base_rev_id == merger.other_rev_id:
3086
note('Nothing to do.')
4604
transport = get_transport(url)
4605
protocol(transport, host, port, inet)
4608
class cmd_join(Command):
4609
"""Combine a tree into its containing tree.
4611
This command requires the target tree to be in a rich-root format.
4613
The TREE argument should be an independent tree, inside another tree, but
4614
not part of it. (Such trees can be produced by "bzr split", but also by
4615
running "bzr branch" with the target inside a tree.)
4617
The result is a combined tree, with the subtree no longer an independant
4618
part. This is marked as a merge of the subtree into the containing tree,
4619
and all history is preserved.
4622
_see_also = ['split']
4623
takes_args = ['tree']
4625
Option('reference', help='Join by reference.', hidden=True),
4628
def run(self, tree, reference=False):
4629
sub_tree = WorkingTree.open(tree)
4630
parent_dir = osutils.dirname(sub_tree.basedir)
4631
containing_tree = WorkingTree.open_containing(parent_dir)[0]
4632
repo = containing_tree.branch.repository
4633
if not repo.supports_rich_root():
4634
raise errors.BzrCommandError(
4635
"Can't join trees because %s doesn't support rich root data.\n"
4636
"You can use bzr upgrade on the repository."
4640
containing_tree.add_reference(sub_tree)
4641
except errors.BadReferenceTarget, e:
4642
# XXX: Would be better to just raise a nicely printable
4643
# exception from the real origin. Also below. mbp 20070306
4644
raise errors.BzrCommandError("Cannot join %s. %s" %
4648
containing_tree.subsume(sub_tree)
4649
except errors.BadSubsumeSource, e:
4650
raise errors.BzrCommandError("Cannot join %s. %s" %
4654
class cmd_split(Command):
4655
"""Split a subdirectory of a tree into a separate tree.
4657
This command will produce a target tree in a format that supports
4658
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
4659
converted into earlier formats like 'dirstate-tags'.
4661
The TREE argument should be a subdirectory of a working tree. That
4662
subdirectory will be converted into an independent tree, with its own
4663
branch. Commits in the top-level tree will not apply to the new subtree.
4666
_see_also = ['join']
4667
takes_args = ['tree']
4669
def run(self, tree):
4670
containing_tree, subdir = WorkingTree.open_containing(tree)
4671
sub_id = containing_tree.path2id(subdir)
4673
raise errors.NotVersionedError(subdir)
4675
containing_tree.extract(sub_id)
4676
except errors.RootNotRich:
4677
raise errors.UpgradeRequired(containing_tree.branch.base)
4680
class cmd_merge_directive(Command):
4681
"""Generate a merge directive for auto-merge tools.
4683
A directive requests a merge to be performed, and also provides all the
4684
information necessary to do so. This means it must either include a
4685
revision bundle, or the location of a branch containing the desired
4688
A submit branch (the location to merge into) must be supplied the first
4689
time the command is issued. After it has been supplied once, it will
4690
be remembered as the default.
4692
A public branch is optional if a revision bundle is supplied, but required
4693
if --diff or --plain is specified. It will be remembered as the default
4694
after the first use.
4697
takes_args = ['submit_branch?', 'public_branch?']
4701
_see_also = ['send']
4704
RegistryOption.from_kwargs('patch-type',
4705
'The type of patch to include in the directive.',
4707
value_switches=True,
4709
bundle='Bazaar revision bundle (default).',
4710
diff='Normal unified diff.',
4711
plain='No patch, just directive.'),
4712
Option('sign', help='GPG-sign the directive.'), 'revision',
4713
Option('mail-to', type=str,
4714
help='Instead of printing the directive, email to this address.'),
4715
Option('message', type=str, short_name='m',
4716
help='Message to use when committing this merge.')
4719
encoding_type = 'exact'
4721
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
4722
sign=False, revision=None, mail_to=None, message=None):
4723
from bzrlib.revision import ensure_null, NULL_REVISION
4724
include_patch, include_bundle = {
4725
'plain': (False, False),
4726
'diff': (True, False),
4727
'bundle': (True, True),
4729
branch = Branch.open('.')
4730
stored_submit_branch = branch.get_submit_branch()
4731
if submit_branch is None:
4732
submit_branch = stored_submit_branch
4734
if stored_submit_branch is None:
4735
branch.set_submit_branch(submit_branch)
4736
if submit_branch is None:
4737
submit_branch = branch.get_parent()
4738
if submit_branch is None:
4739
raise errors.BzrCommandError('No submit branch specified or known')
4741
stored_public_branch = branch.get_public_branch()
4742
if public_branch is None:
4743
public_branch = stored_public_branch
4744
elif stored_public_branch is None:
4745
branch.set_public_branch(public_branch)
4746
if not include_bundle and public_branch is None:
4747
raise errors.BzrCommandError('No public branch specified or'
4749
base_revision_id = None
4750
if revision is not None:
4751
if len(revision) > 2:
4752
raise errors.BzrCommandError('bzr merge-directive takes '
4753
'at most two one revision identifiers')
4754
revision_id = revision[-1].as_revision_id(branch)
4755
if len(revision) == 2:
4756
base_revision_id = revision[0].as_revision_id(branch)
4758
revision_id = branch.last_revision()
4759
revision_id = ensure_null(revision_id)
4760
if revision_id == NULL_REVISION:
4761
raise errors.BzrCommandError('No revisions to bundle.')
4762
directive = merge_directive.MergeDirective2.from_objects(
4763
branch.repository, revision_id, time.time(),
4764
osutils.local_time_offset(), submit_branch,
4765
public_branch=public_branch, include_patch=include_patch,
4766
include_bundle=include_bundle, message=message,
4767
base_revision_id=base_revision_id)
4770
self.outf.write(directive.to_signed(branch))
4772
self.outf.writelines(directive.to_lines())
4774
message = directive.to_email(mail_to, branch, sign)
4775
s = SMTPConnection(branch.get_config())
4776
s.send_email(message)
4779
class cmd_send(Command):
4780
"""Mail or create a merge-directive for submitting changes.
4782
A merge directive provides many things needed for requesting merges:
4784
* A machine-readable description of the merge to perform
4786
* An optional patch that is a preview of the changes requested
4788
* An optional bundle of revision data, so that the changes can be applied
4789
directly from the merge directive, without retrieving data from a
4792
If --no-bundle is specified, then public_branch is needed (and must be
4793
up-to-date), so that the receiver can perform the merge using the
4794
public_branch. The public_branch is always included if known, so that
4795
people can check it later.
4797
The submit branch defaults to the parent, but can be overridden. Both
4798
submit branch and public branch will be remembered if supplied.
4800
If a public_branch is known for the submit_branch, that public submit
4801
branch is used in the merge instructions. This means that a local mirror
4802
can be used as your actual submit branch, once you have set public_branch
4805
Mail is sent using your preferred mail program. This should be transparent
4806
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4807
If the preferred client can't be found (or used), your editor will be used.
4809
To use a specific mail program, set the mail_client configuration option.
4810
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4811
specific clients are "claws", "evolution", "kmail", "mutt", and
4812
"thunderbird"; generic options are "default", "editor", "emacsclient",
4813
"mapi", and "xdg-email". Plugins may also add supported clients.
4815
If mail is being sent, a to address is required. This can be supplied
4816
either on the commandline, by setting the submit_to configuration
4817
option in the branch itself or the child_submit_to configuration option
4818
in the submit branch.
4820
Two formats are currently supported: "4" uses revision bundle format 4 and
4821
merge directive format 2. It is significantly faster and smaller than
4822
older formats. It is compatible with Bazaar 0.19 and later. It is the
4823
default. "0.9" uses revision bundle format 0.9 and merge directive
4824
format 1. It is compatible with Bazaar 0.12 - 0.18.
4826
The merge directives created by bzr send may be applied using bzr merge or
4827
bzr pull by specifying a file containing a merge directive as the location.
4830
encoding_type = 'exact'
4832
_see_also = ['merge', 'pull']
4834
takes_args = ['submit_branch?', 'public_branch?']
4838
help='Do not include a bundle in the merge directive.'),
4839
Option('no-patch', help='Do not include a preview patch in the merge'
4842
help='Remember submit and public branch.'),
4844
help='Branch to generate the submission from, '
4845
'rather than the one containing the working directory.',
4848
Option('output', short_name='o',
4849
help='Write merge directive to this file; '
4850
'use - for stdout.',
4852
Option('mail-to', help='Mail the request to this address.',
4856
Option('body', help='Body for the email.', type=unicode),
4857
RegistryOption('format',
4858
help='Use the specified output format.',
4859
lazy_registry=('bzrlib.send', 'format_registry'))
4862
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4863
no_patch=False, revision=None, remember=False, output=None,
4864
format=None, mail_to=None, message=None, body=None, **kwargs):
4865
from bzrlib.send import send
4866
return send(submit_branch, revision, public_branch, remember,
4867
format, no_bundle, no_patch, output,
4868
kwargs.get('from', '.'), mail_to, message, body,
4872
class cmd_bundle_revisions(cmd_send):
4873
"""Create a merge-directive for submitting changes.
4875
A merge directive provides many things needed for requesting merges:
4877
* A machine-readable description of the merge to perform
4879
* An optional patch that is a preview of the changes requested
4881
* An optional bundle of revision data, so that the changes can be applied
4882
directly from the merge directive, without retrieving data from a
4885
If --no-bundle is specified, then public_branch is needed (and must be
4886
up-to-date), so that the receiver can perform the merge using the
4887
public_branch. The public_branch is always included if known, so that
4888
people can check it later.
4890
The submit branch defaults to the parent, but can be overridden. Both
4891
submit branch and public branch will be remembered if supplied.
4893
If a public_branch is known for the submit_branch, that public submit
4894
branch is used in the merge instructions. This means that a local mirror
4895
can be used as your actual submit branch, once you have set public_branch
4898
Two formats are currently supported: "4" uses revision bundle format 4 and
4899
merge directive format 2. It is significantly faster and smaller than
4900
older formats. It is compatible with Bazaar 0.19 and later. It is the
4901
default. "0.9" uses revision bundle format 0.9 and merge directive
4902
format 1. It is compatible with Bazaar 0.12 - 0.18.
4907
help='Do not include a bundle in the merge directive.'),
4908
Option('no-patch', help='Do not include a preview patch in the merge'
4911
help='Remember submit and public branch.'),
4913
help='Branch to generate the submission from, '
4914
'rather than the one containing the working directory.',
4917
Option('output', short_name='o', help='Write directive to this file.',
4920
RegistryOption('format',
4921
help='Use the specified output format.',
4922
lazy_registry=('bzrlib.send', 'format_registry')),
4924
aliases = ['bundle']
4926
_see_also = ['send', 'merge']
4930
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4931
no_patch=False, revision=None, remember=False, output=None,
4932
format=None, **kwargs):
4935
from bzrlib.send import send
4936
return send(submit_branch, revision, public_branch, remember,
4937
format, no_bundle, no_patch, output,
4938
kwargs.get('from', '.'), None, None, None,
4942
class cmd_tag(Command):
4943
"""Create, remove or modify a tag naming a revision.
4945
Tags give human-meaningful names to revisions. Commands that take a -r
4946
(--revision) option can be given -rtag:X, where X is any previously
4949
Tags are stored in the branch. Tags are copied from one branch to another
4950
along when you branch, push, pull or merge.
4952
It is an error to give a tag name that already exists unless you pass
4953
--force, in which case the tag is moved to point to the new revision.
4955
To rename a tag (change the name but keep it on the same revsion), run ``bzr
4956
tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
4959
_see_also = ['commit', 'tags']
4960
takes_args = ['tag_name']
4963
help='Delete this tag rather than placing it.',
4966
help='Branch in which to place the tag.',
4971
help='Replace existing tags.',
4976
def run(self, tag_name,
4982
branch, relpath = Branch.open_containing(directory)
4986
branch.tags.delete_tag(tag_name)
4987
self.outf.write('Deleted tag %s.\n' % tag_name)
4990
if len(revision) != 1:
4991
raise errors.BzrCommandError(
4992
"Tags can only be placed on a single revision, "
4994
revision_id = revision[0].as_revision_id(branch)
4996
revision_id = branch.last_revision()
4997
if (not force) and branch.tags.has_tag(tag_name):
4998
raise errors.TagAlreadyExists(tag_name)
4999
branch.tags.set_tag(tag_name, revision_id)
5000
self.outf.write('Created tag %s.\n' % tag_name)
5005
class cmd_tags(Command):
5008
This command shows a table of tag names and the revisions they reference.
5014
help='Branch whose tags should be displayed.',
5018
RegistryOption.from_kwargs('sort',
5019
'Sort tags by different criteria.', title='Sorting',
5020
alpha='Sort tags lexicographically (default).',
5021
time='Sort tags chronologically.',
5034
branch, relpath = Branch.open_containing(directory)
5036
tags = branch.tags.get_tag_dict().items()
5043
graph = branch.repository.get_graph()
5044
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5045
revid1, revid2 = rev1.rev_id, rev2.rev_id
5046
# only show revisions between revid1 and revid2 (inclusive)
5047
tags = [(tag, revid) for tag, revid in tags if
5048
graph.is_between(revid, revid1, revid2)]
5051
elif sort == 'time':
5053
for tag, revid in tags:
5055
revobj = branch.repository.get_revision(revid)
5056
except errors.NoSuchRevision:
5057
timestamp = sys.maxint # place them at the end
5059
timestamp = revobj.timestamp
5060
timestamps[revid] = timestamp
5061
tags.sort(key=lambda x: timestamps[x[1]])
5063
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5064
for index, (tag, revid) in enumerate(tags):
5066
revno = branch.revision_id_to_dotted_revno(revid)
5067
if isinstance(revno, tuple):
5068
revno = '.'.join(map(str, revno))
5069
except errors.NoSuchRevision:
5070
# Bad tag data/merges can lead to tagged revisions
5071
# which are not in this branch. Fail gracefully ...
5073
tags[index] = (tag, revno)
5076
for tag, revspec in tags:
5077
self.outf.write('%-20s %s\n' % (tag, revspec))
5080
class cmd_reconfigure(Command):
5081
"""Reconfigure the type of a bzr directory.
5083
A target configuration must be specified.
5085
For checkouts, the bind-to location will be auto-detected if not specified.
5086
The order of preference is
5087
1. For a lightweight checkout, the current bound location.
5088
2. For branches that used to be checkouts, the previously-bound location.
5089
3. The push location.
5090
4. The parent location.
5091
If none of these is available, --bind-to must be specified.
5094
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5095
takes_args = ['location?']
5097
RegistryOption.from_kwargs(
5099
title='Target type',
5100
help='The type to reconfigure the directory to.',
5101
value_switches=True, enum_switch=False,
5102
branch='Reconfigure to be an unbound branch with no working tree.',
5103
tree='Reconfigure to be an unbound branch with a working tree.',
5104
checkout='Reconfigure to be a bound branch with a working tree.',
5105
lightweight_checkout='Reconfigure to be a lightweight'
5106
' checkout (with no local history).',
5107
standalone='Reconfigure to be a standalone branch '
5108
'(i.e. stop using shared repository).',
5109
use_shared='Reconfigure to use a shared repository.',
5110
with_trees='Reconfigure repository to create '
5111
'working trees on branches by default.',
5112
with_no_trees='Reconfigure repository to not create '
5113
'working trees on branches by default.'
5115
Option('bind-to', help='Branch to bind checkout to.', type=str),
5117
help='Perform reconfiguration even if local changes'
5121
def run(self, location=None, target_type=None, bind_to=None, force=False):
5122
directory = bzrdir.BzrDir.open(location)
5123
if target_type is None:
5124
raise errors.BzrCommandError('No target configuration specified')
5125
elif target_type == 'branch':
5126
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5127
elif target_type == 'tree':
5128
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5129
elif target_type == 'checkout':
5130
reconfiguration = reconfigure.Reconfigure.to_checkout(
5132
elif target_type == 'lightweight-checkout':
5133
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5135
elif target_type == 'use-shared':
5136
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5137
elif target_type == 'standalone':
5138
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5139
elif target_type == 'with-trees':
5140
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5142
elif target_type == 'with-no-trees':
5143
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5145
reconfiguration.apply(force)
5148
class cmd_switch(Command):
5149
"""Set the branch of a checkout and update.
5151
For lightweight checkouts, this changes the branch being referenced.
5152
For heavyweight checkouts, this checks that there are no local commits
5153
versus the current bound branch, then it makes the local branch a mirror
5154
of the new location and binds to it.
5156
In both cases, the working tree is updated and uncommitted changes
5157
are merged. The user can commit or revert these as they desire.
5159
Pending merges need to be committed or reverted before using switch.
5161
The path to the branch to switch to can be specified relative to the parent
5162
directory of the current branch. For example, if you are currently in a
5163
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5166
Bound branches use the nickname of its master branch unless it is set
5167
locally, in which case switching will update the the local nickname to be
5171
takes_args = ['to_location']
5172
takes_options = [Option('force',
5173
help='Switch even if local commits will be lost.')
5176
def run(self, to_location, force=False):
5177
from bzrlib import switch
5179
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5181
branch = control_dir.open_branch()
5182
had_explicit_nick = branch.get_config().has_explicit_nickname()
5183
except errors.NotBranchError:
5184
had_explicit_nick = False
5186
to_branch = Branch.open(to_location)
5187
except errors.NotBranchError:
5188
this_url = self._get_branch_location(control_dir)
5189
to_branch = Branch.open(
5190
urlutils.join(this_url, '..', to_location))
5191
switch.switch(control_dir, to_branch, force)
5192
if had_explicit_nick:
5193
branch = control_dir.open_branch() #get the new branch!
5194
branch.nick = to_branch.nick
5195
note('Switched to branch: %s',
5196
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5198
def _get_branch_location(self, control_dir):
5199
"""Return location of branch for this control dir."""
5201
this_branch = control_dir.open_branch()
5202
# This may be a heavy checkout, where we want the master branch
5203
master_location = this_branch.get_bound_location()
5204
if master_location is not None:
5205
return master_location
5206
# If not, use a local sibling
5207
return this_branch.base
5208
except errors.NotBranchError:
5209
format = control_dir.find_branch_format()
5210
if getattr(format, 'get_reference', None) is not None:
5211
return format.get_reference(control_dir)
5213
return control_dir.root_transport.base
5216
class cmd_view(Command):
5217
"""Manage filtered views.
5219
Views provide a mask over the tree so that users can focus on
5220
a subset of a tree when doing their work. After creating a view,
5221
commands that support a list of files - status, diff, commit, etc -
5222
effectively have that list of files implicitly given each time.
5223
An explicit list of files can still be given but those files
5224
must be within the current view.
5226
In most cases, a view has a short life-span: it is created to make
5227
a selected change and is deleted once that change is committed.
5228
At other times, you may wish to create one or more named views
5229
and switch between them.
5231
To disable the current view without deleting it, you can switch to
5232
the pseudo view called ``off``. This can be useful when you need
5233
to see the whole tree for an operation or two (e.g. merge) but
5234
want to switch back to your view after that.
5237
To define the current view::
5239
bzr view file1 dir1 ...
5241
To list the current view::
5245
To delete the current view::
5249
To disable the current view without deleting it::
5251
bzr view --switch off
5253
To define a named view and switch to it::
5255
bzr view --name view-name file1 dir1 ...
5257
To list a named view::
5259
bzr view --name view-name
5261
To delete a named view::
5263
bzr view --name view-name --delete
5265
To switch to a named view::
5267
bzr view --switch view-name
5269
To list all views defined::
5273
To delete all views::
5275
bzr view --delete --all
5279
takes_args = ['file*']
5282
help='Apply list or delete action to all views.',
5285
help='Delete the view.',
5288
help='Name of the view to define, list or delete.',
5292
help='Name of the view to switch to.',
5297
def run(self, file_list,
5303
tree, file_list = tree_files(file_list, apply_view=False)
5304
current_view, view_dict = tree.views.get_view_info()
5309
raise errors.BzrCommandError(
5310
"Both --delete and a file list specified")
5312
raise errors.BzrCommandError(
5313
"Both --delete and --switch specified")
5315
tree.views.set_view_info(None, {})
5316
self.outf.write("Deleted all views.\n")
5318
raise errors.BzrCommandError("No current view to delete")
5320
tree.views.delete_view(name)
5321
self.outf.write("Deleted '%s' view.\n" % name)
5324
raise errors.BzrCommandError(
5325
"Both --switch and a file list specified")
5327
raise errors.BzrCommandError(
5328
"Both --switch and --all specified")
5329
elif switch == 'off':
5330
if current_view is None:
5331
raise errors.BzrCommandError("No current view to disable")
5332
tree.views.set_view_info(None, view_dict)
5333
self.outf.write("Disabled '%s' view.\n" % (current_view))
5335
tree.views.set_view_info(switch, view_dict)
5336
view_str = views.view_display_str(tree.views.lookup_view())
5337
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5340
self.outf.write('Views defined:\n')
5341
for view in sorted(view_dict):
5342
if view == current_view:
5346
view_str = views.view_display_str(view_dict[view])
5347
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5349
self.outf.write('No views defined.\n')
5352
# No name given and no current view set
5355
raise errors.BzrCommandError(
5356
"Cannot change the 'off' pseudo view")
5357
tree.views.set_view(name, sorted(file_list))
5358
view_str = views.view_display_str(tree.views.lookup_view())
5359
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5363
# No name given and no current view set
5364
self.outf.write('No current view.\n')
5366
view_str = views.view_display_str(tree.views.lookup_view(name))
5367
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5370
class cmd_hooks(Command):
5376
for hook_key in sorted(hooks.known_hooks.keys()):
5377
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5378
self.outf.write("%s:\n" % type(some_hooks).__name__)
5379
for hook_name, hook_point in sorted(some_hooks.items()):
5380
self.outf.write(" %s:\n" % (hook_name,))
5381
found_hooks = list(hook_point)
5383
for hook in found_hooks:
5384
self.outf.write(" %s\n" %
5385
(some_hooks.get_hook_name(hook),))
5387
self.outf.write(" <no hooks installed>\n")
5390
class cmd_shelve(Command):
5391
"""Temporarily set aside some changes from the current tree.
5393
Shelve allows you to temporarily put changes you've made "on the shelf",
5394
ie. out of the way, until a later time when you can bring them back from
5395
the shelf with the 'unshelve' command. The changes are stored alongside
5396
your working tree, and so they aren't propagated along with your branch nor
5397
will they survive its deletion.
5399
If shelve --list is specified, previously-shelved changes are listed.
5401
Shelve is intended to help separate several sets of changes that have
5402
been inappropriately mingled. If you just want to get rid of all changes
5403
and you don't need to restore them later, use revert. If you want to
5404
shelve all text changes at once, use shelve --all.
5406
If filenames are specified, only the changes to those files will be
5407
shelved. Other files will be left untouched.
5409
If a revision is specified, changes since that revision will be shelved.
5411
You can put multiple items on the shelf, and by default, 'unshelve' will
5412
restore the most recently shelved changes.
5415
takes_args = ['file*']
5419
Option('all', help='Shelve all changes.'),
5421
RegistryOption('writer', 'Method to use for writing diffs.',
5422
bzrlib.option.diff_writer_registry,
5423
value_switches=True, enum_switch=False),
5425
Option('list', help='List shelved changes.'),
5427
help='Destroy removed changes instead of shelving them.'),
5429
_see_also = ['unshelve']
5431
def run(self, revision=None, all=False, file_list=None, message=None,
5432
writer=None, list=False, destroy=False):
5434
return self.run_for_list()
5435
from bzrlib.shelf_ui import Shelver
5437
writer = bzrlib.option.diff_writer_registry.get()
5439
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5440
message, destroy=destroy).run()
5441
except errors.UserAbort:
3088
if file_list is None:
3089
if pull and merger.base_rev_id == merger.this_rev_id:
3090
count = merger.this_tree.pull(merger.this_branch,
3091
False, merger.other_rev_id)
3092
note('%d revision(s) pulled.' % (count,))
5444
def run_for_list(self):
5445
tree = WorkingTree.open_containing('.')[0]
5448
manager = tree.get_shelf_manager()
5449
shelves = manager.active_shelves()
5450
if len(shelves) == 0:
5451
note('No shelved changes.')
3094
merger.backup_files = backup_files
3095
merger.merge_type = merge_type
3096
merger.set_interesting_files(file_list)
3097
merger.show_base = show_base
3098
merger.reprocess = reprocess
3099
conflicts = merger.do_merge()
3100
if file_list is None:
3101
merger.set_pending()
3108
merge = _merge_helper
5453
for shelf_id in reversed(shelves):
5454
message = manager.get_metadata(shelf_id).get('message')
5456
message = '<no message>'
5457
self.outf.write('%3d: %s\n' % (shelf_id, message))
5463
class cmd_unshelve(Command):
5464
"""Restore shelved changes.
5466
By default, the most recently shelved changes are restored. However if you
5467
specify a shelf by id those changes will be restored instead. This works
5468
best when the changes don't depend on each other.
5471
takes_args = ['shelf_id?']
5473
RegistryOption.from_kwargs(
5474
'action', help="The action to perform.",
5475
enum_switch=False, value_switches=True,
5476
apply="Apply changes and remove from the shelf.",
5477
dry_run="Show changes, but do not apply or remove them.",
5478
delete_only="Delete changes without applying them."
5481
_see_also = ['shelve']
5483
def run(self, shelf_id=None, action='apply'):
5484
from bzrlib.shelf_ui import Unshelver
5485
Unshelver.from_args(shelf_id, action).run()
5488
class cmd_clean_tree(Command):
5489
"""Remove unwanted files from working tree.
5491
By default, only unknown files, not ignored files, are deleted. Versioned
5492
files are never deleted.
5494
Another class is 'detritus', which includes files emitted by bzr during
5495
normal operations and selftests. (The value of these files decreases with
5498
If no options are specified, unknown files are deleted. Otherwise, option
5499
flags are respected, and may be combined.
5501
To check what clean-tree will do, use --dry-run.
5503
takes_options = [Option('ignored', help='Delete all ignored files.'),
5504
Option('detritus', help='Delete conflict files, merge'
5505
' backups, and failed selftest dirs.'),
5507
help='Delete files unknown to bzr (default).'),
5508
Option('dry-run', help='Show files to delete instead of'
5510
Option('force', help='Do not prompt before deleting.')]
5511
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5513
from bzrlib.clean_tree import clean_tree
5514
if not (unknown or ignored or detritus):
5518
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5519
dry_run=dry_run, no_prompt=force)
5522
class cmd_reference(Command):
5523
"""list, view and set branch locations for nested trees.
5525
If no arguments are provided, lists the branch locations for nested trees.
5526
If one argument is provided, display the branch location for that tree.
5527
If two arguments are provided, set the branch location for that tree.
5532
takes_args = ['path?', 'location?']
5534
def run(self, path=None, location=None):
5536
if path is not None:
5538
tree, branch, relpath =(
5539
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5540
if path is not None:
5543
tree = branch.basis_tree()
5545
info = branch._get_all_reference_info().iteritems()
5546
self._display_reference_info(tree, branch, info)
5548
file_id = tree.path2id(path)
5550
raise errors.NotVersionedError(path)
5551
if location is None:
5552
info = [(file_id, branch.get_reference_info(file_id))]
5553
self._display_reference_info(tree, branch, info)
5555
branch.set_reference_info(file_id, path, location)
5557
def _display_reference_info(self, tree, branch, info):
5559
for file_id, (path, location) in info:
5561
path = tree.id2path(file_id)
5562
except errors.NoSuchId:
5564
ref_list.append((path, location))
5565
for path, location in sorted(ref_list):
5566
self.outf.write('%s %s\n' % (path, location))
3111
5569
# these get imported and then picked up by the scan for cmd_*
3112
5570
# TODO: Some more consistent way to split command definitions across files;
3113
# we do need to load at least some information about them to know of
5571
# we do need to load at least some information about them to know of
3114
5572
# aliases. ideally we would avoid loading the implementation until the
3115
5573
# details were needed.
3116
5574
from bzrlib.cmd_version_info import cmd_version_info
3117
5575
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3118
from bzrlib.bundle.commands import cmd_bundle_revisions
5576
from bzrlib.bundle.commands import (
5579
from bzrlib.foreign import cmd_dpush
3119
5580
from bzrlib.sign_my_commits import cmd_sign_my_commits
3120
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
5581
from bzrlib.weave_commands import cmd_versionedfile_list, \
3121
5582
cmd_weave_plan_merge, cmd_weave_merge_text