648
1057
location can be accessed.
651
takes_options = ['remember', 'overwrite', 'verbose',
1060
_see_also = ['pull', 'update', 'working-trees']
1061
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
652
1062
Option('create-prefix',
653
1063
help='Create the path leading up to the branch '
654
'if it does not already exist'),
1064
'if it does not already exist.'),
655
1065
Option('directory',
656
help='branch to push from, '
657
'rather than the one containing the working directory',
1066
help='Branch to push from, '
1067
'rather than the one containing the working directory.',
661
1071
Option('use-existing-dir',
662
1072
help='By default push will fail if the target'
663
1073
' directory exists, but does not already'
664
' have a control directory. This flag will'
1074
' have a control directory. This flag will'
665
1075
' allow push to proceed.'),
1077
help='Create a stacked branch that references the public location '
1078
'of the parent branch.'),
1079
Option('stacked-on',
1080
help='Create a stacked branch that refers to another branch '
1081
'for the commit history. Only the work not present in the '
1082
'referenced branch is included in the branch created.',
1085
help='Refuse to push if there are uncommitted changes in'
1086
' the working tree, --no-strict disables the check.'),
667
1088
takes_args = ['location?']
668
1089
encoding_type = 'replace'
670
1091
def run(self, location=None, remember=False, overwrite=False,
671
create_prefix=False, verbose=False,
672
use_existing_dir=False,
674
# FIXME: Way too big! Put this into a function called from the
1092
create_prefix=False, verbose=False, revision=None,
1093
use_existing_dir=False, directory=None, stacked_on=None,
1094
stacked=False, strict=None):
1095
from bzrlib.push import _show_push_branch
676
1097
if directory is None:
678
br_from = Branch.open_containing(directory)[0]
679
stored_loc = br_from.get_push_location()
1099
# Get the source branch
1101
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1103
strict = br_from.get_config().get_user_option_as_bool('push_strict')
1104
if strict is None: strict = True # default value
1105
# Get the tip's revision_id
1106
revision = _get_one_revision('push', revision)
1107
if revision is not None:
1108
revision_id = revision.in_history(br_from).rev_id
1111
if strict and tree is not None and revision_id is None:
1112
if (tree.has_changes(tree.basis_tree())
1113
or len(tree.get_parent_ids()) > 1):
1114
raise errors.UncommittedChanges(
1115
tree, more='Use --no-strict to force the push.')
1116
if tree.last_revision() != tree.branch.last_revision():
1117
# The tree has lost sync with its branch, there is little
1118
# chance that the user is aware of it but he can still force
1119
# the push with --no-strict
1120
raise errors.OutOfDateTree(
1121
tree, more='Use --no-strict to force the push.')
1123
# Get the stacked_on branch, if any
1124
if stacked_on is not None:
1125
stacked_on = urlutils.normalize_url(stacked_on)
1127
parent_url = br_from.get_parent()
1129
parent = Branch.open(parent_url)
1130
stacked_on = parent.get_public_branch()
1132
# I considered excluding non-http url's here, thus forcing
1133
# 'public' branches only, but that only works for some
1134
# users, so it's best to just depend on the user spotting an
1135
# error by the feedback given to them. RBC 20080227.
1136
stacked_on = parent_url
1138
raise errors.BzrCommandError(
1139
"Could not determine branch to refer to.")
1141
# Get the destination location
680
1142
if location is None:
1143
stored_loc = br_from.get_push_location()
681
1144
if stored_loc is None:
682
raise errors.BzrCommandError("No push location known or specified.")
1145
raise errors.BzrCommandError(
1146
"No push location known or specified.")
684
1148
display_url = urlutils.unescape_for_display(stored_loc,
685
1149
self.outf.encoding)
686
self.outf.write("Using saved location: %s\n" % display_url)
1150
self.outf.write("Using saved push location: %s\n" % display_url)
687
1151
location = stored_loc
689
to_transport = transport.get_transport(location)
690
location_url = to_transport.base
695
br_to = repository_to = dir_to = None
697
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
698
except errors.NotBranchError:
699
pass # Didn't find anything
701
# If we can open a branch, use its direct repository, otherwise see
702
# if there is a repository without a branch.
704
br_to = dir_to.open_branch()
705
except errors.NotBranchError:
706
# Didn't find a branch, can we find a repository?
708
repository_to = dir_to.find_repository()
709
except errors.NoRepositoryPresent:
712
# Found a branch, so we must have found a repository
713
repository_to = br_to.repository
717
# XXX: Refactor the create_prefix/no_create_prefix code into a
718
# common helper function
720
to_transport.mkdir('.')
721
except errors.FileExists:
722
if not use_existing_dir:
723
raise errors.BzrCommandError("Target directory %s"
724
" already exists, but does not have a valid .bzr"
725
" directory. Supply --use-existing-dir to push"
726
" there anyway." % location)
727
except errors.NoSuchFile:
728
if not create_prefix:
729
raise errors.BzrCommandError("Parent directory of %s"
731
"\nYou may supply --create-prefix to create all"
732
" leading parent directories."
735
cur_transport = to_transport
736
needed = [cur_transport]
737
# Recurse upwards until we can create a directory successfully
739
new_transport = cur_transport.clone('..')
740
if new_transport.base == cur_transport.base:
741
raise errors.BzrCommandError("Failed to create path"
745
new_transport.mkdir('.')
746
except errors.NoSuchFile:
747
needed.append(new_transport)
748
cur_transport = new_transport
752
# Now we only need to create child directories
754
cur_transport = needed.pop()
755
cur_transport.mkdir('.')
757
# Now the target directory exists, but doesn't have a .bzr
758
# directory. So we need to create it, along with any work to create
759
# all of the dependent branches, etc.
760
dir_to = br_from.bzrdir.clone(location_url,
761
revision_id=br_from.last_revision())
762
br_to = dir_to.open_branch()
763
count = br_to.last_revision_info()[0]
764
# We successfully created the target, remember it
765
if br_from.get_push_location() is None or remember:
766
br_from.set_push_location(br_to.base)
767
elif repository_to is None:
768
# we have a bzrdir but no branch or repository
769
# XXX: Figure out what to do other than complain.
770
raise errors.BzrCommandError("At %s you have a valid .bzr control"
771
" directory, but not a branch or repository. This is an"
772
" unsupported configuration. Please move the target directory"
773
" out of the way and try again."
776
# We have a repository but no branch, copy the revisions, and then
778
last_revision_id = br_from.last_revision()
779
repository_to.fetch(br_from.repository,
780
revision_id=last_revision_id)
781
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
782
count = len(br_to.revision_history())
783
if br_from.get_push_location() is None or remember:
784
br_from.set_push_location(br_to.base)
785
else: # We have a valid to branch
786
# We were able to connect to the remote location, so remember it
787
# we don't need to successfully push because of possible divergence.
788
if br_from.get_push_location() is None or remember:
789
br_from.set_push_location(br_to.base)
790
old_rh = br_to.revision_history()
793
tree_to = dir_to.open_workingtree()
794
except errors.NotLocalUrl:
795
warning('This transport does not update the working '
796
'tree of: %s' % (br_to.base,))
797
count = br_from.push(br_to, overwrite)
798
except errors.NoWorkingTree:
799
count = br_from.push(br_to, overwrite)
803
count = br_from.push(tree_to.branch, overwrite)
807
except errors.DivergedBranches:
808
raise errors.BzrCommandError('These branches have diverged.'
809
' Try using "merge" and then "push".')
810
note('%d revision(s) pushed.' % (count,))
813
new_rh = br_to.revision_history()
816
from bzrlib.log import show_changed_revisions
817
show_changed_revisions(br_to, old_rh, new_rh,
1153
_show_push_branch(br_from, revision_id, location, self.outf,
1154
verbose=verbose, overwrite=overwrite, remember=remember,
1155
stacked_on=stacked_on, create_prefix=create_prefix,
1156
use_existing_dir=use_existing_dir)
821
1159
class cmd_branch(Command):
822
"""Create a new copy of a branch.
1160
"""Create a new branch that is a copy of an existing branch.
824
1162
If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
825
1163
be used. In other words, "branch ../foo/bar" will attempt to create ./bar.
1164
If the FROM_LOCATION has no / or path separator embedded, the TO_LOCATION
1165
is derived from the FROM_LOCATION by stripping a leading scheme or drive
1166
identifier, if any. For example, "branch lp:foo-bar" will attempt to
827
1169
To retrieve the branch as of a particular revision, supply the --revision
828
1170
parameter, as in "branch foo/bar -r 5".
830
--basis is to speed up branching from remote branches. When specified, it
831
copies all the file-contents, inventory and revision data from the basis
832
branch before copying anything from the remote branch.
1173
_see_also = ['checkout']
834
1174
takes_args = ['from_location', 'to_location?']
835
takes_options = ['revision', 'basis']
1175
takes_options = ['revision', Option('hardlink',
1176
help='Hard-link working tree files where possible.'),
1178
help="Create a branch without a working-tree."),
1180
help="Switch the checkout in the current directory "
1181
"to the new branch."),
1183
help='Create a stacked branch referring to the source branch. '
1184
'The new branch will depend on the availability of the source '
1185
'branch for all operations.'),
1186
Option('standalone',
1187
help='Do not use a shared repository, even if available.'),
1188
Option('use-existing-dir',
1189
help='By default branch will fail if the target'
1190
' directory exists, but does not already'
1191
' have a control directory. This flag will'
1192
' allow branch to proceed.'),
836
1194
aliases = ['get', 'clone']
838
def run(self, from_location, to_location=None, revision=None, basis=None):
841
elif len(revision) > 1:
842
raise errors.BzrCommandError(
843
'bzr branch --revision takes exactly 1 revision value')
845
br_from = Branch.open(from_location)
1196
def run(self, from_location, to_location=None, revision=None,
1197
hardlink=False, stacked=False, standalone=False, no_tree=False,
1198
use_existing_dir=False, switch=False):
1199
from bzrlib import switch as _mod_switch
1200
from bzrlib.tag import _merge_tags_if_possible
1201
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1203
if (accelerator_tree is not None and
1204
accelerator_tree.supports_content_filtering()):
1205
accelerator_tree = None
1206
revision = _get_one_revision('branch', revision)
846
1207
br_from.lock_read()
848
if basis is not None:
849
basis_dir = bzrdir.BzrDir.open_containing(basis)[0]
852
if len(revision) == 1 and revision[0] is not None:
853
revision_id = revision[0].in_history(br_from)[1]
1209
if revision is not None:
1210
revision_id = revision.as_revision_id(br_from)
855
1212
# FIXME - wt.last_revision, fallback to branch, fall back to
856
1213
# None or perhaps NULL_REVISION to mean copy nothing
858
1215
revision_id = br_from.last_revision()
859
1216
if to_location is None:
860
to_location = os.path.basename(from_location.rstrip("/\\"))
863
name = os.path.basename(to_location) + '\n'
1217
to_location = urlutils.derive_to_location(from_location)
865
1218
to_transport = transport.get_transport(to_location)
867
1220
to_transport.mkdir('.')
868
1221
except errors.FileExists:
869
raise errors.BzrCommandError('Target directory "%s" already'
870
' exists.' % to_location)
1222
if not use_existing_dir:
1223
raise errors.BzrCommandError('Target directory "%s" '
1224
'already exists.' % to_location)
1227
bzrdir.BzrDir.open_from_transport(to_transport)
1228
except errors.NotBranchError:
1231
raise errors.AlreadyBranchError(to_location)
871
1232
except errors.NoSuchFile:
872
1233
raise errors.BzrCommandError('Parent of "%s" does not exist.'
875
1236
# preserve whatever source format we have.
876
dir = br_from.bzrdir.sprout(to_transport.base,
877
revision_id, basis_dir)
1237
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1238
possible_transports=[to_transport],
1239
accelerator_tree=accelerator_tree,
1240
hardlink=hardlink, stacked=stacked,
1241
force_new_repo=standalone,
1242
create_tree_if_local=not no_tree,
1243
source_branch=br_from)
878
1244
branch = dir.open_branch()
879
1245
except errors.NoSuchRevision:
880
1246
to_transport.delete_tree('.')
881
msg = "The branch %s has no revision %s." % (from_location, revision[0])
882
raise errors.BzrCommandError(msg)
883
except errors.UnlistableBranch:
884
osutils.rmtree(to_location)
885
msg = "The branch %s cannot be used as a --basis" % (basis,)
886
raise errors.BzrCommandError(msg)
888
branch.control_files.put_utf8('branch-name', name)
889
note('Branched %d revision(s).' % branch.revno())
1247
msg = "The branch %s has no revision %s." % (from_location,
1249
raise errors.BzrCommandError(msg)
1250
_merge_tags_if_possible(br_from, branch)
1251
# If the source branch is stacked, the new branch may
1252
# be stacked whether we asked for that explicitly or not.
1253
# We therefore need a try/except here and not just 'if stacked:'
1255
note('Created new stacked branch referring to %s.' %
1256
branch.get_stacked_on_url())
1257
except (errors.NotStacked, errors.UnstackableBranchFormat,
1258
errors.UnstackableRepositoryFormat), e:
1259
note('Branched %d revision(s).' % branch.revno())
1261
# Switch to the new branch
1262
wt, _ = WorkingTree.open_containing('.')
1263
_mod_switch.switch(wt.bzrdir, branch)
1264
note('Switched to branch: %s',
1265
urlutils.unescape_for_display(branch.base, 'utf-8'))
891
1267
br_from.unlock()
1493
2027
self.outf.write(tree.basedir + '\n')
2030
def _parse_limit(limitstring):
2032
return int(limitstring)
2034
msg = "The limit argument must be an integer."
2035
raise errors.BzrCommandError(msg)
2038
def _parse_levels(s):
2042
msg = "The levels argument must be an integer."
2043
raise errors.BzrCommandError(msg)
1496
2046
class cmd_log(Command):
1497
"""Show log of a branch, file, or directory.
1499
By default show the log of the branch containing the working directory.
1501
To request a range of logs, you can use the command -r begin..end
1502
-r revision requests a specific revision, -r ..end or -r begin.. are
1508
bzr log -r -10.. http://server/branch
2047
"""Show historical log for a branch or subset of a branch.
2049
log is bzr's default tool for exploring the history of a branch.
2050
The branch to use is taken from the first parameter. If no parameters
2051
are given, the branch containing the working directory is logged.
2052
Here are some simple examples::
2054
bzr log log the current branch
2055
bzr log foo.py log a file in its branch
2056
bzr log http://server/branch log a branch on a server
2058
The filtering, ordering and information shown for each revision can
2059
be controlled as explained below. By default, all revisions are
2060
shown sorted (topologically) so that newer revisions appear before
2061
older ones and descendants always appear before ancestors. If displayed,
2062
merged revisions are shown indented under the revision in which they
2067
The log format controls how information about each revision is
2068
displayed. The standard log formats are called ``long``, ``short``
2069
and ``line``. The default is long. See ``bzr help log-formats``
2070
for more details on log formats.
2072
The following options can be used to control what information is
2075
-l N display a maximum of N revisions
2076
-n N display N levels of revisions (0 for all, 1 for collapsed)
2077
-v display a status summary (delta) for each revision
2078
-p display a diff (patch) for each revision
2079
--show-ids display revision-ids (and file-ids), not just revnos
2081
Note that the default number of levels to display is a function of the
2082
log format. If the -n option is not used, the standard log formats show
2083
just the top level (mainline).
2085
Status summaries are shown using status flags like A, M, etc. To see
2086
the changes explained using words like ``added`` and ``modified``
2087
instead, use the -vv option.
2091
To display revisions from oldest to newest, use the --forward option.
2092
In most cases, using this option will have little impact on the total
2093
time taken to produce a log, though --forward does not incrementally
2094
display revisions like --reverse does when it can.
2096
:Revision filtering:
2098
The -r option can be used to specify what revision or range of revisions
2099
to filter against. The various forms are shown below::
2101
-rX display revision X
2102
-rX.. display revision X and later
2103
-r..Y display up to and including revision Y
2104
-rX..Y display from X to Y inclusive
2106
See ``bzr help revisionspec`` for details on how to specify X and Y.
2107
Some common examples are given below::
2109
-r-1 show just the tip
2110
-r-10.. show the last 10 mainline revisions
2111
-rsubmit:.. show what's new on this branch
2112
-rancestor:path.. show changes since the common ancestor of this
2113
branch and the one at location path
2114
-rdate:yesterday.. show changes since yesterday
2116
When logging a range of revisions using -rX..Y, log starts at
2117
revision Y and searches back in history through the primary
2118
("left-hand") parents until it finds X. When logging just the
2119
top level (using -n1), an error is reported if X is not found
2120
along the way. If multi-level logging is used (-n0), X may be
2121
a nested merge revision and the log will be truncated accordingly.
2125
If parameters are given and the first one is not a branch, the log
2126
will be filtered to show only those revisions that changed the
2127
nominated files or directories.
2129
Filenames are interpreted within their historical context. To log a
2130
deleted file, specify a revision range so that the file existed at
2131
the end or start of the range.
2133
Historical context is also important when interpreting pathnames of
2134
renamed files/directories. Consider the following example:
2136
* revision 1: add tutorial.txt
2137
* revision 2: modify tutorial.txt
2138
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
2142
* ``bzr log guide.txt`` will log the file added in revision 1
2144
* ``bzr log tutorial.txt`` will log the new file added in revision 3
2146
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2147
the original file in revision 2.
2149
* ``bzr log -r2 -p guide.txt`` will display an error message as there
2150
was no file called guide.txt in revision 2.
2152
Renames are always followed by log. By design, there is no need to
2153
explicitly ask for this (and no way to stop logging a file back
2154
until it was last renamed).
2158
The --message option can be used for finding revisions that match a
2159
regular expression in a commit message.
2163
GUI tools and IDEs are often better at exploring history than command
2164
line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
2165
respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2166
http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2168
Web interfaces are often better at exploring history than command line
2169
tools, particularly for branches on servers. You may prefer Loggerhead
2170
or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
2172
You may find it useful to add the aliases below to ``bazaar.conf``::
2176
top = log -l10 --line
2179
``bzr tip`` will then show the latest revision while ``bzr top``
2180
will show the last 10 mainline revisions. To see the details of a
2181
particular revision X, ``bzr show -rX``.
2183
If you are interested in looking deeper into a particular merge X,
2184
use ``bzr log -n0 -rX``.
2186
``bzr log -v`` on a branch with lots of history is currently
2187
very slow. A fix for this issue is currently under development.
2188
With or without that fix, it is recommended that a revision range
2189
be given when using the -v option.
2191
bzr has a generic full-text matching plugin, bzr-search, that can be
2192
used to find revisions matching user names, commit messages, etc.
2193
Among other features, this plugin can find all revisions containing
2194
a list of words but not others.
2196
When exploring non-mainline history on large projects with deep
2197
history, the performance of log can be greatly improved by installing
2198
the historycache plugin. This plugin buffers historical information
2199
trading disk space for faster speed.
1511
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1513
takes_args = ['location?']
1514
takes_options = [Option('forward',
1515
help='show from oldest to newest'),
1519
help='show files changed in each revision'),
1520
'show-ids', 'revision',
1524
help='show revisions whose message matches this regexp',
2201
takes_args = ['file*']
2202
_see_also = ['log-formats', 'revisionspec']
2205
help='Show from oldest to newest.'),
2207
custom_help('verbose',
2208
help='Show files changed in each revision.'),
2212
type=bzrlib.option._parse_revision_str,
2214
help='Show just the specified revision.'
2215
' See also "help revisionspec".'),
2219
help='Number of levels to display - 0 for all, 1 for flat.',
2221
type=_parse_levels),
2224
help='Show revisions whose message matches this '
2225
'regular expression.',
2229
help='Limit the output to the first N revisions.',
2234
help='Show changes made in each revision as a patch.'),
2235
Option('include-merges',
2236
help='Show merged revisions like --levels 0 does.'),
1527
2238
encoding_type = 'replace'
1529
2240
@display_command
1530
def run(self, location=None, timezone='original',
2241
def run(self, file_list=None, timezone='original',
1532
2243
show_ids=False,
1535
2247
log_format=None,
1537
from bzrlib.log import show_log
1538
assert message is None or isinstance(message, basestring), \
1539
"invalid message argument %r" % message
2252
include_merges=False):
2253
from bzrlib.log import (
2255
make_log_request_dict,
2256
_get_info_for_log_files,
1540
2258
direction = (forward and 'forward') or 'reverse'
1545
# find the file id to log:
1547
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
1551
tree = b.basis_tree()
1552
file_id = tree.path2id(fp)
1554
raise errors.BzrCommandError(
1555
"Path does not have any revision history: %s" %
1559
# FIXME ? log the current subdir only RBC 20060203
1560
if revision is not None \
1561
and len(revision) > 0 and revision[0].get_branch():
1562
location = revision[0].get_branch()
1565
dir, relpath = bzrdir.BzrDir.open_containing(location)
1566
b = dir.open_branch()
2263
raise errors.BzrCommandError(
2264
'--levels and --include-merges are mutually exclusive')
2266
if change is not None:
2268
raise errors.RangeInChangeOption()
2269
if revision is not None:
2270
raise errors.BzrCommandError(
2271
'--revision and --change are mutually exclusive')
2276
filter_by_dir = False
1570
if revision is None:
1573
elif len(revision) == 1:
1574
rev1 = rev2 = revision[0].in_history(b).revno
1575
elif len(revision) == 2:
1576
if revision[1].get_branch() != revision[0].get_branch():
1577
# b is taken from revision[0].get_branch(), and
1578
# show_log will use its revision_history. Having
1579
# different branches will lead to weird behaviors.
1580
raise errors.BzrCommandError(
1581
"Log doesn't accept two revisions in different"
1583
if revision[0].spec is None:
1584
# missing begin-range means first revision
1587
rev1 = revision[0].in_history(b).revno
1589
if revision[1].spec is None:
1590
# missing end-range means last known revision
1593
rev2 = revision[1].in_history(b).revno
1595
raise errors.BzrCommandError(
1596
'bzr log --revision takes one or two values.')
1598
# By this point, the revision numbers are converted to the +ve
1599
# form if they were supplied in the -ve form, so we can do
1600
# this comparison in relative safety
1602
(rev2, rev1) = (rev1, rev2)
2280
# find the file ids to log and check for directory filtering
2281
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2282
revision, file_list)
2283
for relpath, file_id, kind in file_info_list:
2285
raise errors.BzrCommandError(
2286
"Path unknown at end or start of revision range: %s" %
2288
# If the relpath is the top of the tree, we log everything
2293
file_ids.append(file_id)
2294
filter_by_dir = filter_by_dir or (
2295
kind in ['directory', 'tree-reference'])
2298
# FIXME ? log the current subdir only RBC 20060203
2299
if revision is not None \
2300
and len(revision) > 0 and revision[0].get_branch():
2301
location = revision[0].get_branch()
2304
dir, relpath = bzrdir.BzrDir.open_containing(location)
2305
b = dir.open_branch()
2307
rev1, rev2 = _get_revision_range(revision, b, self.name())
2309
# Decide on the type of delta & diff filtering to use
2310
# TODO: add an --all-files option to make this configurable & consistent
2318
diff_type = 'partial'
2322
# Build the log formatter
1604
2323
if log_format is None:
1605
2324
log_format = log.log_formatter_registry.get_default(b)
1607
2325
lf = log_format(show_ids=show_ids, to_file=self.outf,
1608
show_timezone=timezone)
1614
direction=direction,
1615
start_revision=rev1,
2326
show_timezone=timezone,
2327
delta_format=get_verbosity_level(),
2329
show_advice=levels is None)
2331
# Choose the algorithm for doing the logging. It's annoying
2332
# having multiple code paths like this but necessary until
2333
# the underlying repository format is faster at generating
2334
# deltas or can provide everything we need from the indices.
2335
# The default algorithm - match-using-deltas - works for
2336
# multiple files and directories and is faster for small
2337
# amounts of history (200 revisions say). However, it's too
2338
# slow for logging a single file in a repository with deep
2339
# history, i.e. > 10K revisions. In the spirit of "do no
2340
# evil when adding features", we continue to use the
2341
# original algorithm - per-file-graph - for the "single
2342
# file that isn't a directory without showing a delta" case.
2343
partial_history = revision and b.repository._format.supports_chks
2344
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2345
or delta_type or partial_history)
2347
# Build the LogRequest and execute it
2348
if len(file_ids) == 0:
2350
rqst = make_log_request_dict(
2351
direction=direction, specific_fileids=file_ids,
2352
start_revision=rev1, end_revision=rev2, limit=limit,
2353
message_search=message, delta_type=delta_type,
2354
diff_type=diff_type, _match_using_deltas=match_using_deltas)
2355
Logger(b, rqst).show(lf)
2361
def _get_revision_range(revisionspec_list, branch, command_name):
2362
"""Take the input of a revision option and turn it into a revision range.
2364
It returns RevisionInfo objects which can be used to obtain the rev_id's
2365
of the desired revisions. It does some user input validations.
2367
if revisionspec_list is None:
2370
elif len(revisionspec_list) == 1:
2371
rev1 = rev2 = revisionspec_list[0].in_history(branch)
2372
elif len(revisionspec_list) == 2:
2373
start_spec = revisionspec_list[0]
2374
end_spec = revisionspec_list[1]
2375
if end_spec.get_branch() != start_spec.get_branch():
2376
# b is taken from revision[0].get_branch(), and
2377
# show_log will use its revision_history. Having
2378
# different branches will lead to weird behaviors.
2379
raise errors.BzrCommandError(
2380
"bzr %s doesn't accept two revisions in different"
2381
" branches." % command_name)
2382
rev1 = start_spec.in_history(branch)
2383
# Avoid loading all of history when we know a missing
2384
# end of range means the last revision ...
2385
if end_spec.spec is None:
2386
last_revno, last_revision_id = branch.last_revision_info()
2387
rev2 = RevisionInfo(branch, last_revno, last_revision_id)
2389
rev2 = end_spec.in_history(branch)
2391
raise errors.BzrCommandError(
2392
'bzr %s --revision takes one or two values.' % command_name)
2396
def _revision_range_to_revid_range(revision_range):
2399
if revision_range[0] is not None:
2400
rev_id1 = revision_range[0].rev_id
2401
if revision_range[1] is not None:
2402
rev_id2 = revision_range[1].rev_id
2403
return rev_id1, rev_id2
1622
2405
def get_log_format(long=False, short=False, line=False, default='long'):
1623
2406
log_format = default
2402
3585
directory, where they can be reviewed (with bzr diff), tested, and then
2403
3586
committed to record the result of the merge.
2407
To merge the latest revision from bzr.dev
2408
bzr merge ../bzr.dev
2410
To merge changes up to and including revision 82 from bzr.dev
2411
bzr merge -r 82 ../bzr.dev
2413
To merge the changes introduced by 82, without previous changes:
2414
bzr merge -r 81..82 ../bzr.dev
2416
3588
merge refuses to run if there are any uncommitted changes, unless
2417
3589
--force is given.
2419
The following merge types are available:
3591
To select only some changes to merge, use "merge -i", which will prompt
3592
you to apply each diff hunk and file change, similar to "shelve".
3595
To merge the latest revision from bzr.dev::
3597
bzr merge ../bzr.dev
3599
To merge changes up to and including revision 82 from bzr.dev::
3601
bzr merge -r 82 ../bzr.dev
3603
To merge the changes introduced by 82, without previous changes::
3605
bzr merge -r 81..82 ../bzr.dev
3607
To apply a merge directive contained in /tmp/merge:
3609
bzr merge /tmp/merge
2421
takes_args = ['branch?']
2422
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
3612
encoding_type = 'exact'
3613
_see_also = ['update', 'remerge', 'status-flags', 'send']
3614
takes_args = ['location?']
3619
help='Merge even if the destination tree has uncommitted changes.'),
2423
3623
Option('show-base', help="Show base revision text in "
2425
3625
Option('uncommitted', help='Apply uncommitted changes'
2426
' from a working copy, instead of branch changes'),
3626
' from a working copy, instead of branch changes.'),
2427
3627
Option('pull', help='If the destination is already'
2428
3628
' completely merged into the source, pull from the'
2429
' source rather than merging. When this happens,'
3629
' source rather than merging. When this happens,'
2430
3630
' you do not need to commit the result.'),
2431
3631
Option('directory',
2432
help='branch to merge into, '
2433
'rather than the one containing the working directory',
3632
help='Branch to merge into, '
3633
'rather than the one containing the working directory.',
3637
Option('preview', help='Instead of merging, show a diff of the'
3639
Option('interactive', help='Select changes interactively.',
2439
def run(self, branch=None, revision=None, force=False, merge_type=None,
2440
show_base=False, reprocess=False, remember=False,
3643
def run(self, location=None, revision=None, force=False,
3644
merge_type=None, show_base=False, reprocess=None, remember=False,
2441
3645
uncommitted=False, pull=False,
2442
3646
directory=None,
2444
3650
if merge_type is None:
2445
3651
merge_type = _mod_merge.Merge3Merger
2447
3653
if directory is None: directory = u'.'
2448
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2449
# inventory. Because merge is a mutating operation, it really
2450
# should be a lock_write() for the whole cmd_merge operation.
2451
# However, cmd_merge open's its own tree in _merge_helper, which
2452
# means if we lock here, the later lock_write() will always block.
2453
# Either the merge helper code should be updated to take a tree,
2454
# or the ChangeReporter should be updated to not require an
2455
# inventory. (What about tree.merge_from_branch?)
3654
possible_transports = []
3656
allow_pending = True
3657
verified = 'inapplicable'
2456
3658
tree = WorkingTree.open_containing(directory)[0]
2459
change_reporter = delta.ChangeReporter(tree.inventory)
2463
if branch is not None:
2465
reader = bundle.read_bundle_from_url(branch)
2466
except errors.NotABundle:
2467
pass # Continue on considering this url a Branch
2469
conflicts = merge_bundle(reader, tree, not force, merge_type,
2470
reprocess, show_base, change_reporter)
3660
# die as quickly as possible if there are uncommitted changes
3662
basis_tree = tree.revision_tree(tree.last_revision())
3663
except errors.NoSuchRevision:
3664
basis_tree = tree.basis_tree()
3666
if tree.has_changes(basis_tree):
3667
raise errors.UncommittedChanges(tree)
3669
view_info = _get_view_info_for_change_reporter(tree)
3670
change_reporter = delta._ChangeReporter(
3671
unversioned_filter=tree.is_ignored, view_info=view_info)
3674
pb = ui.ui_factory.nested_progress_bar()
3675
cleanups.append(pb.finished)
3677
cleanups.append(tree.unlock)
3678
if location is not None:
3680
mergeable = bundle.read_mergeable_from_url(location,
3681
possible_transports=possible_transports)
3682
except errors.NotABundle:
2476
if revision is None \
2477
or len(revision) < 1 or revision[0].needs_branch():
2478
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2480
if revision is None or len(revision) < 1:
2483
other = [branch, None]
2486
other = [branch, -1]
2487
other_branch, path = Branch.open_containing(branch)
2490
raise errors.BzrCommandError('Cannot use --uncommitted and'
2491
' --revision at the same time.')
2492
branch = revision[0].get_branch() or branch
2493
if len(revision) == 1:
2495
other_branch, path = Branch.open_containing(branch)
2496
revno = revision[0].in_history(other_branch).revno
2497
other = [branch, revno]
2499
assert len(revision) == 2
2500
if None in revision:
2501
raise errors.BzrCommandError(
2502
"Merge doesn't permit empty revision specifier.")
2503
base_branch, path = Branch.open_containing(branch)
2504
branch1 = revision[1].get_branch() or branch
2505
other_branch, path1 = Branch.open_containing(branch1)
2506
if revision[0].get_branch() is not None:
2507
# then path was obtained from it, and is None.
2510
base = [branch, revision[0].in_history(base_branch).revno]
2511
other = [branch1, revision[1].in_history(other_branch).revno]
2513
if tree.branch.get_parent() is None or remember:
2514
tree.branch.set_parent(other_branch.base)
2517
interesting_files = [path]
2519
interesting_files = None
2520
pb = ui.ui_factory.nested_progress_bar()
2523
conflict_count = _merge_helper(
2524
other, base, check_clean=(not force),
2525
merge_type=merge_type,
2526
reprocess=reprocess,
2527
show_base=show_base,
2530
pb=pb, file_list=interesting_files,
2531
change_reporter=change_reporter)
2534
if conflict_count != 0:
3686
raise errors.BzrCommandError('Cannot use --uncommitted'
3687
' with bundles or merge directives.')
3689
if revision is not None:
3690
raise errors.BzrCommandError(
3691
'Cannot use -r with merge directives or bundles')
3692
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3695
if merger is None and uncommitted:
3696
if revision is not None and len(revision) > 0:
3697
raise errors.BzrCommandError('Cannot use --uncommitted and'
3698
' --revision at the same time.')
3699
merger = self.get_merger_from_uncommitted(tree, location, pb,
3701
allow_pending = False
3704
merger, allow_pending = self._get_merger_from_branch(tree,
3705
location, revision, remember, possible_transports, pb)
3707
merger.merge_type = merge_type
3708
merger.reprocess = reprocess
3709
merger.show_base = show_base
3710
self.sanity_check_merger(merger)
3711
if (merger.base_rev_id == merger.other_rev_id and
3712
merger.other_rev_id is not None):
3713
note('Nothing to do.')
2538
except errors.AmbiguousBase, e:
2539
m = ("sorry, bzr can't determine the right merge base yet\n"
2540
"candidates are:\n "
2541
+ "\n ".join(e.bases)
2543
"please specify an explicit base with -r,\n"
2544
"and (if you want) report this to the bzr developers\n")
2547
# TODO: move up to common parent; this isn't merge-specific anymore.
2548
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3716
if merger.interesting_files is not None:
3717
raise errors.BzrCommandError('Cannot pull individual files')
3718
if (merger.base_rev_id == tree.last_revision()):
3719
result = tree.pull(merger.other_branch, False,
3720
merger.other_rev_id)
3721
result.report(self.outf)
3723
merger.check_basis(False)
3725
return self._do_preview(merger, cleanups)
3727
return self._do_interactive(merger, cleanups)
3729
return self._do_merge(merger, change_reporter, allow_pending,
3732
for cleanup in reversed(cleanups):
3735
def _get_preview(self, merger, cleanups):
3736
tree_merger = merger.make_merger()
3737
tt = tree_merger.make_preview_transform()
3738
cleanups.append(tt.finalize)
3739
result_tree = tt.get_preview_tree()
3742
def _do_preview(self, merger, cleanups):
3743
from bzrlib.diff import show_diff_trees
3744
result_tree = self._get_preview(merger, cleanups)
3745
show_diff_trees(merger.this_tree, result_tree, self.outf,
3746
old_label='', new_label='')
3748
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3749
merger.change_reporter = change_reporter
3750
conflict_count = merger.do_merge()
3752
merger.set_pending()
3753
if verified == 'failed':
3754
warning('Preview patch does not match changes')
3755
if conflict_count != 0:
3760
def _do_interactive(self, merger, cleanups):
3761
"""Perform an interactive merge.
3763
This works by generating a preview tree of the merge, then using
3764
Shelver to selectively remove the differences between the working tree
3765
and the preview tree.
3767
from bzrlib import shelf_ui
3768
result_tree = self._get_preview(merger, cleanups)
3769
writer = bzrlib.option.diff_writer_registry.get()
3770
shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
3771
reporter=shelf_ui.ApplyReporter(),
3772
diff_writer=writer(sys.stdout))
3775
def sanity_check_merger(self, merger):
3776
if (merger.show_base and
3777
not merger.merge_type is _mod_merge.Merge3Merger):
3778
raise errors.BzrCommandError("Show-base is not supported for this"
3779
" merge type. %s" % merger.merge_type)
3780
if merger.reprocess is None:
3781
if merger.show_base:
3782
merger.reprocess = False
3784
# Use reprocess if the merger supports it
3785
merger.reprocess = merger.merge_type.supports_reprocess
3786
if merger.reprocess and not merger.merge_type.supports_reprocess:
3787
raise errors.BzrCommandError("Conflict reduction is not supported"
3788
" for merge type %s." %
3790
if merger.reprocess and merger.show_base:
3791
raise errors.BzrCommandError("Cannot do conflict reduction and"
3794
def _get_merger_from_branch(self, tree, location, revision, remember,
3795
possible_transports, pb):
3796
"""Produce a merger from a location, assuming it refers to a branch."""
3797
from bzrlib.tag import _merge_tags_if_possible
3798
# find the branch locations
3799
other_loc, user_location = self._select_branch_location(tree, location,
3801
if revision is not None and len(revision) == 2:
3802
base_loc, _unused = self._select_branch_location(tree,
3803
location, revision, 0)
3805
base_loc = other_loc
3807
other_branch, other_path = Branch.open_containing(other_loc,
3808
possible_transports)
3809
if base_loc == other_loc:
3810
base_branch = other_branch
3812
base_branch, base_path = Branch.open_containing(base_loc,
3813
possible_transports)
3814
# Find the revision ids
3815
other_revision_id = None
3816
base_revision_id = None
3817
if revision is not None:
3818
if len(revision) >= 1:
3819
other_revision_id = revision[-1].as_revision_id(other_branch)
3820
if len(revision) == 2:
3821
base_revision_id = revision[0].as_revision_id(base_branch)
3822
if other_revision_id is None:
3823
other_revision_id = _mod_revision.ensure_null(
3824
other_branch.last_revision())
3825
# Remember where we merge from
3826
if ((remember or tree.branch.get_submit_branch() is None) and
3827
user_location is not None):
3828
tree.branch.set_submit_branch(other_branch.base)
3829
_merge_tags_if_possible(other_branch, tree.branch)
3830
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3831
other_revision_id, base_revision_id, other_branch, base_branch)
3832
if other_path != '':
3833
allow_pending = False
3834
merger.interesting_files = [other_path]
3836
allow_pending = True
3837
return merger, allow_pending
3839
def get_merger_from_uncommitted(self, tree, location, pb, cleanups):
3840
"""Get a merger for uncommitted changes.
3842
:param tree: The tree the merger should apply to.
3843
:param location: The location containing uncommitted changes.
3844
:param pb: The progress bar to use for showing progress.
3845
:param cleanups: A list of operations to perform to clean up the
3846
temporary directories, unfinalized objects, etc.
3848
location = self._select_branch_location(tree, location)[0]
3849
other_tree, other_path = WorkingTree.open_containing(location)
3850
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree, pb)
3851
if other_path != '':
3852
merger.interesting_files = [other_path]
3855
def _select_branch_location(self, tree, user_location, revision=None,
3857
"""Select a branch location, according to possible inputs.
3859
If provided, branches from ``revision`` are preferred. (Both
3860
``revision`` and ``index`` must be supplied.)
3862
Otherwise, the ``location`` parameter is used. If it is None, then the
3863
``submit`` or ``parent`` location is used, and a note is printed.
3865
:param tree: The working tree to select a branch for merging into
3866
:param location: The location entered by the user
3867
:param revision: The revision parameter to the command
3868
:param index: The index to use for the revision parameter. Negative
3869
indices are permitted.
3870
:return: (selected_location, user_location). The default location
3871
will be the user-entered location.
3873
if (revision is not None and index is not None
3874
and revision[index] is not None):
3875
branch = revision[index].get_branch()
3876
if branch is not None:
3877
return branch, branch
3878
if user_location is None:
3879
location = self._get_remembered(tree, 'Merging from')
3881
location = user_location
3882
return location, user_location
3884
def _get_remembered(self, tree, verb_string):
2549
3885
"""Use tree.branch's parent if none was supplied.
2551
3887
Report if the remembered location was used.
2553
if supplied_location is not None:
2554
return supplied_location
2555
stored_location = tree.branch.get_parent()
3889
stored_location = tree.branch.get_submit_branch()
3890
stored_location_type = "submit"
3891
if stored_location is None:
3892
stored_location = tree.branch.get_parent()
3893
stored_location_type = "parent"
2556
3894
mutter("%s", stored_location)
2557
3895
if stored_location is None:
2558
3896
raise errors.BzrCommandError("No location specified or remembered")
2559
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2560
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3897
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3898
note(u"%s remembered %s location %s", verb_string,
3899
stored_location_type, display_url)
2561
3900
return stored_location
3150
4716
takes_options = [
3152
help='serve on stdin/out for use from inetd or sshd'),
4718
help='Serve on stdin/out for use from inetd or sshd.'),
4719
RegistryOption('protocol',
4720
help="Protocol to serve.",
4721
lazy_registry=('bzrlib.transport', 'transport_server_registry'),
4722
value_switches=True),
3154
help='listen for connections on nominated port of the form '
3155
'[hostname:]portnumber. Passing 0 as the port number will '
3156
'result in a dynamically allocated port.',
4724
help='Listen for connections on nominated port of the form '
4725
'[hostname:]portnumber. Passing 0 as the port number will '
4726
'result in a dynamically allocated port. The default port '
4727
'depends on the protocol.',
3158
4729
Option('directory',
3159
help='serve contents of directory',
4730
help='Serve contents of this directory.',
3161
4732
Option('allow-writes',
3162
help='By default the server is a readonly server. Supplying '
4733
help='By default the server is a readonly server. Supplying '
3163
4734
'--allow-writes enables write access to the contents of '
3164
'the served directory and below. '
4735
'the served directory and below.'
3168
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3169
from bzrlib.transport import smart
3170
from bzrlib.transport import get_transport
4739
def get_host_and_port(self, port):
4740
"""Return the host and port to run the smart server on.
4742
If 'port' is None, None will be returned for the host and port.
4744
If 'port' has a colon in it, the string before the colon will be
4745
interpreted as the host.
4747
:param port: A string of the port to run the server on.
4748
:return: A tuple of (host, port), where 'host' is a host name or IP,
4749
and port is an integer TCP/IP port.
4752
if port is not None:
4754
host, port = port.split(':')
4758
def run(self, port=None, inet=False, directory=None, allow_writes=False,
4760
from bzrlib.transport import get_transport, transport_server_registry
3171
4761
if directory is None:
3172
4762
directory = os.getcwd()
4763
if protocol is None:
4764
protocol = transport_server_registry.get()
4765
host, port = self.get_host_and_port(port)
3173
4766
url = urlutils.local_path_to_url(directory)
3174
4767
if not allow_writes:
3175
4768
url = 'readonly+' + url
3176
t = get_transport(url)
3178
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3179
elif port is not None:
3181
host, port = port.split(':')
3184
server = smart.SmartTCPServer(t, host=host, port=int(port))
3185
print 'listening on port: ', server.port
3188
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3192
# command-line interpretation helper for merge-related commands
3193
def _merge_helper(other_revision, base_revision,
3194
check_clean=True, ignore_zero=False,
3195
this_dir=None, backup_files=False,
3197
file_list=None, show_base=False, reprocess=False,
3200
change_reporter=None):
3201
"""Merge changes into a tree.
3204
list(path, revno) Base for three-way merge.
3205
If [None, None] then a base will be automatically determined.
3207
list(path, revno) Other revision for three-way merge.
3209
Directory to merge changes into; '.' by default.
3211
If true, this_dir must have no uncommitted changes before the
3213
ignore_zero - If true, suppress the "zero conflicts" message when
3214
there are no conflicts; should be set when doing something we expect
3215
to complete perfectly.
3216
file_list - If supplied, merge only changes to selected files.
3218
All available ancestors of other_revision and base_revision are
3219
automatically pulled into the branch.
3221
The revno may be -1 to indicate the last revision on the branch, which is
3224
This function is intended for use from the command line; programmatic
3225
clients might prefer to call merge.merge_inner(), which has less magic
3228
# Loading it late, so that we don't always have to import bzrlib.merge
3229
if merge_type is None:
3230
merge_type = _mod_merge.Merge3Merger
3231
if this_dir is None:
3233
this_tree = WorkingTree.open_containing(this_dir)[0]
3234
if show_base and not merge_type is _mod_merge.Merge3Merger:
3235
raise errors.BzrCommandError("Show-base is not supported for this merge"
3236
" type. %s" % merge_type)
3237
if reprocess and not merge_type.supports_reprocess:
3238
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3239
" type %s." % merge_type)
3240
if reprocess and show_base:
3241
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3242
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3243
# only want to take out a lock_tree_write() if we don't have to pull
3244
# any ancestry. But merge might fetch ancestry in the middle, in
3245
# which case we would need a lock_write().
3246
# Because we cannot upgrade locks, for now we live with the fact that
3247
# the tree will be locked multiple times during a merge. (Maybe
3248
# read-only some of the time, but it means things will get read
3251
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3252
pb=pb, change_reporter=change_reporter)
3253
merger.pp = ProgressPhase("Merge phase", 5, pb)
3254
merger.pp.next_phase()
3255
merger.check_basis(check_clean)
3256
merger.set_other(other_revision)
3257
merger.pp.next_phase()
3258
merger.set_base(base_revision)
3259
if merger.base_rev_id == merger.other_rev_id:
3260
note('Nothing to do.')
4769
transport = get_transport(url)
4770
protocol(transport, host, port, inet)
4773
class cmd_join(Command):
4774
"""Combine a tree into its containing tree.
4776
This command requires the target tree to be in a rich-root format.
4778
The TREE argument should be an independent tree, inside another tree, but
4779
not part of it. (Such trees can be produced by "bzr split", but also by
4780
running "bzr branch" with the target inside a tree.)
4782
The result is a combined tree, with the subtree no longer an independant
4783
part. This is marked as a merge of the subtree into the containing tree,
4784
and all history is preserved.
4787
_see_also = ['split']
4788
takes_args = ['tree']
4790
Option('reference', help='Join by reference.', hidden=True),
4793
def run(self, tree, reference=False):
4794
sub_tree = WorkingTree.open(tree)
4795
parent_dir = osutils.dirname(sub_tree.basedir)
4796
containing_tree = WorkingTree.open_containing(parent_dir)[0]
4797
repo = containing_tree.branch.repository
4798
if not repo.supports_rich_root():
4799
raise errors.BzrCommandError(
4800
"Can't join trees because %s doesn't support rich root data.\n"
4801
"You can use bzr upgrade on the repository."
4805
containing_tree.add_reference(sub_tree)
4806
except errors.BadReferenceTarget, e:
4807
# XXX: Would be better to just raise a nicely printable
4808
# exception from the real origin. Also below. mbp 20070306
4809
raise errors.BzrCommandError("Cannot join %s. %s" %
4813
containing_tree.subsume(sub_tree)
4814
except errors.BadSubsumeSource, e:
4815
raise errors.BzrCommandError("Cannot join %s. %s" %
4819
class cmd_split(Command):
4820
"""Split a subdirectory of a tree into a separate tree.
4822
This command will produce a target tree in a format that supports
4823
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
4824
converted into earlier formats like 'dirstate-tags'.
4826
The TREE argument should be a subdirectory of a working tree. That
4827
subdirectory will be converted into an independent tree, with its own
4828
branch. Commits in the top-level tree will not apply to the new subtree.
4831
_see_also = ['join']
4832
takes_args = ['tree']
4834
def run(self, tree):
4835
containing_tree, subdir = WorkingTree.open_containing(tree)
4836
sub_id = containing_tree.path2id(subdir)
4838
raise errors.NotVersionedError(subdir)
4840
containing_tree.extract(sub_id)
4841
except errors.RootNotRich:
4842
raise errors.RichRootUpgradeRequired(containing_tree.branch.base)
4845
class cmd_merge_directive(Command):
4846
"""Generate a merge directive for auto-merge tools.
4848
A directive requests a merge to be performed, and also provides all the
4849
information necessary to do so. This means it must either include a
4850
revision bundle, or the location of a branch containing the desired
4853
A submit branch (the location to merge into) must be supplied the first
4854
time the command is issued. After it has been supplied once, it will
4855
be remembered as the default.
4857
A public branch is optional if a revision bundle is supplied, but required
4858
if --diff or --plain is specified. It will be remembered as the default
4859
after the first use.
4862
takes_args = ['submit_branch?', 'public_branch?']
4866
_see_also = ['send']
4869
RegistryOption.from_kwargs('patch-type',
4870
'The type of patch to include in the directive.',
4872
value_switches=True,
4874
bundle='Bazaar revision bundle (default).',
4875
diff='Normal unified diff.',
4876
plain='No patch, just directive.'),
4877
Option('sign', help='GPG-sign the directive.'), 'revision',
4878
Option('mail-to', type=str,
4879
help='Instead of printing the directive, email to this address.'),
4880
Option('message', type=str, short_name='m',
4881
help='Message to use when committing this merge.')
4884
encoding_type = 'exact'
4886
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
4887
sign=False, revision=None, mail_to=None, message=None):
4888
from bzrlib.revision import ensure_null, NULL_REVISION
4889
include_patch, include_bundle = {
4890
'plain': (False, False),
4891
'diff': (True, False),
4892
'bundle': (True, True),
4894
branch = Branch.open('.')
4895
stored_submit_branch = branch.get_submit_branch()
4896
if submit_branch is None:
4897
submit_branch = stored_submit_branch
4899
if stored_submit_branch is None:
4900
branch.set_submit_branch(submit_branch)
4901
if submit_branch is None:
4902
submit_branch = branch.get_parent()
4903
if submit_branch is None:
4904
raise errors.BzrCommandError('No submit branch specified or known')
4906
stored_public_branch = branch.get_public_branch()
4907
if public_branch is None:
4908
public_branch = stored_public_branch
4909
elif stored_public_branch is None:
4910
branch.set_public_branch(public_branch)
4911
if not include_bundle and public_branch is None:
4912
raise errors.BzrCommandError('No public branch specified or'
4914
base_revision_id = None
4915
if revision is not None:
4916
if len(revision) > 2:
4917
raise errors.BzrCommandError('bzr merge-directive takes '
4918
'at most two one revision identifiers')
4919
revision_id = revision[-1].as_revision_id(branch)
4920
if len(revision) == 2:
4921
base_revision_id = revision[0].as_revision_id(branch)
4923
revision_id = branch.last_revision()
4924
revision_id = ensure_null(revision_id)
4925
if revision_id == NULL_REVISION:
4926
raise errors.BzrCommandError('No revisions to bundle.')
4927
directive = merge_directive.MergeDirective2.from_objects(
4928
branch.repository, revision_id, time.time(),
4929
osutils.local_time_offset(), submit_branch,
4930
public_branch=public_branch, include_patch=include_patch,
4931
include_bundle=include_bundle, message=message,
4932
base_revision_id=base_revision_id)
4935
self.outf.write(directive.to_signed(branch))
4937
self.outf.writelines(directive.to_lines())
4939
message = directive.to_email(mail_to, branch, sign)
4940
s = SMTPConnection(branch.get_config())
4941
s.send_email(message)
4944
class cmd_send(Command):
4945
"""Mail or create a merge-directive for submitting changes.
4947
A merge directive provides many things needed for requesting merges:
4949
* A machine-readable description of the merge to perform
4951
* An optional patch that is a preview of the changes requested
4953
* An optional bundle of revision data, so that the changes can be applied
4954
directly from the merge directive, without retrieving data from a
4957
If --no-bundle is specified, then public_branch is needed (and must be
4958
up-to-date), so that the receiver can perform the merge using the
4959
public_branch. The public_branch is always included if known, so that
4960
people can check it later.
4962
The submit branch defaults to the parent, but can be overridden. Both
4963
submit branch and public branch will be remembered if supplied.
4965
If a public_branch is known for the submit_branch, that public submit
4966
branch is used in the merge instructions. This means that a local mirror
4967
can be used as your actual submit branch, once you have set public_branch
4970
Mail is sent using your preferred mail program. This should be transparent
4971
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4972
If the preferred client can't be found (or used), your editor will be used.
4974
To use a specific mail program, set the mail_client configuration option.
4975
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4976
specific clients are "claws", "evolution", "kmail", "mutt", and
4977
"thunderbird"; generic options are "default", "editor", "emacsclient",
4978
"mapi", and "xdg-email". Plugins may also add supported clients.
4980
If mail is being sent, a to address is required. This can be supplied
4981
either on the commandline, by setting the submit_to configuration
4982
option in the branch itself or the child_submit_to configuration option
4983
in the submit branch.
4985
Two formats are currently supported: "4" uses revision bundle format 4 and
4986
merge directive format 2. It is significantly faster and smaller than
4987
older formats. It is compatible with Bazaar 0.19 and later. It is the
4988
default. "0.9" uses revision bundle format 0.9 and merge directive
4989
format 1. It is compatible with Bazaar 0.12 - 0.18.
4991
The merge directives created by bzr send may be applied using bzr merge or
4992
bzr pull by specifying a file containing a merge directive as the location.
4995
encoding_type = 'exact'
4997
_see_also = ['merge', 'pull']
4999
takes_args = ['submit_branch?', 'public_branch?']
5003
help='Do not include a bundle in the merge directive.'),
5004
Option('no-patch', help='Do not include a preview patch in the merge'
5007
help='Remember submit and public branch.'),
5009
help='Branch to generate the submission from, '
5010
'rather than the one containing the working directory.',
5013
Option('output', short_name='o',
5014
help='Write merge directive to this file; '
5015
'use - for stdout.',
5018
help='Refuse to send if there are uncommitted changes in'
5019
' the working tree, --no-strict disables the check.'),
5020
Option('mail-to', help='Mail the request to this address.',
5024
Option('body', help='Body for the email.', type=unicode),
5025
RegistryOption('format',
5026
help='Use the specified output format.',
5027
lazy_registry=('bzrlib.send', 'format_registry')),
5030
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5031
no_patch=False, revision=None, remember=False, output=None,
5032
format=None, mail_to=None, message=None, body=None,
5033
strict=None, **kwargs):
5034
from bzrlib.send import send
5035
return send(submit_branch, revision, public_branch, remember,
5036
format, no_bundle, no_patch, output,
5037
kwargs.get('from', '.'), mail_to, message, body,
5042
class cmd_bundle_revisions(cmd_send):
5043
"""Create a merge-directive for submitting changes.
5045
A merge directive provides many things needed for requesting merges:
5047
* A machine-readable description of the merge to perform
5049
* An optional patch that is a preview of the changes requested
5051
* An optional bundle of revision data, so that the changes can be applied
5052
directly from the merge directive, without retrieving data from a
5055
If --no-bundle is specified, then public_branch is needed (and must be
5056
up-to-date), so that the receiver can perform the merge using the
5057
public_branch. The public_branch is always included if known, so that
5058
people can check it later.
5060
The submit branch defaults to the parent, but can be overridden. Both
5061
submit branch and public branch will be remembered if supplied.
5063
If a public_branch is known for the submit_branch, that public submit
5064
branch is used in the merge instructions. This means that a local mirror
5065
can be used as your actual submit branch, once you have set public_branch
5068
Two formats are currently supported: "4" uses revision bundle format 4 and
5069
merge directive format 2. It is significantly faster and smaller than
5070
older formats. It is compatible with Bazaar 0.19 and later. It is the
5071
default. "0.9" uses revision bundle format 0.9 and merge directive
5072
format 1. It is compatible with Bazaar 0.12 - 0.18.
5077
help='Do not include a bundle in the merge directive.'),
5078
Option('no-patch', help='Do not include a preview patch in the merge'
5081
help='Remember submit and public branch.'),
5083
help='Branch to generate the submission from, '
5084
'rather than the one containing the working directory.',
5087
Option('output', short_name='o', help='Write directive to this file.',
5090
help='Refuse to bundle revisions if there are uncommitted'
5091
' changes in the working tree, --no-strict disables the check.'),
5093
RegistryOption('format',
5094
help='Use the specified output format.',
5095
lazy_registry=('bzrlib.send', 'format_registry')),
5097
aliases = ['bundle']
5099
_see_also = ['send', 'merge']
5103
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5104
no_patch=False, revision=None, remember=False, output=None,
5105
format=None, strict=None, **kwargs):
5108
from bzrlib.send import send
5109
return send(submit_branch, revision, public_branch, remember,
5110
format, no_bundle, no_patch, output,
5111
kwargs.get('from', '.'), None, None, None,
5112
self.outf, strict=strict)
5115
class cmd_tag(Command):
5116
"""Create, remove or modify a tag naming a revision.
5118
Tags give human-meaningful names to revisions. Commands that take a -r
5119
(--revision) option can be given -rtag:X, where X is any previously
5122
Tags are stored in the branch. Tags are copied from one branch to another
5123
along when you branch, push, pull or merge.
5125
It is an error to give a tag name that already exists unless you pass
5126
--force, in which case the tag is moved to point to the new revision.
5128
To rename a tag (change the name but keep it on the same revsion), run ``bzr
5129
tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
5132
_see_also = ['commit', 'tags']
5133
takes_args = ['tag_name']
5136
help='Delete this tag rather than placing it.',
5139
help='Branch in which to place the tag.',
5144
help='Replace existing tags.',
5149
def run(self, tag_name,
5155
branch, relpath = Branch.open_containing(directory)
5159
branch.tags.delete_tag(tag_name)
5160
self.outf.write('Deleted tag %s.\n' % tag_name)
5163
if len(revision) != 1:
5164
raise errors.BzrCommandError(
5165
"Tags can only be placed on a single revision, "
5167
revision_id = revision[0].as_revision_id(branch)
5169
revision_id = branch.last_revision()
5170
if (not force) and branch.tags.has_tag(tag_name):
5171
raise errors.TagAlreadyExists(tag_name)
5172
branch.tags.set_tag(tag_name, revision_id)
5173
self.outf.write('Created tag %s.\n' % tag_name)
5178
class cmd_tags(Command):
5181
This command shows a table of tag names and the revisions they reference.
5187
help='Branch whose tags should be displayed.',
5191
RegistryOption.from_kwargs('sort',
5192
'Sort tags by different criteria.', title='Sorting',
5193
alpha='Sort tags lexicographically (default).',
5194
time='Sort tags chronologically.',
5207
branch, relpath = Branch.open_containing(directory)
5209
tags = branch.tags.get_tag_dict().items()
5216
graph = branch.repository.get_graph()
5217
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5218
revid1, revid2 = rev1.rev_id, rev2.rev_id
5219
# only show revisions between revid1 and revid2 (inclusive)
5220
tags = [(tag, revid) for tag, revid in tags if
5221
graph.is_between(revid, revid1, revid2)]
5224
elif sort == 'time':
5226
for tag, revid in tags:
5228
revobj = branch.repository.get_revision(revid)
5229
except errors.NoSuchRevision:
5230
timestamp = sys.maxint # place them at the end
5232
timestamp = revobj.timestamp
5233
timestamps[revid] = timestamp
5234
tags.sort(key=lambda x: timestamps[x[1]])
5236
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5237
for index, (tag, revid) in enumerate(tags):
5239
revno = branch.revision_id_to_dotted_revno(revid)
5240
if isinstance(revno, tuple):
5241
revno = '.'.join(map(str, revno))
5242
except errors.NoSuchRevision:
5243
# Bad tag data/merges can lead to tagged revisions
5244
# which are not in this branch. Fail gracefully ...
5246
tags[index] = (tag, revno)
5249
for tag, revspec in tags:
5250
self.outf.write('%-20s %s\n' % (tag, revspec))
5253
class cmd_reconfigure(Command):
5254
"""Reconfigure the type of a bzr directory.
5256
A target configuration must be specified.
5258
For checkouts, the bind-to location will be auto-detected if not specified.
5259
The order of preference is
5260
1. For a lightweight checkout, the current bound location.
5261
2. For branches that used to be checkouts, the previously-bound location.
5262
3. The push location.
5263
4. The parent location.
5264
If none of these is available, --bind-to must be specified.
5267
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5268
takes_args = ['location?']
5270
RegistryOption.from_kwargs(
5272
title='Target type',
5273
help='The type to reconfigure the directory to.',
5274
value_switches=True, enum_switch=False,
5275
branch='Reconfigure to be an unbound branch with no working tree.',
5276
tree='Reconfigure to be an unbound branch with a working tree.',
5277
checkout='Reconfigure to be a bound branch with a working tree.',
5278
lightweight_checkout='Reconfigure to be a lightweight'
5279
' checkout (with no local history).',
5280
standalone='Reconfigure to be a standalone branch '
5281
'(i.e. stop using shared repository).',
5282
use_shared='Reconfigure to use a shared repository.',
5283
with_trees='Reconfigure repository to create '
5284
'working trees on branches by default.',
5285
with_no_trees='Reconfigure repository to not create '
5286
'working trees on branches by default.'
5288
Option('bind-to', help='Branch to bind checkout to.', type=str),
5290
help='Perform reconfiguration even if local changes'
5292
Option('stacked-on',
5293
help='Reconfigure a branch to be stacked on another branch.',
5297
help='Reconfigure a branch to be unstacked. This '
5298
'may require copying substantial data into it.',
5302
def run(self, location=None, target_type=None, bind_to=None, force=False,
5305
directory = bzrdir.BzrDir.open(location)
5306
if stacked_on and unstacked:
5307
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5308
elif stacked_on is not None:
5309
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5311
reconfigure.ReconfigureUnstacked().apply(directory)
5312
# At the moment you can use --stacked-on and a different
5313
# reconfiguration shape at the same time; there seems no good reason
5315
if target_type is None:
5316
if stacked_on or unstacked:
5319
raise errors.BzrCommandError('No target configuration '
5321
elif target_type == 'branch':
5322
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5323
elif target_type == 'tree':
5324
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5325
elif target_type == 'checkout':
5326
reconfiguration = reconfigure.Reconfigure.to_checkout(
5328
elif target_type == 'lightweight-checkout':
5329
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5331
elif target_type == 'use-shared':
5332
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5333
elif target_type == 'standalone':
5334
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5335
elif target_type == 'with-trees':
5336
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5338
elif target_type == 'with-no-trees':
5339
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5341
reconfiguration.apply(force)
5344
class cmd_switch(Command):
5345
"""Set the branch of a checkout and update.
5347
For lightweight checkouts, this changes the branch being referenced.
5348
For heavyweight checkouts, this checks that there are no local commits
5349
versus the current bound branch, then it makes the local branch a mirror
5350
of the new location and binds to it.
5352
In both cases, the working tree is updated and uncommitted changes
5353
are merged. The user can commit or revert these as they desire.
5355
Pending merges need to be committed or reverted before using switch.
5357
The path to the branch to switch to can be specified relative to the parent
5358
directory of the current branch. For example, if you are currently in a
5359
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5362
Bound branches use the nickname of its master branch unless it is set
5363
locally, in which case switching will update the the local nickname to be
5367
takes_args = ['to_location']
5368
takes_options = [Option('force',
5369
help='Switch even if local commits will be lost.'),
5370
Option('create-branch', short_name='b',
5371
help='Create the target branch from this one before'
5372
' switching to it.'),
5375
def run(self, to_location, force=False, create_branch=False):
5376
from bzrlib import switch
5378
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5380
branch = control_dir.open_branch()
5381
had_explicit_nick = branch.get_config().has_explicit_nickname()
5382
except errors.NotBranchError:
5384
had_explicit_nick = False
5387
raise errors.BzrCommandError('cannot create branch without'
5389
if '/' not in to_location and '\\' not in to_location:
5390
# This path is meant to be relative to the existing branch
5391
this_url = self._get_branch_location(control_dir)
5392
to_location = urlutils.join(this_url, '..', to_location)
5393
to_branch = branch.bzrdir.sprout(to_location,
5394
possible_transports=[branch.bzrdir.root_transport],
5395
source_branch=branch).open_branch()
5397
# from_branch = control_dir.open_branch()
5398
# except errors.NotBranchError:
5399
# raise BzrCommandError('Cannot create a branch from this'
5400
# ' location when we cannot open this branch')
5401
# from_branch.bzrdir.sprout(
5405
to_branch = Branch.open(to_location)
5406
except errors.NotBranchError:
5407
this_url = self._get_branch_location(control_dir)
5408
to_branch = Branch.open(
5409
urlutils.join(this_url, '..', to_location))
5410
switch.switch(control_dir, to_branch, force)
5411
if had_explicit_nick:
5412
branch = control_dir.open_branch() #get the new branch!
5413
branch.nick = to_branch.nick
5414
note('Switched to branch: %s',
5415
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5417
def _get_branch_location(self, control_dir):
5418
"""Return location of branch for this control dir."""
5420
this_branch = control_dir.open_branch()
5421
# This may be a heavy checkout, where we want the master branch
5422
master_location = this_branch.get_bound_location()
5423
if master_location is not None:
5424
return master_location
5425
# If not, use a local sibling
5426
return this_branch.base
5427
except errors.NotBranchError:
5428
format = control_dir.find_branch_format()
5429
if getattr(format, 'get_reference', None) is not None:
5430
return format.get_reference(control_dir)
5432
return control_dir.root_transport.base
5435
class cmd_view(Command):
5436
"""Manage filtered views.
5438
Views provide a mask over the tree so that users can focus on
5439
a subset of a tree when doing their work. After creating a view,
5440
commands that support a list of files - status, diff, commit, etc -
5441
effectively have that list of files implicitly given each time.
5442
An explicit list of files can still be given but those files
5443
must be within the current view.
5445
In most cases, a view has a short life-span: it is created to make
5446
a selected change and is deleted once that change is committed.
5447
At other times, you may wish to create one or more named views
5448
and switch between them.
5450
To disable the current view without deleting it, you can switch to
5451
the pseudo view called ``off``. This can be useful when you need
5452
to see the whole tree for an operation or two (e.g. merge) but
5453
want to switch back to your view after that.
5456
To define the current view::
5458
bzr view file1 dir1 ...
5460
To list the current view::
5464
To delete the current view::
5468
To disable the current view without deleting it::
5470
bzr view --switch off
5472
To define a named view and switch to it::
5474
bzr view --name view-name file1 dir1 ...
5476
To list a named view::
5478
bzr view --name view-name
5480
To delete a named view::
5482
bzr view --name view-name --delete
5484
To switch to a named view::
5486
bzr view --switch view-name
5488
To list all views defined::
5492
To delete all views::
5494
bzr view --delete --all
5498
takes_args = ['file*']
5501
help='Apply list or delete action to all views.',
5504
help='Delete the view.',
5507
help='Name of the view to define, list or delete.',
5511
help='Name of the view to switch to.',
5516
def run(self, file_list,
5522
tree, file_list = tree_files(file_list, apply_view=False)
5523
current_view, view_dict = tree.views.get_view_info()
5528
raise errors.BzrCommandError(
5529
"Both --delete and a file list specified")
5531
raise errors.BzrCommandError(
5532
"Both --delete and --switch specified")
5534
tree.views.set_view_info(None, {})
5535
self.outf.write("Deleted all views.\n")
5537
raise errors.BzrCommandError("No current view to delete")
5539
tree.views.delete_view(name)
5540
self.outf.write("Deleted '%s' view.\n" % name)
5543
raise errors.BzrCommandError(
5544
"Both --switch and a file list specified")
5546
raise errors.BzrCommandError(
5547
"Both --switch and --all specified")
5548
elif switch == 'off':
5549
if current_view is None:
5550
raise errors.BzrCommandError("No current view to disable")
5551
tree.views.set_view_info(None, view_dict)
5552
self.outf.write("Disabled '%s' view.\n" % (current_view))
5554
tree.views.set_view_info(switch, view_dict)
5555
view_str = views.view_display_str(tree.views.lookup_view())
5556
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5559
self.outf.write('Views defined:\n')
5560
for view in sorted(view_dict):
5561
if view == current_view:
5565
view_str = views.view_display_str(view_dict[view])
5566
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5568
self.outf.write('No views defined.\n')
5571
# No name given and no current view set
5574
raise errors.BzrCommandError(
5575
"Cannot change the 'off' pseudo view")
5576
tree.views.set_view(name, sorted(file_list))
5577
view_str = views.view_display_str(tree.views.lookup_view())
5578
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5582
# No name given and no current view set
5583
self.outf.write('No current view.\n')
5585
view_str = views.view_display_str(tree.views.lookup_view(name))
5586
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5589
class cmd_hooks(Command):
5595
for hook_key in sorted(hooks.known_hooks.keys()):
5596
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5597
self.outf.write("%s:\n" % type(some_hooks).__name__)
5598
for hook_name, hook_point in sorted(some_hooks.items()):
5599
self.outf.write(" %s:\n" % (hook_name,))
5600
found_hooks = list(hook_point)
5602
for hook in found_hooks:
5603
self.outf.write(" %s\n" %
5604
(some_hooks.get_hook_name(hook),))
5606
self.outf.write(" <no hooks installed>\n")
5609
class cmd_shelve(Command):
5610
"""Temporarily set aside some changes from the current tree.
5612
Shelve allows you to temporarily put changes you've made "on the shelf",
5613
ie. out of the way, until a later time when you can bring them back from
5614
the shelf with the 'unshelve' command. The changes are stored alongside
5615
your working tree, and so they aren't propagated along with your branch nor
5616
will they survive its deletion.
5618
If shelve --list is specified, previously-shelved changes are listed.
5620
Shelve is intended to help separate several sets of changes that have
5621
been inappropriately mingled. If you just want to get rid of all changes
5622
and you don't need to restore them later, use revert. If you want to
5623
shelve all text changes at once, use shelve --all.
5625
If filenames are specified, only the changes to those files will be
5626
shelved. Other files will be left untouched.
5628
If a revision is specified, changes since that revision will be shelved.
5630
You can put multiple items on the shelf, and by default, 'unshelve' will
5631
restore the most recently shelved changes.
5634
takes_args = ['file*']
5638
Option('all', help='Shelve all changes.'),
5640
RegistryOption('writer', 'Method to use for writing diffs.',
5641
bzrlib.option.diff_writer_registry,
5642
value_switches=True, enum_switch=False),
5644
Option('list', help='List shelved changes.'),
5646
help='Destroy removed changes instead of shelving them.'),
5648
_see_also = ['unshelve']
5650
def run(self, revision=None, all=False, file_list=None, message=None,
5651
writer=None, list=False, destroy=False):
5653
return self.run_for_list()
5654
from bzrlib.shelf_ui import Shelver
5656
writer = bzrlib.option.diff_writer_registry.get()
5658
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5659
file_list, message, destroy=destroy)
5663
shelver.work_tree.unlock()
5664
except errors.UserAbort:
3262
if file_list is None:
3263
if pull and merger.base_rev_id == merger.this_rev_id:
3264
count = merger.this_tree.pull(merger.this_branch,
3265
False, merger.other_rev_id)
3266
note('%d revision(s) pulled.' % (count,))
5667
def run_for_list(self):
5668
tree = WorkingTree.open_containing('.')[0]
5671
manager = tree.get_shelf_manager()
5672
shelves = manager.active_shelves()
5673
if len(shelves) == 0:
5674
note('No shelved changes.')
3268
merger.backup_files = backup_files
3269
merger.merge_type = merge_type
3270
merger.set_interesting_files(file_list)
3271
merger.show_base = show_base
3272
merger.reprocess = reprocess
3273
conflicts = merger.do_merge()
3274
if file_list is None:
3275
merger.set_pending()
3282
merge = _merge_helper
5676
for shelf_id in reversed(shelves):
5677
message = manager.get_metadata(shelf_id).get('message')
5679
message = '<no message>'
5680
self.outf.write('%3d: %s\n' % (shelf_id, message))
5686
class cmd_unshelve(Command):
5687
"""Restore shelved changes.
5689
By default, the most recently shelved changes are restored. However if you
5690
specify a shelf by id those changes will be restored instead. This works
5691
best when the changes don't depend on each other.
5694
takes_args = ['shelf_id?']
5696
RegistryOption.from_kwargs(
5697
'action', help="The action to perform.",
5698
enum_switch=False, value_switches=True,
5699
apply="Apply changes and remove from the shelf.",
5700
dry_run="Show changes, but do not apply or remove them.",
5701
delete_only="Delete changes without applying them."
5704
_see_also = ['shelve']
5706
def run(self, shelf_id=None, action='apply'):
5707
from bzrlib.shelf_ui import Unshelver
5708
unshelver = Unshelver.from_args(shelf_id, action)
5712
unshelver.tree.unlock()
5715
class cmd_clean_tree(Command):
5716
"""Remove unwanted files from working tree.
5718
By default, only unknown files, not ignored files, are deleted. Versioned
5719
files are never deleted.
5721
Another class is 'detritus', which includes files emitted by bzr during
5722
normal operations and selftests. (The value of these files decreases with
5725
If no options are specified, unknown files are deleted. Otherwise, option
5726
flags are respected, and may be combined.
5728
To check what clean-tree will do, use --dry-run.
5730
takes_options = [Option('ignored', help='Delete all ignored files.'),
5731
Option('detritus', help='Delete conflict files, merge'
5732
' backups, and failed selftest dirs.'),
5734
help='Delete files unknown to bzr (default).'),
5735
Option('dry-run', help='Show files to delete instead of'
5737
Option('force', help='Do not prompt before deleting.')]
5738
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5740
from bzrlib.clean_tree import clean_tree
5741
if not (unknown or ignored or detritus):
5745
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5746
dry_run=dry_run, no_prompt=force)
5749
class cmd_reference(Command):
5750
"""list, view and set branch locations for nested trees.
5752
If no arguments are provided, lists the branch locations for nested trees.
5753
If one argument is provided, display the branch location for that tree.
5754
If two arguments are provided, set the branch location for that tree.
5759
takes_args = ['path?', 'location?']
5761
def run(self, path=None, location=None):
5763
if path is not None:
5765
tree, branch, relpath =(
5766
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5767
if path is not None:
5770
tree = branch.basis_tree()
5772
info = branch._get_all_reference_info().iteritems()
5773
self._display_reference_info(tree, branch, info)
5775
file_id = tree.path2id(path)
5777
raise errors.NotVersionedError(path)
5778
if location is None:
5779
info = [(file_id, branch.get_reference_info(file_id))]
5780
self._display_reference_info(tree, branch, info)
5782
branch.set_reference_info(file_id, path, location)
5784
def _display_reference_info(self, tree, branch, info):
5786
for file_id, (path, location) in info:
5788
path = tree.id2path(file_id)
5789
except errors.NoSuchId:
5791
ref_list.append((path, location))
5792
for path, location in sorted(ref_list):
5793
self.outf.write('%s %s\n' % (path, location))
3285
5796
# these get imported and then picked up by the scan for cmd_*
3286
5797
# TODO: Some more consistent way to split command definitions across files;
3287
# we do need to load at least some information about them to know of
5798
# we do need to load at least some information about them to know of
3288
5799
# aliases. ideally we would avoid loading the implementation until the
3289
5800
# details were needed.
3290
5801
from bzrlib.cmd_version_info import cmd_version_info
3291
5802
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3292
from bzrlib.bundle.commands import cmd_bundle_revisions
5803
from bzrlib.bundle.commands import (
5806
from bzrlib.foreign import cmd_dpush
3293
5807
from bzrlib.sign_my_commits import cmd_sign_my_commits
3294
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
5808
from bzrlib.weave_commands import cmd_versionedfile_list, \
3295
5809
cmd_weave_plan_merge, cmd_weave_merge_text