606
594
self.outf.encoding)
607
595
self.outf.write("Using saved location: %s\n" % display_url)
608
596
location = stored_loc
609
location_transport = transport.get_transport(location)
611
if mergeable is not None:
612
if revision is not None:
613
raise errors.BzrCommandError(
614
'Cannot use -r with merge directives or bundles')
615
mergeable.install_revisions(branch_to.repository)
616
base_revision_id, revision_id, verified = \
617
mergeable.get_merge_request(branch_to.repository)
598
if reader is not None:
599
install_bundle(branch_to.repository, reader)
618
600
branch_from = branch_to
620
branch_from = Branch.open_from_transport(location_transport)
602
branch_from = Branch.open(location)
622
604
if branch_to.get_parent() is None or remember:
623
605
branch_to.set_parent(branch_from.base)
625
if revision is not None:
626
if len(revision) == 1:
627
revision_id = revision[0].in_history(branch_from).rev_id
629
raise errors.BzrCommandError(
630
'bzr pull --revision takes one value.')
609
if reader is not None:
610
rev_id = reader.target
611
elif len(revision) == 1:
612
rev_id = revision[0].in_history(branch_from).rev_id
614
raise errors.BzrCommandError('bzr pull --revision takes one value.')
633
old_rh = branch_to.revision_history()
616
old_rh = branch_to.revision_history()
634
617
if tree_to is not None:
635
result = tree_to.pull(branch_from, overwrite, revision_id,
618
result = tree_to.pull(branch_from, overwrite, rev_id,
636
619
delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
638
result = branch_to.pull(branch_from, overwrite, revision_id)
621
result = branch_to.pull(branch_from, overwrite, rev_id)
640
623
result.report(self.outf)
642
625
from bzrlib.log import show_changed_revisions
643
626
new_rh = branch_to.revision_history()
644
show_changed_revisions(branch_to, old_rh, new_rh,
627
show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
648
630
class cmd_push(Command):
906
912
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
907
913
be used. In other words, "checkout ../foo/bar" will attempt to create ./bar.
908
If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
909
is derived from the BRANCH_LOCATION by stripping a leading scheme or drive
910
identifier, if any. For example, "checkout lp:foo-bar" will attempt to
913
915
To retrieve the branch as of a particular revision, supply the --revision
914
916
parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
915
917
out of date [so you cannot commit] but it may be useful (i.e. to examine old
920
--basis is to speed up checking out from remote branches. When specified, it
921
uses the inventory and file contents from the basis branch in preference to the
922
branch being checked out.
924
See "help checkouts" for more information on checkouts.
919
_see_also = ['checkouts', 'branch']
920
926
takes_args = ['branch_location?', 'to_location?']
921
takes_options = ['revision',
927
takes_options = ['revision', # , 'basis']
922
928
Option('lightweight',
923
help="Perform a lightweight checkout. Lightweight "
929
help="perform a lightweight checkout. Lightweight "
924
930
"checkouts depend on access to the branch for "
925
"every operation. Normal checkouts can perform "
931
"every operation. Normal checkouts can perform "
926
932
"common operations like diff and status without "
927
933
"such access, and also support local commits."
932
def run(self, branch_location=None, to_location=None, revision=None,
938
def run(self, branch_location=None, to_location=None, revision=None, basis=None,
933
939
lightweight=False):
934
940
if revision is None:
935
941
revision = [None]
1082
1079
also new, they will also be removed.
1084
1081
takes_args = ['file*']
1085
takes_options = ['verbose',
1086
Option('new', help='Remove newly-added files.'),
1087
RegistryOption.from_kwargs('file-deletion-strategy',
1088
'The file deletion mode to be used',
1089
title='Deletion Strategy', value_switches=True, enum_switch=False,
1090
safe='Only delete files if they can be'
1091
' safely recovered (default).',
1092
keep="Don't delete any files.",
1093
force='Delete all the specified files, even if they can not be '
1094
'recovered and even if they are non-empty directories.')]
1082
takes_options = ['verbose', Option('new', help='remove newly-added files')]
1095
1083
aliases = ['rm']
1096
1084
encoding_type = 'replace'
1098
def run(self, file_list, verbose=False, new=False,
1099
file_deletion_strategy='safe'):
1086
def run(self, file_list, verbose=False, new=False):
1100
1087
tree, file_list = tree_files(file_list)
1102
if file_list is not None:
1103
file_list = [f for f in file_list if f != '']
1105
raise errors.BzrCommandError('Specify one or more files to'
1106
' remove, or use --new.')
1089
if file_list is None:
1090
raise errors.BzrCommandError('Specify one or more files to'
1091
' remove, or use --new.')
1109
1093
added = tree.changes_from(tree.basis_tree(),
1110
1094
specific_files=file_list).added
1111
1095
file_list = sorted([f[0] for f in added], reverse=True)
1112
1096
if len(file_list) == 0:
1113
1097
raise errors.BzrCommandError('No matching files.')
1114
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1115
keep_files=file_deletion_strategy=='keep',
1116
force=file_deletion_strategy=='force')
1098
tree.remove(file_list, verbose=verbose, to_file=self.outf)
1119
1101
class cmd_file_id(Command):
1323
1286
class cmd_init_repository(Command):
1324
1287
"""Create a shared repository to hold branches.
1326
New branches created under the repository directory will store their
1327
revisions in the repository, not in the branch directory.
1329
If the --no-trees option is used then the branches in the repository
1330
will not have working trees by default.
1289
New branches created under the repository directory will store their revisions
1290
in the repository, not in the branch directory, if the branch format supports
1333
bzr init-repo --no-trees repo
1334
1295
bzr init repo/trunk
1335
1296
bzr checkout --lightweight repo/trunk trunk-checkout
1336
1297
cd trunk-checkout
1337
1298
(add files here)
1339
See 'bzr help repositories' for more information.
1342
_see_also = ['init', 'branch', 'checkout']
1343
1300
takes_args = ["location"]
1344
1301
takes_options = [RegistryOption('format',
1345
1302
help='Specify a format for this repository. See'
1346
' "bzr help formats" for details.',
1303
' "bzr help formats" for details',
1347
1304
registry=bzrdir.format_registry,
1348
1305
converter=bzrdir.format_registry.make_bzrdir,
1349
1306
value_switches=True, title='Repository format'),
1351
help='Branches in the repository will default to'
1352
' not having a working tree.'),
1308
help='Allows branches in repository to have'
1354
1310
aliases = ["init-repo"]
1356
def run(self, location, format=None, no_trees=False):
1311
def run(self, location, format=None, trees=False):
1357
1312
if format is None:
1358
1313
format = bzrdir.format_registry.make_bzrdir('default')
1739
1689
"""List files in a tree.
1742
_see_also = ['status', 'cat']
1743
1692
takes_args = ['path?']
1744
1693
# TODO: Take a revision or remote path and list that tree instead.
1748
Option('non-recursive',
1749
help='Don\'t recurse into subdirectories.'),
1751
help='Print paths relative to the root of the branch.'),
1752
Option('unknown', help='Print unknown files.'),
1753
Option('versioned', help='Print versioned files.'),
1754
Option('ignored', help='Print ignored files.'),
1756
help='Write an ascii NUL (\\0) separator '
1757
'between files rather than a newline.'),
1759
help='List entries of a particular kind: file, directory, symlink.',
1694
takes_options = ['verbose', 'revision',
1695
Option('non-recursive',
1696
help='don\'t recurse into sub-directories'),
1698
help='Print all paths from the root of the branch.'),
1699
Option('unknown', help='Print unknown files'),
1700
Option('versioned', help='Print versioned files'),
1701
Option('ignored', help='Print ignored files'),
1703
Option('null', help='Null separate the files'),
1763
1706
@display_command
1764
def run(self, revision=None, verbose=False,
1707
def run(self, revision=None, verbose=False,
1765
1708
non_recursive=False, from_root=False,
1766
1709
unknown=False, versioned=False, ignored=False,
1767
1710
null=False, kind=None, show_ids=False, path=None):
2137
2043
# XXX: verbose currently does nothing
2139
_see_also = ['bugs', 'uncommit']
2140
2045
takes_args = ['selected*']
2142
Option('message', type=unicode,
2144
help="Description of the new revision."),
2147
help='Commit even if nothing has changed.'),
2148
Option('file', type=str,
2151
help='Take commit message from this file.'),
2153
help="Refuse to commit if there are unknown "
2154
"files in the working tree."),
2155
ListOption('fixes', type=str,
2156
help="Mark a bug as being fixed by this revision."),
2158
help="Perform a local commit in a bound "
2159
"branch. Local commits are not pushed to "
2160
"the master branch until a normal commit "
2046
takes_options = ['message', 'verbose',
2048
help='commit even if nothing has changed'),
2049
Option('file', type=str,
2052
help='file containing commit message'),
2054
help="refuse to commit if there are unknown "
2055
"files in the working tree."),
2057
help="perform a local only commit in a bound "
2058
"branch. Such commits are not pushed to "
2059
"the master branch until a normal commit "
2164
2063
aliases = ['ci', 'checkin']
2166
def _get_bug_fix_properties(self, fixes, branch):
2168
# Configure the properties for bug fixing attributes.
2169
for fixed_bug in fixes:
2170
tokens = fixed_bug.split(':')
2171
if len(tokens) != 2:
2172
raise errors.BzrCommandError(
2173
"Invalid bug %s. Must be in the form of 'tag:id'. "
2174
"Commit refused." % fixed_bug)
2175
tag, bug_id = tokens
2177
bug_url = bugtracker.get_bug_url(tag, branch, bug_id)
2178
except errors.UnknownBugTrackerAbbreviation:
2179
raise errors.BzrCommandError(
2180
'Unrecognized bug %s. Commit refused.' % fixed_bug)
2181
except errors.MalformedBugIdentifier:
2182
raise errors.BzrCommandError(
2183
"Invalid bug identifier for %s. Commit refused."
2185
properties.append('%s fixed' % bug_url)
2186
return '\n'.join(properties)
2188
2065
def run(self, message=None, file=None, verbose=True, selected_list=None,
2189
unchanged=False, strict=False, local=False, fixes=None):
2066
unchanged=False, strict=False, local=False):
2190
2067
from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
2191
2068
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
2192
2069
StrictCommitFailed)
2387
2256
all other tests are run. This is useful if you have been working in a
2388
2257
particular area, but want to make sure nothing else was broken.
2390
If --exclude is given, tests that match that regular expression are
2391
excluded, regardless of whether they match --first or not.
2393
To help catch accidential dependencies between tests, the --randomize
2394
option is useful. In most cases, the argument used is the word 'now'.
2395
Note that the seed used for the random number generator is displayed
2396
when this option is used. The seed can be explicitly passed as the
2397
argument to this option if required. This enables reproduction of the
2398
actual ordering used if and when an order sensitive problem is encountered.
2400
If --list-only is given, the tests that would be run are listed. This is
2401
useful when combined with --first, --exclude and/or --randomize to
2402
understand their impact. The test harness reports "Listed nn tests in ..."
2403
instead of "Ran nn tests in ..." when list mode is enabled.
2405
2259
If the global option '--no-plugins' is given, plugins are not loaded
2406
2260
before running the selftests. This has two effects: features provided or
2407
2261
modified by plugins will not be tested, and tests provided by plugins will
2410
Tests that need working space on disk use a common temporary directory,
2411
typically inside $TMPDIR or /tmp.
2414
2265
bzr selftest ignore
2415
2266
run only tests relating to 'ignore'
2416
2267
bzr --no-plugins selftest -v
2417
2268
disable plugins and list tests as they're run
2270
For each test, that needs actual disk access, bzr create their own
2271
subdirectory in the temporary testing directory (testXXXX.tmp).
2272
By default the name of such subdirectory is based on the name of the test.
2273
If option '--numbered-dirs' is given, bzr will use sequent numbers
2274
of running tests to create such subdirectories. This is default behavior
2275
on Windows because of path length limitation.
2277
# TODO: --list should give a list of all available tests
2419
2279
# NB: this is used from the class without creating an instance, which is
2420
2280
# why it does not have a self parameter.
2421
2281
def get_transport_type(typestring):
2437
2297
takes_args = ['testspecs*']
2438
2298
takes_options = ['verbose',
2440
help='Stop when one test fails.',
2299
Option('one', help='stop when one test fails'),
2300
Option('keep-output',
2301
help='keep output directories when tests fail'),
2443
2302
Option('transport',
2444
2303
help='Use a different transport by default '
2445
2304
'throughout the test suite.',
2446
2305
type=get_transport_type),
2448
help='Run the benchmarks rather than selftests.'),
2306
Option('benchmark', help='run the bzr benchmarks.'),
2449
2307
Option('lsprof-timed',
2450
help='Generate lsprof output for benchmarked'
2308
help='generate lsprof output for benchmarked'
2451
2309
' sections of code.'),
2452
2310
Option('cache-dir', type=str,
2453
help='Cache intermediate benchmark output in this '
2311
help='a directory to cache intermediate'
2312
' benchmark steps'),
2313
Option('clean-output',
2314
help='clean temporary tests directories'
2315
' without running tests'),
2455
2316
Option('first',
2456
help='Run all tests, but run specified tests first.',
2317
help='run all tests, but run specified tests first'
2460
help='List the tests instead of running them.'),
2461
Option('randomize', type=str, argname="SEED",
2462
help='Randomize the order of tests using the given'
2463
' seed or "now" for the current time.'),
2464
Option('exclude', type=str, argname="PATTERN",
2466
help='Exclude tests that match this regular'
2319
Option('numbered-dirs',
2320
help='use numbered dirs for TestCaseInTempDir'),
2469
2322
encoding_type = 'replace'
2471
2324
def run(self, testspecs_list=None, verbose=None, one=False,
2472
transport=None, benchmark=None,
2473
lsprof_timed=None, cache_dir=None,
2474
first=False, list_only=False,
2475
randomize=None, exclude=None):
2325
keep_output=False, transport=None, benchmark=None,
2326
lsprof_timed=None, cache_dir=None, clean_output=False,
2327
first=False, numbered_dirs=None):
2476
2328
import bzrlib.ui
2477
2329
from bzrlib.tests import selftest
2478
2330
import bzrlib.benchmarks as benchmarks
2479
2331
from bzrlib.benchmarks import tree_creator
2480
from bzrlib.version import show_version
2334
from bzrlib.tests import clean_selftest_output
2335
clean_selftest_output()
2338
if numbered_dirs is None and sys.platform == 'win32':
2339
numbered_dirs = True
2482
2341
if cache_dir is not None:
2483
2342
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2485
show_version(show_config=False, show_copyright=False)
2343
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2344
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
2487
2346
if testspecs_list is not None:
2488
2347
pattern = '|'.join(testspecs_list)
2598
To merge the latest revision from bzr.dev:
2599
bzr merge ../bzr.dev
2458
To merge the latest revision from bzr.dev
2459
bzr merge ../bzr.dev
2601
To merge changes up to and including revision 82 from bzr.dev:
2602
bzr merge -r 82 ../bzr.dev
2461
To merge changes up to and including revision 82 from bzr.dev
2462
bzr merge -r 82 ../bzr.dev
2604
2464
To merge the changes introduced by 82, without previous changes:
2605
bzr merge -r 81..82 ../bzr.dev
2465
bzr merge -r 81..82 ../bzr.dev
2607
2467
merge refuses to run if there are any uncommitted changes, unless
2608
2468
--force is given.
2470
The following merge types are available:
2611
_see_also = ['update', 'remerge', 'status-flags']
2612
2472
takes_args = ['branch?']
2616
help='Merge even if the destination tree has uncommitted changes.'),
2473
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2620
2474
Option('show-base', help="Show base revision text in "
2622
2476
Option('uncommitted', help='Apply uncommitted changes'
2623
' from a working copy, instead of branch changes.'),
2477
' from a working copy, instead of branch changes'),
2624
2478
Option('pull', help='If the destination is already'
2625
2479
' completely merged into the source, pull from the'
2626
' source rather than merging. When this happens,'
2480
' source rather than merging. When this happens,'
2627
2481
' you do not need to commit the result.'),
2628
2482
Option('directory',
2629
help='Branch to merge into, '
2630
'rather than the one containing the working directory.',
2483
help='Branch to merge into, '
2484
'rather than the one containing the working directory',
2636
2490
def run(self, branch=None, revision=None, force=False, merge_type=None,
2639
2493
directory=None,
2641
2495
from bzrlib.tag import _merge_tags_if_possible
2642
# This is actually a branch (or merge-directive) *location*.
2646
2496
if merge_type is None:
2647
2497
merge_type = _mod_merge.Merge3Merger
2649
2499
if directory is None: directory = u'.'
2650
possible_transports = []
2652
allow_pending = True
2653
verified = 'inapplicable'
2500
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2501
# inventory. Because merge is a mutating operation, it really
2502
# should be a lock_write() for the whole cmd_merge operation.
2503
# However, cmd_merge open's its own tree in _merge_helper, which
2504
# means if we lock here, the later lock_write() will always block.
2505
# Either the merge helper code should be updated to take a tree,
2506
# (What about tree.merge_from_branch?)
2654
2507
tree = WorkingTree.open_containing(directory)[0]
2655
2508
change_reporter = delta._ChangeReporter(
2656
2509
unversioned_filter=tree.is_ignored)
2659
pb = ui.ui_factory.nested_progress_bar()
2660
cleanups.append(pb.finished)
2662
cleanups.append(tree.unlock)
2663
if location is not None:
2664
mergeable, other_transport = _get_mergeable_helper(location)
2667
raise errors.BzrCommandError('Cannot use --uncommitted'
2668
' with bundles or merge directives.')
2670
if revision is not None:
2671
raise errors.BzrCommandError(
2672
'Cannot use -r with merge directives or bundles')
2673
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2675
possible_transports.append(other_transport)
2677
if merger is None and uncommitted:
2678
if revision is not None and len(revision) > 0:
2679
raise errors.BzrCommandError('Cannot use --uncommitted and'
2680
' --revision at the same time.')
2681
location = self._select_branch_location(tree, location)[0]
2682
other_tree, other_path = WorkingTree.open_containing(location)
2683
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2685
allow_pending = False
2688
merger, allow_pending = self._get_merger_from_branch(tree,
2689
location, revision, remember, possible_transports, pb)
2691
merger.merge_type = merge_type
2692
merger.reprocess = reprocess
2693
merger.show_base = show_base
2694
merger.change_reporter = change_reporter
2695
self.sanity_check_merger(merger)
2696
if (merger.base_rev_id == merger.other_rev_id and
2697
merger.other_rev_id != None):
2698
note('Nothing to do.')
2701
if merger.interesting_files is not None:
2702
raise BzrCommandError('Cannot pull individual files')
2703
if (merger.base_rev_id == tree.last_revision()):
2704
result = tree.pull(merger.other_branch, False,
2705
merger.other_rev_id)
2706
result.report(self.outf)
2511
if branch is not None:
2513
reader = bundle.read_bundle_from_url(branch)
2514
except errors.NotABundle:
2515
pass # Continue on considering this url a Branch
2517
conflicts = merge_bundle(reader, tree, not force, merge_type,
2518
reprocess, show_base, change_reporter)
2708
merger.check_basis(not force)
2709
conflict_count = merger.do_merge()
2711
merger.set_pending()
2712
if verified == 'failed':
2713
warning('Preview patch does not match changes')
2714
if conflict_count != 0:
2719
for cleanup in reversed(cleanups):
2722
def sanity_check_merger(self, merger):
2723
if (merger.show_base and
2724
not merger.merge_type is _mod_merge.Merge3Merger):
2725
raise errors.BzrCommandError("Show-base is not supported for this"
2726
" merge type. %s" % merge_type)
2727
if merger.reprocess and not merger.merge_type.supports_reprocess:
2728
raise errors.BzrCommandError("Conflict reduction is not supported"
2729
" for merge type %s." % merge_type)
2730
if merger.reprocess and merger.show_base:
2731
raise errors.BzrCommandError("Cannot do conflict reduction and"
2734
def _get_merger_from_branch(self, tree, location, revision, remember,
2735
possible_transports, pb):
2736
"""Produce a merger from a location, assuming it refers to a branch."""
2737
from bzrlib.tag import _merge_tags_if_possible
2738
assert revision is None or len(revision) < 3
2739
# find the branch locations
2740
other_loc, location = self._select_branch_location(tree, location,
2742
if revision is not None and len(revision) == 2:
2743
base_loc, location = self._select_branch_location(tree, location,
2746
base_loc = other_loc
2748
other_branch, other_path = Branch.open_containing(other_loc,
2749
possible_transports)
2750
if base_loc == other_loc:
2751
base_branch = other_branch
2753
base_branch, base_path = Branch.open_containing(base_loc,
2754
possible_transports)
2755
# Find the revision ids
2756
if revision is None or len(revision) < 1 or revision[-1] is None:
2757
other_revision_id = _mod_revision.ensure_null(
2758
other_branch.last_revision())
2760
other_revision_id = \
2761
_mod_revision.ensure_null(
2762
revision[-1].in_history(other_branch).rev_id)
2763
if (revision is not None and len(revision) == 2
2764
and revision[0] is not None):
2765
base_revision_id = \
2766
_mod_revision.ensure_null(
2767
revision[0].in_history(base_branch).rev_id)
2769
base_revision_id = None
2770
# Remember where we merge from
2771
if ((tree.branch.get_parent() is None or remember) and
2772
other_branch is not None):
2524
if revision is None \
2525
or len(revision) < 1 or revision[0].needs_branch():
2526
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2528
if revision is None or len(revision) < 1:
2531
other = [branch, None]
2534
other = [branch, -1]
2535
other_branch, path = Branch.open_containing(branch)
2538
raise errors.BzrCommandError('Cannot use --uncommitted and'
2539
' --revision at the same time.')
2540
branch = revision[0].get_branch() or branch
2541
if len(revision) == 1:
2543
other_branch, path = Branch.open_containing(branch)
2544
revno = revision[0].in_history(other_branch).revno
2545
other = [branch, revno]
2547
assert len(revision) == 2
2548
if None in revision:
2549
raise errors.BzrCommandError(
2550
"Merge doesn't permit empty revision specifier.")
2551
base_branch, path = Branch.open_containing(branch)
2552
branch1 = revision[1].get_branch() or branch
2553
other_branch, path1 = Branch.open_containing(branch1)
2554
if revision[0].get_branch() is not None:
2555
# then path was obtained from it, and is None.
2558
base = [branch, revision[0].in_history(base_branch).revno]
2559
other = [branch1, revision[1].in_history(other_branch).revno]
2561
if tree.branch.get_parent() is None or remember:
2773
2562
tree.branch.set_parent(other_branch.base)
2564
# pull tags now... it's a bit inconsistent to do it ahead of copying
2565
# the history but that's done inside the merge code
2774
2566
_merge_tags_if_possible(other_branch, tree.branch)
2775
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
2776
other_revision_id, base_revision_id, other_branch, base_branch)
2777
if other_path != '':
2778
allow_pending = False
2779
merger.interesting_files = [other_path]
2569
interesting_files = [path]
2781
allow_pending = True
2782
return merger, allow_pending
2784
def _select_branch_location(self, tree, location, revision=None,
2786
"""Select a branch location, according to possible inputs.
2788
If provided, branches from ``revision`` are preferred. (Both
2789
``revision`` and ``index`` must be supplied.)
2791
Otherwise, the ``location`` parameter is used. If it is None, then the
2792
``parent`` location is used, and a note is printed.
2794
:param tree: The working tree to select a branch for merging into
2795
:param location: The location entered by the user
2796
:param revision: The revision parameter to the command
2797
:param index: The index to use for the revision parameter. Negative
2798
indices are permitted.
2799
:return: (selected_location, default_location). The default location
2800
will be the user-entered location, if any, or else the remembered
2803
if (revision is not None and index is not None
2804
and revision[index] is not None):
2805
branch = revision[index].get_branch()
2806
if branch is not None:
2807
return branch, location
2808
location = self._get_remembered_parent(tree, location, 'Merging from')
2809
return location, location
2571
interesting_files = None
2572
pb = ui.ui_factory.nested_progress_bar()
2575
conflict_count = _merge_helper(
2576
other, base, check_clean=(not force),
2577
merge_type=merge_type,
2578
reprocess=reprocess,
2579
show_base=show_base,
2582
pb=pb, file_list=interesting_files,
2583
change_reporter=change_reporter)
2586
if conflict_count != 0:
2590
except errors.AmbiguousBase, e:
2591
m = ("sorry, bzr can't determine the right merge base yet\n"
2592
"candidates are:\n "
2593
+ "\n ".join(e.bases)
2595
"please specify an explicit base with -r,\n"
2596
"and (if you want) report this to the bzr developers\n")
2811
2599
# TODO: move up to common parent; this isn't merge-specific anymore.
2812
2600
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3042
2810
class cmd_missing(Command):
3043
2811
"""Show unmerged/unpulled revisions between two branches.
3045
2813
OTHER_BRANCH may be local or remote.
3048
_see_also = ['merge', 'pull']
3049
2815
takes_args = ['other_branch?']
3051
Option('reverse', 'Reverse the order of revisions.'),
3053
'Display changes in the local branch only.'),
3054
Option('this' , 'Same as --mine-only.'),
3055
Option('theirs-only',
3056
'Display changes in the remote branch only.'),
3057
Option('other', 'Same as --theirs-only.'),
2816
takes_options = [Option('reverse', 'Reverse the order of revisions'),
2818
'Display changes in the local branch only'),
2819
Option('theirs-only',
2820
'Display changes in the remote branch only'),
3062
2825
encoding_type = 'replace'
3064
2827
@display_command
3065
2828
def run(self, other_branch=None, reverse=False, mine_only=False,
3066
2829
theirs_only=False, log_format=None, long=False, short=False, line=False,
3067
show_ids=False, verbose=False, this=False, other=False):
3068
from bzrlib.missing import find_unmerged, iter_log_revisions
2830
show_ids=False, verbose=False):
2831
from bzrlib.missing import find_unmerged, iter_log_data
3069
2832
from bzrlib.log import log_formatter
3076
2833
local_branch = Branch.open_containing(u".")[0]
3077
2834
parent = local_branch.get_parent()
3078
2835
if other_branch is None:
3079
2836
other_branch = parent
3080
2837
if other_branch is None:
3081
raise errors.BzrCommandError("No peer location known"
2838
raise errors.BzrCommandError("No peer location known or specified.")
3083
2839
display_url = urlutils.unescape_for_display(parent,
3084
2840
self.outf.encoding)
3085
self.outf.write("Using last location: " + display_url + "\n")
2841
print "Using last location: " + display_url
3087
2843
remote_branch = Branch.open(other_branch)
3088
2844
if remote_branch.base == local_branch.base:
3485
3202
takes_options = [
3487
help='Serve on stdin/out for use from inetd or sshd.'),
3204
help='serve on stdin/out for use from inetd or sshd'),
3489
help='Listen for connections on nominated port of the form '
3490
'[hostname:]portnumber. Passing 0 as the port number will '
3491
'result in a dynamically allocated port. The default port is '
3206
help='listen for connections on nominated port of the form '
3207
'[hostname:]portnumber. Passing 0 as the port number will '
3208
'result in a dynamically allocated port. Default port is '
3494
3211
Option('directory',
3495
help='Serve contents of this directory.',
3212
help='serve contents of directory',
3497
3214
Option('allow-writes',
3498
help='By default the server is a readonly server. Supplying '
3215
help='By default the server is a readonly server. Supplying '
3499
3216
'--allow-writes enables write access to the contents of '
3500
'the served directory and below.'
3217
'the served directory and below. '
3504
3221
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3505
from bzrlib.smart import medium, server
3222
from bzrlib.transport import smart
3506
3223
from bzrlib.transport import get_transport
3507
from bzrlib.transport.chroot import ChrootServer
3508
from bzrlib.transport.remote import BZR_DEFAULT_PORT, BZR_DEFAULT_INTERFACE
3509
3224
if directory is None:
3510
3225
directory = os.getcwd()
3511
3226
url = urlutils.local_path_to_url(directory)
3512
3227
if not allow_writes:
3513
3228
url = 'readonly+' + url
3514
chroot_server = ChrootServer(get_transport(url))
3515
chroot_server.setUp()
3516
t = get_transport(chroot_server.get_url())
3229
t = get_transport(url)
3518
smart_server = medium.SmartServerPipeStreamMedium(
3519
sys.stdin, sys.stdout, t)
3231
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3521
host = BZR_DEFAULT_INTERFACE
3522
3233
if port is None:
3523
port = BZR_DEFAULT_PORT
3234
port = smart.BZR_DEFAULT_PORT
3525
3237
if ':' in port:
3526
3238
host, port = port.split(':')
3527
3241
port = int(port)
3528
smart_server = server.SmartTCPServer(t, host=host, port=port)
3529
print 'listening on port: ', smart_server.port
3242
server = smart.SmartTCPServer(t, host=host, port=port)
3243
print 'listening on port: ', server.port
3530
3244
sys.stdout.flush()
3531
# for the duration of this server, no UI output is permitted.
3532
# note that this may cause problems with blackbox tests. This should
3533
# be changed with care though, as we dont want to use bandwidth sending
3534
# progress over stderr to smart server clients!
3535
old_factory = ui.ui_factory
3537
ui.ui_factory = ui.SilentUIFactory()
3538
smart_server.serve()
3540
ui.ui_factory = old_factory
3543
3247
class cmd_join(Command):
3544
3248
"""Combine a subtree into its containing tree.
3644
3346
takes_args = ['submit_branch?', 'public_branch?']
3648
_see_also = ['submit']
3650
3348
takes_options = [
3651
3349
RegistryOption.from_kwargs('patch-type',
3652
3350
'The type of patch to include in the directive',
3654
value_switches=True,
3656
bundle='Bazaar revision bundle (default).',
3657
diff='Normal unified diff.',
3658
plain='No patch, just directive.'),
3659
Option('sign', help='GPG-sign the directive.'), 'revision',
3351
title='Patch type', value_switches=True, enum_switch=False,
3352
bundle='Bazaar revision bundle (default)',
3353
diff='Normal unified diff',
3354
plain='No patch, just directive'),
3355
Option('sign', help='GPG-sign the directive'), 'revision',
3660
3356
Option('mail-to', type=str,
3661
help='Instead of printing the directive, email to this address.'),
3357
help='Instead of printing the directive, email to this address'),
3662
3358
Option('message', type=str, short_name='m',
3663
help='Message to use when committing this merge.')
3359
help='Message to use when committing this merge')
3666
encoding_type = 'exact'
3668
3362
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3669
3363
sign=False, revision=None, mail_to=None, message=None):
3670
from bzrlib.revision import ensure_null, NULL_REVISION
3671
include_patch, include_bundle = {
3672
'plain': (False, False),
3673
'diff': (True, False),
3674
'bundle': (True, True),
3364
if patch_type == 'plain':
3676
3366
branch = Branch.open('.')
3677
3367
stored_submit_branch = branch.get_submit_branch()
3678
3368
if submit_branch is None:
3720
3403
self.outf.writelines(directive.to_lines())
3722
3405
message = directive.to_email(mail_to, branch, sign)
3723
s = SMTPConnection(branch.get_config())
3724
s.send_email(message)
3727
class cmd_submit(Command):
3728
"""Create a merge-directive for submiting changes.
3730
A merge directive provides many things needed for requesting merges:
3731
- A machine-readable description of the merge to perform
3732
- An optional patch that is a preview of the changes requested
3733
- An optional bundle of revision data, so that the changes can be applied
3734
directly from the merge directive, without retrieving data from a
3737
If --no-bundle is specified, then public_branch is needed (and must be
3738
up-to-date), so that the receiver can perform the merge using the
3739
public_branch. The public_branch is always included if known, so that
3740
people can check it later.
3742
The submit branch defaults to the parent, but can be overridden. Both
3743
submit branch and public branch will be remembered if supplied.
3745
If a public_branch is known for the submit_branch, that public submit
3746
branch is used in the merge instructions. This means that a local mirror
3747
can be used as your actual submit branch, once you have set public_branch
3751
encoding_type = 'exact'
3753
aliases = ['bundle', 'bundle-revisions']
3755
_see_also = ['merge']
3757
takes_args = ['submit_branch?', 'public_branch?']
3760
help='Do not include a bundle in the merge directive.'),
3761
Option('no-patch', help='Do not include a preview patch in the merge'
3764
help='Remember submit and public branch.'),
3766
help='Branch to generate the submission from, '
3767
'rather than the one containing the working directory.',
3770
Option('output', short_name='o', help='Write directive to this file.',
3775
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
3776
no_patch=False, revision=None, remember=False, output=None,
3778
from bzrlib.revision import ensure_null, NULL_REVISION
3782
outfile = open(output, 'wb')
3784
from_ = kwargs.get('from', '.')
3785
branch = Branch.open_containing(from_)[0]
3786
if remember and submit_branch is None:
3787
raise errors.BzrCommandError(
3788
'--remember requires a branch to be specified.')
3789
stored_submit_branch = branch.get_submit_branch()
3790
remembered_submit_branch = False
3791
if submit_branch is None:
3792
submit_branch = stored_submit_branch
3793
remembered_submit_branch = True
3795
if stored_submit_branch is None or remember:
3796
branch.set_submit_branch(submit_branch)
3797
if submit_branch is None:
3798
submit_branch = branch.get_parent()
3799
remembered_submit_branch = True
3800
if submit_branch is None:
3801
raise errors.BzrCommandError('No submit branch known or'
3803
if remembered_submit_branch:
3804
note('Using saved location: %s', submit_branch)
3806
stored_public_branch = branch.get_public_branch()
3807
if public_branch is None:
3808
public_branch = stored_public_branch
3809
elif stored_public_branch is None or remember:
3810
branch.set_public_branch(public_branch)
3811
if no_bundle and public_branch is None:
3812
raise errors.BzrCommandError('No public branch specified or'
3814
base_revision_id = None
3815
if revision is not None:
3816
if len(revision) > 2:
3817
raise errors.BzrCommandError('bzr submit takes '
3818
'at most two one revision identifiers')
3819
revision_id = revision[-1].in_history(branch).rev_id
3820
if len(revision) == 2:
3821
base_revision_id = revision[0].in_history(branch).rev_id
3822
base_revision_id = ensure_null(base_revision_id)
3824
revision_id = branch.last_revision()
3825
revision_id = ensure_null(revision_id)
3826
if revision_id == NULL_REVISION:
3827
raise errors.BzrCommandError('No revisions to submit.')
3828
directive = merge_directive.MergeDirective2.from_objects(
3829
branch.repository, revision_id, time.time(),
3830
osutils.local_time_offset(), submit_branch,
3831
public_branch=public_branch, include_patch=not no_patch,
3832
include_bundle=not no_bundle, message=None,
3833
base_revision_id=base_revision_id)
3834
outfile.writelines(directive.to_lines())
3836
if output is not None:
3407
server = branch.get_config().get_user_option('smtp_server')
3409
server = 'localhost'
3411
s.sendmail(message['From'], message['To'], message.as_string())
3839
3414
class cmd_tag(Command):
3840
3415
"""Create a tag naming a revision.
3920
3493
self.outf.write('%-20s %s\n' % (tag_name, target))
3923
def _create_prefix(cur_transport):
3924
needed = [cur_transport]
3925
# Recurse upwards until we can create a directory successfully
3927
new_transport = cur_transport.clone('..')
3928
if new_transport.base == cur_transport.base:
3929
raise errors.BzrCommandError(
3930
"Failed to create path prefix for %s."
3931
% cur_transport.base)
3933
new_transport.mkdir('.')
3934
except errors.NoSuchFile:
3935
needed.append(new_transport)
3936
cur_transport = new_transport
3939
# Now we only need to create child directories
3941
cur_transport = needed.pop()
3942
cur_transport.ensure_base()
3945
def _get_mergeable_helper(location):
3946
"""Get a merge directive or bundle if 'location' points to one.
3948
Try try to identify a bundle and returns its mergeable form. If it's not,
3949
we return the tried transport anyway so that it can reused to access the
3952
:param location: can point to a bundle or a branch.
3954
:return: mergeable, transport
3496
# command-line interpretation helper for merge-related commands
3497
def _merge_helper(other_revision, base_revision,
3498
check_clean=True, ignore_zero=False,
3499
this_dir=None, backup_files=False,
3501
file_list=None, show_base=False, reprocess=False,
3504
change_reporter=None):
3505
"""Merge changes into a tree.
3508
list(path, revno) Base for three-way merge.
3509
If [None, None] then a base will be automatically determined.
3511
list(path, revno) Other revision for three-way merge.
3513
Directory to merge changes into; '.' by default.
3515
If true, this_dir must have no uncommitted changes before the
3517
ignore_zero - If true, suppress the "zero conflicts" message when
3518
there are no conflicts; should be set when doing something we expect
3519
to complete perfectly.
3520
file_list - If supplied, merge only changes to selected files.
3522
All available ancestors of other_revision and base_revision are
3523
automatically pulled into the branch.
3525
The revno may be -1 to indicate the last revision on the branch, which is
3528
This function is intended for use from the command line; programmatic
3529
clients might prefer to call merge.merge_inner(), which has less magic
3957
url = urlutils.normalize_url(location)
3958
url, filename = urlutils.split(url, exclude_trailing_slash=False)
3959
location_transport = transport.get_transport(url)
3962
# There may be redirections but we ignore the intermediate
3963
# and final transports used
3964
read = bundle.read_mergeable_from_transport
3965
mergeable, t = read(location_transport, filename)
3966
except errors.NotABundle:
3967
# Continue on considering this url a Branch but adjust the
3968
# location_transport
3969
location_transport = location_transport.clone(filename)
3970
return mergeable, location_transport
3532
# Loading it late, so that we don't always have to import bzrlib.merge
3533
if merge_type is None:
3534
merge_type = _mod_merge.Merge3Merger
3535
if this_dir is None:
3537
this_tree = WorkingTree.open_containing(this_dir)[0]
3538
if show_base and not merge_type is _mod_merge.Merge3Merger:
3539
raise errors.BzrCommandError("Show-base is not supported for this merge"
3540
" type. %s" % merge_type)
3541
if reprocess and not merge_type.supports_reprocess:
3542
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3543
" type %s." % merge_type)
3544
if reprocess and show_base:
3545
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3546
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3547
# only want to take out a lock_tree_write() if we don't have to pull
3548
# any ancestry. But merge might fetch ancestry in the middle, in
3549
# which case we would need a lock_write().
3550
# Because we cannot upgrade locks, for now we live with the fact that
3551
# the tree will be locked multiple times during a merge. (Maybe
3552
# read-only some of the time, but it means things will get read
3555
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3556
pb=pb, change_reporter=change_reporter)
3557
merger.pp = ProgressPhase("Merge phase", 5, pb)
3558
merger.pp.next_phase()
3559
merger.check_basis(check_clean)
3560
merger.set_other(other_revision)
3561
merger.pp.next_phase()
3562
merger.set_base(base_revision)
3563
if merger.base_rev_id == merger.other_rev_id:
3564
note('Nothing to do.')
3566
if file_list is None:
3567
if pull and merger.base_rev_id == merger.this_rev_id:
3568
# FIXME: deduplicate with pull
3569
result = merger.this_tree.pull(merger.this_branch,
3570
False, merger.other_rev_id)
3571
if result.old_revid == result.new_revid:
3572
note('No revisions to pull.')
3574
note('Now on revision %d.' % result.new_revno)
3576
merger.backup_files = backup_files
3577
merger.merge_type = merge_type
3578
merger.set_interesting_files(file_list)
3579
merger.show_base = show_base
3580
merger.reprocess = reprocess
3581
conflicts = merger.do_merge()
3582
if file_list is None:
3583
merger.set_pending()
3590
merge = _merge_helper
3973
3593
# these get imported and then picked up by the scan for cmd_*