539
719
location can be accessed.
542
takes_options = ['remember', 'overwrite', 'verbose',
543
Option('create-prefix',
544
help='Create the path leading up to the branch '
545
'if it does not already exist')]
722
_see_also = ['pull', 'update', 'working-trees']
723
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
724
Option('create-prefix',
725
help='Create the path leading up to the branch '
726
'if it does not already exist.'),
728
help='Branch to push from, '
729
'rather than the one containing the working directory.',
733
Option('use-existing-dir',
734
help='By default push will fail if the target'
735
' directory exists, but does not already'
736
' have a control directory. This flag will'
737
' allow push to proceed.'),
739
help='Create a stacked branch that references the public location '
740
'of the parent branch.'),
742
help='Create a stacked branch that refers to another branch '
743
'for the commit history. Only the work not present in the '
744
'referenced branch is included in the branch created.',
546
747
takes_args = ['location?']
547
748
encoding_type = 'replace'
549
750
def run(self, location=None, remember=False, overwrite=False,
550
create_prefix=False, verbose=False):
551
# FIXME: Way too big! Put this into a function called from the
554
br_from = Branch.open_containing('.')[0]
555
stored_loc = br_from.get_push_location()
751
create_prefix=False, verbose=False, revision=None,
752
use_existing_dir=False, directory=None, stacked_on=None,
754
from bzrlib.push import _show_push_branch
756
# Get the source branch and revision_id
757
if directory is None:
759
br_from = Branch.open_containing(directory)[0]
760
if revision is not None:
761
if len(revision) == 1:
762
revision_id = revision[0].in_history(br_from).rev_id
764
raise errors.BzrCommandError(
765
'bzr push --revision takes one value.')
767
revision_id = br_from.last_revision()
769
# Get the stacked_on branch, if any
770
if stacked_on is not None:
771
stacked_on = urlutils.normalize_url(stacked_on)
773
parent_url = br_from.get_parent()
775
parent = Branch.open(parent_url)
776
stacked_on = parent.get_public_branch()
778
# I considered excluding non-http url's here, thus forcing
779
# 'public' branches only, but that only works for some
780
# users, so it's best to just depend on the user spotting an
781
# error by the feedback given to them. RBC 20080227.
782
stacked_on = parent_url
784
raise errors.BzrCommandError(
785
"Could not determine branch to refer to.")
787
# Get the destination location
556
788
if location is None:
789
stored_loc = br_from.get_push_location()
557
790
if stored_loc is None:
558
raise BzrCommandError("No push location known or specified.")
791
raise errors.BzrCommandError(
792
"No push location known or specified.")
560
794
display_url = urlutils.unescape_for_display(stored_loc,
561
795
self.outf.encoding)
562
796
self.outf.write("Using saved location: %s\n" % display_url)
563
797
location = stored_loc
565
to_transport = transport.get_transport(location)
566
location_url = to_transport.base
570
dir_to = bzrdir.BzrDir.open(location_url)
571
br_to = dir_to.open_branch()
572
except NotBranchError:
574
to_transport = to_transport.clone('..')
575
if not create_prefix:
577
relurl = to_transport.relpath(location_url)
578
mutter('creating directory %s => %s', location_url, relurl)
579
to_transport.mkdir(relurl)
581
raise BzrCommandError("Parent directory of %s "
582
"does not exist." % location)
584
current = to_transport.base
585
needed = [(to_transport, to_transport.relpath(location_url))]
588
to_transport, relpath = needed[-1]
589
to_transport.mkdir(relpath)
592
new_transport = to_transport.clone('..')
593
needed.append((new_transport,
594
new_transport.relpath(to_transport.base)))
595
if new_transport.base == to_transport.base:
596
raise BzrCommandError("Could not create "
598
dir_to = br_from.bzrdir.clone(location_url,
599
revision_id=br_from.last_revision())
600
br_to = dir_to.open_branch()
601
count = len(br_to.revision_history())
602
# We successfully created the target, remember it
603
if br_from.get_push_location() is None or remember:
604
br_from.set_push_location(br_to.base)
606
# We were able to connect to the remote location, so remember it
607
# we don't need to successfully push because of possible divergence.
608
if br_from.get_push_location() is None or remember:
609
br_from.set_push_location(br_to.base)
610
old_rh = br_to.revision_history()
613
tree_to = dir_to.open_workingtree()
614
except errors.NotLocalUrl:
615
warning('This transport does not update the working '
616
'tree of: %s' % (br_to.base,))
617
count = br_to.pull(br_from, overwrite)
618
except NoWorkingTree:
619
count = br_to.pull(br_from, overwrite)
621
count = tree_to.pull(br_from, overwrite)
622
except DivergedBranches:
623
raise BzrCommandError("These branches have diverged."
624
" Try a merge then push with overwrite.")
625
note('%d revision(s) pushed.' % (count,))
628
new_rh = br_to.revision_history()
631
from bzrlib.log import show_changed_revisions
632
show_changed_revisions(br_to, old_rh, new_rh,
799
_show_push_branch(br_from, revision_id, location, self.outf,
800
verbose=verbose, overwrite=overwrite, remember=remember,
801
stacked_on=stacked_on, create_prefix=create_prefix,
802
use_existing_dir=use_existing_dir)
636
805
class cmd_branch(Command):
1070
1312
# Just using os.mkdir, since I don't
1071
1313
# believe that we want to create a bunch of
1072
1314
# locations if the user supplies an extended path
1073
# TODO: create-prefix
1075
to_transport.mkdir('.')
1076
except errors.FileExists:
1080
existing_bzrdir = bzrdir.BzrDir.open(location)
1081
except NotBranchError:
1316
to_transport.ensure_base()
1317
except errors.NoSuchFile:
1318
if not create_prefix:
1319
raise errors.BzrCommandError("Parent directory of %s"
1321
"\nYou may supply --create-prefix to create all"
1322
" leading parent directories."
1324
_create_prefix(to_transport)
1327
existing_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1328
except errors.NotBranchError:
1082
1329
# really a NotBzrDir error...
1083
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1330
create_branch = bzrdir.BzrDir.create_branch_convenience
1331
branch = create_branch(to_transport.base, format=format,
1332
possible_transports=[to_transport])
1334
from bzrlib.transport.local import LocalTransport
1085
1335
if existing_bzrdir.has_branch():
1086
1336
if (isinstance(to_transport, LocalTransport)
1087
1337
and not existing_bzrdir.has_workingtree()):
1088
1338
raise errors.BranchExistsWithoutWorkingTree(location)
1089
1339
raise errors.AlreadyBranchError(location)
1091
existing_bzrdir.create_branch()
1341
branch = existing_bzrdir.create_branch()
1092
1342
existing_bzrdir.create_workingtree()
1343
if append_revisions_only:
1345
branch.set_append_revisions_only(True)
1346
except errors.UpgradeRequired:
1347
raise errors.BzrCommandError('This branch format cannot be set'
1348
' to append-revisions-only. Try --experimental-branch6')
1350
from bzrlib.info import show_bzrdir_info
1351
show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
1352
to_transport)[0], verbose=0, outfile=self.outf)
1095
1355
class cmd_init_repository(Command):
1096
1356
"""Create a shared repository to hold branches.
1098
New branches created under the repository directory will store their revisions
1099
in the repository, not in the branch directory, if the branch format supports
1105
bzr checkout --lightweight repo/trunk trunk-checkout
1358
New branches created under the repository directory will store their
1359
revisions in the repository, not in the branch directory.
1361
If the --no-trees option is used then the branches in the repository
1362
will not have working trees by default.
1365
Create a shared repositories holding just branches::
1367
bzr init-repo --no-trees repo
1370
Make a lightweight checkout elsewhere::
1372
bzr checkout --lightweight repo/trunk trunk-checkout
1109
takes_args = ["location"]
1110
takes_options = [Option('format',
1111
help='Specify a format for this repository.'
1112
' Current formats are: default, knit,'
1113
' metaweave and weave. Default is knit;'
1114
' metaweave and weave are deprecated',
1115
type=get_format_type),
1117
help='Allows branches in repository to have'
1377
_see_also = ['init', 'branch', 'checkout', 'repositories']
1378
takes_args = ["location"]
1379
takes_options = [RegistryOption('format',
1380
help='Specify a format for this repository. See'
1381
' "bzr help formats" for details.',
1382
registry=bzrdir.format_registry,
1383
converter=bzrdir.format_registry.make_bzrdir,
1384
value_switches=True, title='Repository format'),
1386
help='Branches in the repository will default to'
1387
' not having a working tree.'),
1119
1389
aliases = ["init-repo"]
1120
def run(self, location, format=None, trees=False):
1391
def run(self, location, format=None, no_trees=False):
1121
1392
if format is None:
1122
format = get_format_type('default')
1393
format = bzrdir.format_registry.make_bzrdir('default')
1124
1395
if location is None:
1127
1398
to_transport = transport.get_transport(location)
1129
to_transport.mkdir('.')
1130
except errors.FileExists:
1399
to_transport.ensure_base()
1133
1401
newdir = format.initialize_on_transport(to_transport)
1134
1402
repo = newdir.create_repository(shared=True)
1135
repo.set_make_working_trees(trees)
1403
repo.set_make_working_trees(not no_trees)
1405
from bzrlib.info import show_bzrdir_info
1406
show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
1407
to_transport)[0], verbose=0, outfile=self.outf)
1138
1410
class cmd_diff(Command):
1139
"""Show differences in the working tree or between revisions.
1411
"""Show differences in the working tree, between revisions or branches.
1141
If files are listed, only the changes in those files are listed.
1142
Otherwise, all changes for the tree are listed.
1413
If no arguments are given, all changes for the current tree are listed.
1414
If files are given, only the changes in those files are listed.
1415
Remote and multiple branches can be compared by using the --old and
1416
--new options. If not provided, the default for both is derived from
1417
the first argument, if any, or the current tree if no arguments are
1144
1420
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1145
1421
produces patches suitable for "patch -p1".
1149
Shows the difference in the working tree versus the last commit
1151
Difference between the working tree and revision 1
1153
Difference between revision 2 and revision 1
1154
bzr diff --diff-prefix old/:new/
1155
Same as 'bzr diff' but prefix paths with old/ and new/
1156
bzr diff bzr.mine bzr.dev
1157
Show the differences between the two working trees
1159
Show just the differences for 'foo.c'
1425
2 - unrepresentable changes
1430
Shows the difference in the working tree versus the last commit::
1434
Difference between the working tree and revision 1::
1438
Difference between revision 2 and revision 1::
1442
Difference between revision 2 and revision 1 for branch xxx::
1446
Show just the differences for file NEWS::
1450
Show the differences in working tree xxx for file NEWS::
1454
Show the differences from branch xxx to this working tree:
1458
Show the differences between two branches for file NEWS::
1460
bzr diff --old xxx --new yyy NEWS
1462
Same as 'bzr diff' but prefix paths with old/ and new/::
1464
bzr diff --prefix old/:new/
1161
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1162
# or a graphical diff.
1164
# TODO: Python difflib is not exactly the same as unidiff; should
1165
# either fix it up or prefer to use an external diff.
1167
# TODO: Selected-file diff is inefficient and doesn't show you
1170
# TODO: This probably handles non-Unix newlines poorly.
1466
_see_also = ['status']
1172
1467
takes_args = ['file*']
1173
takes_options = ['revision', 'diff-options', 'prefix']
1469
Option('diff-options', type=str,
1470
help='Pass these options to the external diff program.'),
1471
Option('prefix', type=str,
1473
help='Set prefixes added to old and new filenames, as '
1474
'two values separated by a colon. (eg "old/:new/").'),
1476
help='Branch/tree to compare from.',
1480
help='Branch/tree to compare to.',
1486
help='Use this command to compare files.',
1174
1490
aliases = ['di', 'dif']
1175
1491
encoding_type = 'exact'
1177
1493
@display_command
1178
1494
def run(self, revision=None, file_list=None, diff_options=None,
1180
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1495
prefix=None, old=None, new=None, using=None):
1496
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1182
1498
if (prefix is None) or (prefix == '0'):
1183
1499
# diff -p0 format
1767
2296
# selected-file merge commit is not done yet
1768
2297
selected_list = []
2301
bug_property = self._get_bug_fix_properties(fixes, tree.branch)
2303
properties['bugs'] = bug_property
1770
2305
if local and not tree.branch.get_bound_location():
1771
2306
raise errors.LocalRequiresBoundBranch()
1772
if message is None and not file:
1773
template = make_commit_message_template(tree, selected_list)
1774
message = edit_commit_message(template)
1776
raise BzrCommandError("please specify a commit message"
1777
" with either --message or --file")
1778
elif message and file:
1779
raise BzrCommandError("please specify either --message or --file")
1782
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1785
raise BzrCommandError("empty commit message specified")
1788
reporter = ReportCommitToLog()
1790
reporter = NullCommitReporter()
2308
def get_message(commit_obj):
2309
"""Callback to get commit message"""
2310
my_message = message
2311
if my_message is None and not file:
2312
t = make_commit_message_template_encoded(tree,
2313
selected_list, diff=show_diff,
2314
output_encoding=bzrlib.user_encoding)
2315
my_message = edit_commit_message_encoded(t)
2316
if my_message is None:
2317
raise errors.BzrCommandError("please specify a commit"
2318
" message with either --message or --file")
2319
elif my_message and file:
2320
raise errors.BzrCommandError(
2321
"please specify either --message or --file")
2323
my_message = codecs.open(file, 'rt',
2324
bzrlib.user_encoding).read()
2325
if my_message == "":
2326
raise errors.BzrCommandError("empty commit message specified")
1793
tree.commit(message, specific_files=selected_list,
2330
tree.commit(message_callback=get_message,
2331
specific_files=selected_list,
1794
2332
allow_pointless=unchanged, strict=strict, local=local,
2333
reporter=None, verbose=verbose, revprops=properties,
2335
exclude=safe_relpath_files(tree, exclude))
1796
2336
except PointlessCommit:
1797
2337
# FIXME: This should really happen before the file is read in;
1798
2338
# perhaps prepare the commit; get the message; then actually commit
1799
raise BzrCommandError("no changes to commit."
1800
" use --unchanged to commit anyhow")
2339
raise errors.BzrCommandError("no changes to commit."
2340
" use --unchanged to commit anyhow")
1801
2341
except ConflictsInTree:
1802
raise BzrCommandError("Conflicts detected in working tree. "
1803
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
2342
raise errors.BzrCommandError('Conflicts detected in working '
2343
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1804
2345
except StrictCommitFailed:
1805
raise BzrCommandError("Commit refused because there are unknown "
1806
"files in the working tree.")
2346
raise errors.BzrCommandError("Commit refused because there are"
2347
" unknown files in the working tree.")
1807
2348
except errors.BoundBranchOutOfDate, e:
1808
raise BzrCommandError(str(e) + "\n"
1809
'To commit to master branch, run update and then commit.\n'
1810
'You can also pass --local to commit to continue working '
2349
raise errors.BzrCommandError(str(e) + "\n"
2350
'To commit to master branch, run update and then commit.\n'
2351
'You can also pass --local to commit to continue working '
1813
2355
class cmd_check(Command):
1814
"""Validate consistency of branch history.
1816
This command checks various invariants about the branch storage to
1817
detect data corruption or bzr bugs.
2356
"""Validate working tree structure, branch consistency and repository history.
2358
This command checks various invariants about branch and repository storage
2359
to detect data corruption or bzr bugs.
2361
The working tree and branch checks will only give output if a problem is
2362
detected. The output fields of the repository check are:
2364
revisions: This is just the number of revisions checked. It doesn't
2366
versionedfiles: This is just the number of versionedfiles checked. It
2367
doesn't indicate a problem.
2368
unreferenced ancestors: Texts that are ancestors of other texts, but
2369
are not properly referenced by the revision ancestry. This is a
2370
subtle problem that Bazaar can work around.
2371
unique file texts: This is the total number of unique file contents
2372
seen in the checked revisions. It does not indicate a problem.
2373
repeated file texts: This is the total number of repeated texts seen
2374
in the checked revisions. Texts can be repeated when their file
2375
entries are modified, but the file contents are not. It does not
2378
If no restrictions are specified, all Bazaar data that is found at the given
2379
location will be checked.
2383
Check the tree and branch at 'foo'::
2385
bzr check --tree --branch foo
2387
Check only the repository at 'bar'::
2389
bzr check --repo bar
2391
Check everything at 'baz'::
1819
takes_args = ['branch?']
1820
takes_options = ['verbose']
1822
def run(self, branch=None, verbose=False):
1823
from bzrlib.check import check
1825
tree = WorkingTree.open_containing()[0]
1826
branch = tree.branch
1828
branch = Branch.open(branch)
1829
check(branch, verbose)
1832
class cmd_scan_cache(Command):
1835
from bzrlib.hashcache import HashCache
1841
print '%6d stats' % c.stat_count
1842
print '%6d in hashcache' % len(c._cache)
1843
print '%6d files removed from cache' % c.removed_count
1844
print '%6d hashes updated' % c.update_count
1845
print '%6d files changed too recently to cache' % c.danger_count
2396
_see_also = ['reconcile']
2397
takes_args = ['path?']
2398
takes_options = ['verbose',
2399
Option('branch', help="Check the branch related to the"
2400
" current directory."),
2401
Option('repo', help="Check the repository related to the"
2402
" current directory."),
2403
Option('tree', help="Check the working tree related to"
2404
" the current directory.")]
2406
def run(self, path=None, verbose=False, branch=False, repo=False,
2408
from bzrlib.check import check_dwim
2411
if not branch and not repo and not tree:
2412
branch = repo = tree = True
2413
check_dwim(path, verbose, do_branch=branch, do_repo=repo, do_tree=tree)
1851
2416
class cmd_upgrade(Command):
1974
2638
return FakeNFSServer
1975
2639
msg = "No known transport type %s. Supported types are: sftp\n" %\
1977
raise BzrCommandError(msg)
2641
raise errors.BzrCommandError(msg)
1980
2644
takes_args = ['testspecs*']
1981
2645
takes_options = ['verbose',
1982
Option('one', help='stop when one test fails'),
1983
Option('keep-output',
1984
help='keep output directories when tests fail'),
2647
help='Stop when one test fails.',
1986
2651
help='Use a different transport by default '
1987
2652
'throughout the test suite.',
1988
2653
type=get_transport_type),
1989
Option('benchmark', help='run the bzr bencharks.'),
2655
help='Run the benchmarks rather than selftests.'),
1990
2656
Option('lsprof-timed',
1991
help='generate lsprof output for benchmarked'
2657
help='Generate lsprof output for benchmarked'
1992
2658
' sections of code.'),
1993
2659
Option('cache-dir', type=str,
1994
help='a directory to cache intermediate'
1995
' benchmark steps'),
2660
help='Cache intermediate benchmark output in this '
2663
help='Run all tests, but run specified tests first.',
2667
help='List the tests instead of running them.'),
2668
Option('randomize', type=str, argname="SEED",
2669
help='Randomize the order of tests using the given'
2670
' seed or "now" for the current time.'),
2671
Option('exclude', type=str, argname="PATTERN",
2673
help='Exclude tests that match this regular'
2675
Option('strict', help='Fail on missing dependencies or '
2677
Option('load-list', type=str, argname='TESTLISTFILE',
2678
help='Load a test id list from a text file.'),
2679
ListOption('debugflag', type=str, short_name='E',
2680
help='Turn on a selftest debug flag.'),
2681
Option('starting-with', type=str, argname='TESTID',
2683
help='Load only the tests starting with TESTID.'),
2685
encoding_type = 'replace'
1998
def run(self, testspecs_list=None, verbose=None, one=False,
1999
keep_output=False, transport=None, benchmark=None,
2000
lsprof_timed=None, cache_dir=None):
2687
def run(self, testspecs_list=None, verbose=False, one=False,
2688
transport=None, benchmark=None,
2689
lsprof_timed=None, cache_dir=None,
2690
first=False, list_only=False,
2691
randomize=None, exclude=None, strict=False,
2692
load_list=None, debugflag=None, starting_with=None):
2001
2693
import bzrlib.ui
2002
2694
from bzrlib.tests import selftest
2003
2695
import bzrlib.benchmarks as benchmarks
2004
2696
from bzrlib.benchmarks import tree_creator
2698
# Make deprecation warnings visible, unless -Werror is set
2699
symbol_versioning.activate_deprecation_warnings(override=False)
2006
2701
if cache_dir is not None:
2007
2702
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2008
# we don't want progress meters from the tests to go to the
2009
# real output; and we don't want log messages cluttering up
2011
save_ui = ui.ui_factory
2012
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2013
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
2704
print 'testing: %s' % (osutils.realpath(sys.argv[0]),)
2705
print ' %s (%s python%s)' % (
2707
bzrlib.version_string,
2708
bzrlib._format_version_tuple(sys.version_info),
2015
info('running tests...')
2711
if testspecs_list is not None:
2712
pattern = '|'.join(testspecs_list)
2716
test_suite_factory = benchmarks.test_suite
2717
# Unless user explicitly asks for quiet, be verbose in benchmarks
2718
verbose = not is_quiet()
2719
# TODO: should possibly lock the history file...
2720
benchfile = open(".perf_history", "at", buffering=1)
2722
test_suite_factory = None
2017
ui.ui_factory = ui.SilentUIFactory()
2018
if testspecs_list is not None:
2019
pattern = '|'.join(testspecs_list)
2023
test_suite_factory = benchmarks.test_suite
2026
benchfile = open(".perf_history", "at")
2028
test_suite_factory = None
2033
result = selftest(verbose=verbose,
2035
stop_on_failure=one,
2036
keep_output=keep_output,
2037
transport=transport,
2038
test_suite_factory=test_suite_factory,
2039
lsprof_timed=lsprof_timed,
2040
bench_history=benchfile)
2042
if benchfile is not None:
2045
info('tests passed')
2047
info('tests failed')
2048
return int(not result)
2725
result = selftest(verbose=verbose,
2727
stop_on_failure=one,
2728
transport=transport,
2729
test_suite_factory=test_suite_factory,
2730
lsprof_timed=lsprof_timed,
2731
bench_history=benchfile,
2732
matching_tests_first=first,
2733
list_only=list_only,
2734
random_seed=randomize,
2735
exclude_pattern=exclude,
2737
load_list=load_list,
2738
debug_flags=debugflag,
2739
starting_with=starting_with,
2050
ui.ui_factory = save_ui
2742
if benchfile is not None:
2745
note('tests passed')
2747
note('tests failed')
2748
return int(not result)
2053
2751
class cmd_version(Command):
2054
2752
"""Show version of bzr."""
2754
encoding_type = 'replace'
2756
Option("short", help="Print just the version number."),
2056
2759
@display_command
2760
def run(self, short=False):
2058
2761
from bzrlib.version import show_version
2763
self.outf.write(bzrlib.version_string + '\n')
2765
show_version(to_file=self.outf)
2062
2768
class cmd_rocks(Command):
2122
2836
default, use --remember. The value will only be saved if the remote
2123
2837
location can be accessed.
2127
To merge the latest revision from bzr.dev
2128
bzr merge ../bzr.dev
2130
To merge changes up to and including revision 82 from bzr.dev
2131
bzr merge -r 82 ../bzr.dev
2133
To merge the changes introduced by 82, without previous changes:
2134
bzr merge -r 81..82 ../bzr.dev
2839
The results of the merge are placed into the destination working
2840
directory, where they can be reviewed (with bzr diff), tested, and then
2841
committed to record the result of the merge.
2136
2843
merge refuses to run if there are any uncommitted changes, unless
2137
2844
--force is given.
2139
The following merge types are available:
2847
To merge the latest revision from bzr.dev::
2849
bzr merge ../bzr.dev
2851
To merge changes up to and including revision 82 from bzr.dev::
2853
bzr merge -r 82 ../bzr.dev
2855
To merge the changes introduced by 82, without previous changes::
2857
bzr merge -r 81..82 ../bzr.dev
2859
To apply a merge directive contained in in /tmp/merge:
2861
bzr merge /tmp/merge
2141
takes_args = ['branch?']
2142
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2143
Option('show-base', help="Show base revision text in "
2145
Option('uncommitted', help='Apply uncommitted changes'
2146
' from a working copy, instead of branch changes')]
2149
from merge import merge_type_help
2150
from inspect import getdoc
2151
return getdoc(self) + '\n' + merge_type_help()
2153
def run(self, branch=None, revision=None, force=False, merge_type=None,
2154
show_base=False, reprocess=False, remember=False,
2864
encoding_type = 'exact'
2865
_see_also = ['update', 'remerge', 'status-flags']
2866
takes_args = ['location?']
2871
help='Merge even if the destination tree has uncommitted changes.'),
2875
Option('show-base', help="Show base revision text in "
2877
Option('uncommitted', help='Apply uncommitted changes'
2878
' from a working copy, instead of branch changes.'),
2879
Option('pull', help='If the destination is already'
2880
' completely merged into the source, pull from the'
2881
' source rather than merging. When this happens,'
2882
' you do not need to commit the result.'),
2884
help='Branch to merge into, '
2885
'rather than the one containing the working directory.',
2889
Option('preview', help='Instead of merging, show a diff of the merge.')
2892
def run(self, location=None, revision=None, force=False,
2893
merge_type=None, show_base=False, reprocess=False, remember=False,
2894
uncommitted=False, pull=False,
2156
2898
if merge_type is None:
2157
merge_type = Merge3Merger
2159
tree = WorkingTree.open_containing(u'.')[0]
2161
if branch is not None:
2163
reader = bundle.read_bundle_from_url(branch)
2165
pass # Continue on considering this url a Branch
2167
conflicts = merge_bundle(reader, tree, not force, merge_type,
2168
reprocess, show_base)
2899
merge_type = _mod_merge.Merge3Merger
2901
if directory is None: directory = u'.'
2902
possible_transports = []
2904
allow_pending = True
2905
verified = 'inapplicable'
2906
tree = WorkingTree.open_containing(directory)[0]
2907
change_reporter = delta._ChangeReporter(
2908
unversioned_filter=tree.is_ignored)
2911
pb = ui.ui_factory.nested_progress_bar()
2912
cleanups.append(pb.finished)
2914
cleanups.append(tree.unlock)
2915
if location is not None:
2917
mergeable = bundle.read_mergeable_from_url(location,
2918
possible_transports=possible_transports)
2919
except errors.NotABundle:
2174
if revision is None \
2175
or len(revision) < 1 or revision[0].needs_branch():
2176
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2178
if revision is None or len(revision) < 1:
2181
other = [branch, None]
2184
other = [branch, -1]
2185
other_branch, path = Branch.open_containing(branch)
2188
raise BzrCommandError('Cannot use --uncommitted and --revision'
2189
' at the same time.')
2190
branch = revision[0].get_branch() or branch
2191
if len(revision) == 1:
2193
other_branch, path = Branch.open_containing(branch)
2194
revno = revision[0].in_history(other_branch).revno
2195
other = [branch, revno]
2197
assert len(revision) == 2
2198
if None in revision:
2199
raise BzrCommandError(
2200
"Merge doesn't permit empty revision specifier.")
2201
base_branch, path = Branch.open_containing(branch)
2202
branch1 = revision[1].get_branch() or branch
2203
other_branch, path1 = Branch.open_containing(branch1)
2204
if revision[0].get_branch() is not None:
2205
# then path was obtained from it, and is None.
2208
base = [branch, revision[0].in_history(base_branch).revno]
2209
other = [branch1, revision[1].in_history(other_branch).revno]
2211
if tree.branch.get_parent() is None or remember:
2212
tree.branch.set_parent(other_branch.base)
2215
interesting_files = [path]
2217
interesting_files = None
2218
pb = ui.ui_factory.nested_progress_bar()
2221
conflict_count = merge(other, base, check_clean=(not force),
2222
merge_type=merge_type,
2223
reprocess=reprocess,
2224
show_base=show_base,
2225
pb=pb, file_list=interesting_files)
2228
if conflict_count != 0:
2923
raise errors.BzrCommandError('Cannot use --uncommitted'
2924
' with bundles or merge directives.')
2926
if revision is not None:
2927
raise errors.BzrCommandError(
2928
'Cannot use -r with merge directives or bundles')
2929
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2932
if merger is None and uncommitted:
2933
if revision is not None and len(revision) > 0:
2934
raise errors.BzrCommandError('Cannot use --uncommitted and'
2935
' --revision at the same time.')
2936
location = self._select_branch_location(tree, location)[0]
2937
other_tree, other_path = WorkingTree.open_containing(location)
2938
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2940
allow_pending = False
2941
if other_path != '':
2942
merger.interesting_files = [other_path]
2945
merger, allow_pending = self._get_merger_from_branch(tree,
2946
location, revision, remember, possible_transports, pb)
2948
merger.merge_type = merge_type
2949
merger.reprocess = reprocess
2950
merger.show_base = show_base
2951
self.sanity_check_merger(merger)
2952
if (merger.base_rev_id == merger.other_rev_id and
2953
merger.other_rev_id is not None):
2954
note('Nothing to do.')
2232
except errors.AmbiguousBase, e:
2233
m = ("sorry, bzr can't determine the right merge base yet\n"
2234
"candidates are:\n "
2235
+ "\n ".join(e.bases)
2237
"please specify an explicit base with -r,\n"
2238
"and (if you want) report this to the bzr developers\n")
2241
# TODO: move up to common parent; this isn't merge-specific anymore.
2242
def _get_remembered_parent(self, tree, supplied_location, verb_string):
2957
if merger.interesting_files is not None:
2958
raise errors.BzrCommandError('Cannot pull individual files')
2959
if (merger.base_rev_id == tree.last_revision()):
2960
result = tree.pull(merger.other_branch, False,
2961
merger.other_rev_id)
2962
result.report(self.outf)
2964
merger.check_basis(not force)
2966
return self._do_preview(merger)
2968
return self._do_merge(merger, change_reporter, allow_pending,
2971
for cleanup in reversed(cleanups):
2974
def _do_preview(self, merger):
2975
from bzrlib.diff import show_diff_trees
2976
tree_merger = merger.make_merger()
2977
tt = tree_merger.make_preview_transform()
2979
result_tree = tt.get_preview_tree()
2980
show_diff_trees(merger.this_tree, result_tree, self.outf,
2981
old_label='', new_label='')
2985
def _do_merge(self, merger, change_reporter, allow_pending, verified):
2986
merger.change_reporter = change_reporter
2987
conflict_count = merger.do_merge()
2989
merger.set_pending()
2990
if verified == 'failed':
2991
warning('Preview patch does not match changes')
2992
if conflict_count != 0:
2997
def sanity_check_merger(self, merger):
2998
if (merger.show_base and
2999
not merger.merge_type is _mod_merge.Merge3Merger):
3000
raise errors.BzrCommandError("Show-base is not supported for this"
3001
" merge type. %s" % merger.merge_type)
3002
if merger.reprocess and not merger.merge_type.supports_reprocess:
3003
raise errors.BzrCommandError("Conflict reduction is not supported"
3004
" for merge type %s." %
3006
if merger.reprocess and merger.show_base:
3007
raise errors.BzrCommandError("Cannot do conflict reduction and"
3010
def _get_merger_from_branch(self, tree, location, revision, remember,
3011
possible_transports, pb):
3012
"""Produce a merger from a location, assuming it refers to a branch."""
3013
from bzrlib.tag import _merge_tags_if_possible
3014
# find the branch locations
3015
other_loc, user_location = self._select_branch_location(tree, location,
3017
if revision is not None and len(revision) == 2:
3018
base_loc, _unused = self._select_branch_location(tree,
3019
location, revision, 0)
3021
base_loc = other_loc
3023
other_branch, other_path = Branch.open_containing(other_loc,
3024
possible_transports)
3025
if base_loc == other_loc:
3026
base_branch = other_branch
3028
base_branch, base_path = Branch.open_containing(base_loc,
3029
possible_transports)
3030
# Find the revision ids
3031
if revision is None or len(revision) < 1 or revision[-1] is None:
3032
other_revision_id = _mod_revision.ensure_null(
3033
other_branch.last_revision())
3035
other_revision_id = revision[-1].as_revision_id(other_branch)
3036
if (revision is not None and len(revision) == 2
3037
and revision[0] is not None):
3038
base_revision_id = revision[0].as_revision_id(base_branch)
3040
base_revision_id = None
3041
# Remember where we merge from
3042
if ((remember or tree.branch.get_submit_branch() is None) and
3043
user_location is not None):
3044
tree.branch.set_submit_branch(other_branch.base)
3045
_merge_tags_if_possible(other_branch, tree.branch)
3046
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3047
other_revision_id, base_revision_id, other_branch, base_branch)
3048
if other_path != '':
3049
allow_pending = False
3050
merger.interesting_files = [other_path]
3052
allow_pending = True
3053
return merger, allow_pending
3055
def _select_branch_location(self, tree, user_location, revision=None,
3057
"""Select a branch location, according to possible inputs.
3059
If provided, branches from ``revision`` are preferred. (Both
3060
``revision`` and ``index`` must be supplied.)
3062
Otherwise, the ``location`` parameter is used. If it is None, then the
3063
``submit`` or ``parent`` location is used, and a note is printed.
3065
:param tree: The working tree to select a branch for merging into
3066
:param location: The location entered by the user
3067
:param revision: The revision parameter to the command
3068
:param index: The index to use for the revision parameter. Negative
3069
indices are permitted.
3070
:return: (selected_location, user_location). The default location
3071
will be the user-entered location.
3073
if (revision is not None and index is not None
3074
and revision[index] is not None):
3075
branch = revision[index].get_branch()
3076
if branch is not None:
3077
return branch, branch
3078
if user_location is None:
3079
location = self._get_remembered(tree, 'Merging from')
3081
location = user_location
3082
return location, user_location
3084
def _get_remembered(self, tree, verb_string):
2243
3085
"""Use tree.branch's parent if none was supplied.
2245
3087
Report if the remembered location was used.
2247
if supplied_location is not None:
2248
return supplied_location
2249
stored_location = tree.branch.get_parent()
3089
stored_location = tree.branch.get_submit_branch()
3090
if stored_location is None:
3091
stored_location = tree.branch.get_parent()
2250
3092
mutter("%s", stored_location)
2251
3093
if stored_location is None:
2252
raise BzrCommandError("No location specified or remembered")
2253
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2254
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3094
raise errors.BzrCommandError("No location specified or remembered")
3095
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3096
note(u"%s remembered location %s", verb_string, display_url)
2255
3097
return stored_location
2792
# command-line interpretation helper for merge-related commands
2793
def merge(other_revision, base_revision,
2794
check_clean=True, ignore_zero=False,
2795
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2796
file_list=None, show_base=False, reprocess=False,
2797
pb=DummyProgress()):
2798
"""Merge changes into a tree.
2801
list(path, revno) Base for three-way merge.
2802
If [None, None] then a base will be automatically determined.
2804
list(path, revno) Other revision for three-way merge.
2806
Directory to merge changes into; '.' by default.
2808
If true, this_dir must have no uncommitted changes before the
2810
ignore_zero - If true, suppress the "zero conflicts" message when
2811
there are no conflicts; should be set when doing something we expect
2812
to complete perfectly.
2813
file_list - If supplied, merge only changes to selected files.
2815
All available ancestors of other_revision and base_revision are
2816
automatically pulled into the branch.
2818
The revno may be -1 to indicate the last revision on the branch, which is
2821
This function is intended for use from the command line; programmatic
2822
clients might prefer to call merge.merge_inner(), which has less magic
2825
from bzrlib.merge import Merger
2826
if this_dir is None:
2828
this_tree = WorkingTree.open_containing(this_dir)[0]
2829
if show_base and not merge_type is Merge3Merger:
2830
raise BzrCommandError("Show-base is not supported for this merge"
2831
" type. %s" % merge_type)
2832
if reprocess and not merge_type.supports_reprocess:
2833
raise BzrCommandError("Conflict reduction is not supported for merge"
2834
" type %s." % merge_type)
2835
if reprocess and show_base:
2836
raise BzrCommandError("Cannot do conflict reduction and show base.")
2838
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2839
merger.pp = ProgressPhase("Merge phase", 5, pb)
2840
merger.pp.next_phase()
2841
merger.check_basis(check_clean)
2842
merger.set_other(other_revision)
2843
merger.pp.next_phase()
2844
merger.set_base(base_revision)
2845
if merger.base_rev_id == merger.other_rev_id:
2846
note('Nothing to do.')
2848
merger.backup_files = backup_files
2849
merger.merge_type = merge_type
2850
merger.set_interesting_files(file_list)
2851
merger.show_base = show_base
2852
merger.reprocess = reprocess
2853
conflicts = merger.do_merge()
2854
if file_list is None:
2855
merger.set_pending()
3838
class cmd_wait_until_signalled(Command):
3839
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
3841
This just prints a line to signal when it is ready, then blocks on stdin.
3847
sys.stdout.write("running\n")
3849
sys.stdin.readline()
3852
class cmd_serve(Command):
3853
"""Run the bzr server."""
3855
aliases = ['server']
3859
help='Serve on stdin/out for use from inetd or sshd.'),
3861
help='Listen for connections on nominated port of the form '
3862
'[hostname:]portnumber. Passing 0 as the port number will '
3863
'result in a dynamically allocated port. The default port is '
3867
help='Serve contents of this directory.',
3869
Option('allow-writes',
3870
help='By default the server is a readonly server. Supplying '
3871
'--allow-writes enables write access to the contents of '
3872
'the served directory and below.'
3876
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3877
from bzrlib import lockdir
3878
from bzrlib.smart import medium, server
3879
from bzrlib.transport import get_transport
3880
from bzrlib.transport.chroot import ChrootServer
3881
if directory is None:
3882
directory = os.getcwd()
3883
url = urlutils.local_path_to_url(directory)
3884
if not allow_writes:
3885
url = 'readonly+' + url
3886
chroot_server = ChrootServer(get_transport(url))
3887
chroot_server.setUp()
3888
t = get_transport(chroot_server.get_url())
3890
smart_server = medium.SmartServerPipeStreamMedium(
3891
sys.stdin, sys.stdout, t)
3893
host = medium.BZR_DEFAULT_INTERFACE
3895
port = medium.BZR_DEFAULT_PORT
3898
host, port = port.split(':')
3900
smart_server = server.SmartTCPServer(t, host=host, port=port)
3901
print 'listening on port: ', smart_server.port
3903
# for the duration of this server, no UI output is permitted.
3904
# note that this may cause problems with blackbox tests. This should
3905
# be changed with care though, as we dont want to use bandwidth sending
3906
# progress over stderr to smart server clients!
3907
old_factory = ui.ui_factory
3908
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
3910
ui.ui_factory = ui.SilentUIFactory()
3911
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
3912
smart_server.serve()
3914
ui.ui_factory = old_factory
3915
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
3918
class cmd_join(Command):
3919
"""Combine a subtree into its containing tree.
3921
This command is for experimental use only. It requires the target tree
3922
to be in dirstate-with-subtree format, which cannot be converted into
3925
The TREE argument should be an independent tree, inside another tree, but
3926
not part of it. (Such trees can be produced by "bzr split", but also by
3927
running "bzr branch" with the target inside a tree.)
3929
The result is a combined tree, with the subtree no longer an independant
3930
part. This is marked as a merge of the subtree into the containing tree,
3931
and all history is preserved.
3933
If --reference is specified, the subtree retains its independence. It can
3934
be branched by itself, and can be part of multiple projects at the same
3935
time. But operations performed in the containing tree, such as commit
3936
and merge, will recurse into the subtree.
3939
_see_also = ['split']
3940
takes_args = ['tree']
3942
Option('reference', help='Join by reference.'),
3946
def run(self, tree, reference=False):
3947
sub_tree = WorkingTree.open(tree)
3948
parent_dir = osutils.dirname(sub_tree.basedir)
3949
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3950
repo = containing_tree.branch.repository
3951
if not repo.supports_rich_root():
3952
raise errors.BzrCommandError(
3953
"Can't join trees because %s doesn't support rich root data.\n"
3954
"You can use bzr upgrade on the repository."
3958
containing_tree.add_reference(sub_tree)
3959
except errors.BadReferenceTarget, e:
3960
# XXX: Would be better to just raise a nicely printable
3961
# exception from the real origin. Also below. mbp 20070306
3962
raise errors.BzrCommandError("Cannot join %s. %s" %
3966
containing_tree.subsume(sub_tree)
3967
except errors.BadSubsumeSource, e:
3968
raise errors.BzrCommandError("Cannot join %s. %s" %
3972
class cmd_split(Command):
3973
"""Split a subdirectory of a tree into a separate tree.
3975
This command will produce a target tree in a format that supports
3976
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
3977
converted into earlier formats like 'dirstate-tags'.
3979
The TREE argument should be a subdirectory of a working tree. That
3980
subdirectory will be converted into an independent tree, with its own
3981
branch. Commits in the top-level tree will not apply to the new subtree.
3984
# join is not un-hidden yet
3985
#_see_also = ['join']
3986
takes_args = ['tree']
3988
def run(self, tree):
3989
containing_tree, subdir = WorkingTree.open_containing(tree)
3990
sub_id = containing_tree.path2id(subdir)
3992
raise errors.NotVersionedError(subdir)
3994
containing_tree.extract(sub_id)
3995
except errors.RootNotRich:
3996
raise errors.UpgradeRequired(containing_tree.branch.base)
3999
class cmd_merge_directive(Command):
4000
"""Generate a merge directive for auto-merge tools.
4002
A directive requests a merge to be performed, and also provides all the
4003
information necessary to do so. This means it must either include a
4004
revision bundle, or the location of a branch containing the desired
4007
A submit branch (the location to merge into) must be supplied the first
4008
time the command is issued. After it has been supplied once, it will
4009
be remembered as the default.
4011
A public branch is optional if a revision bundle is supplied, but required
4012
if --diff or --plain is specified. It will be remembered as the default
4013
after the first use.
4016
takes_args = ['submit_branch?', 'public_branch?']
4020
_see_also = ['send']
4023
RegistryOption.from_kwargs('patch-type',
4024
'The type of patch to include in the directive.',
4026
value_switches=True,
4028
bundle='Bazaar revision bundle (default).',
4029
diff='Normal unified diff.',
4030
plain='No patch, just directive.'),
4031
Option('sign', help='GPG-sign the directive.'), 'revision',
4032
Option('mail-to', type=str,
4033
help='Instead of printing the directive, email to this address.'),
4034
Option('message', type=str, short_name='m',
4035
help='Message to use when committing this merge.')
4038
encoding_type = 'exact'
4040
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
4041
sign=False, revision=None, mail_to=None, message=None):
4042
from bzrlib.revision import ensure_null, NULL_REVISION
4043
include_patch, include_bundle = {
4044
'plain': (False, False),
4045
'diff': (True, False),
4046
'bundle': (True, True),
4048
branch = Branch.open('.')
4049
stored_submit_branch = branch.get_submit_branch()
4050
if submit_branch is None:
4051
submit_branch = stored_submit_branch
4053
if stored_submit_branch is None:
4054
branch.set_submit_branch(submit_branch)
4055
if submit_branch is None:
4056
submit_branch = branch.get_parent()
4057
if submit_branch is None:
4058
raise errors.BzrCommandError('No submit branch specified or known')
4060
stored_public_branch = branch.get_public_branch()
4061
if public_branch is None:
4062
public_branch = stored_public_branch
4063
elif stored_public_branch is None:
4064
branch.set_public_branch(public_branch)
4065
if not include_bundle and public_branch is None:
4066
raise errors.BzrCommandError('No public branch specified or'
4068
base_revision_id = None
4069
if revision is not None:
4070
if len(revision) > 2:
4071
raise errors.BzrCommandError('bzr merge-directive takes '
4072
'at most two one revision identifiers')
4073
revision_id = revision[-1].as_revision_id(branch)
4074
if len(revision) == 2:
4075
base_revision_id = revision[0].as_revision_id(branch)
4077
revision_id = branch.last_revision()
4078
revision_id = ensure_null(revision_id)
4079
if revision_id == NULL_REVISION:
4080
raise errors.BzrCommandError('No revisions to bundle.')
4081
directive = merge_directive.MergeDirective2.from_objects(
4082
branch.repository, revision_id, time.time(),
4083
osutils.local_time_offset(), submit_branch,
4084
public_branch=public_branch, include_patch=include_patch,
4085
include_bundle=include_bundle, message=message,
4086
base_revision_id=base_revision_id)
4089
self.outf.write(directive.to_signed(branch))
4091
self.outf.writelines(directive.to_lines())
4093
message = directive.to_email(mail_to, branch, sign)
4094
s = SMTPConnection(branch.get_config())
4095
s.send_email(message)
4098
class cmd_send(Command):
4099
"""Mail or create a merge-directive for submiting changes.
4101
A merge directive provides many things needed for requesting merges:
4103
* A machine-readable description of the merge to perform
4105
* An optional patch that is a preview of the changes requested
4107
* An optional bundle of revision data, so that the changes can be applied
4108
directly from the merge directive, without retrieving data from a
4111
If --no-bundle is specified, then public_branch is needed (and must be
4112
up-to-date), so that the receiver can perform the merge using the
4113
public_branch. The public_branch is always included if known, so that
4114
people can check it later.
4116
The submit branch defaults to the parent, but can be overridden. Both
4117
submit branch and public branch will be remembered if supplied.
4119
If a public_branch is known for the submit_branch, that public submit
4120
branch is used in the merge instructions. This means that a local mirror
4121
can be used as your actual submit branch, once you have set public_branch
4124
Mail is sent using your preferred mail program. This should be transparent
4125
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4126
If the preferred client can't be found (or used), your editor will be used.
4128
To use a specific mail program, set the mail_client configuration option.
4129
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4130
specific clients are "evolution", "kmail", "mutt", and "thunderbird";
4131
generic options are "default", "editor", "emacsclient", "mapi", and
4134
If mail is being sent, a to address is required. This can be supplied
4135
either on the commandline, by setting the submit_to configuration
4136
option in the branch itself or the child_submit_to configuration option
4137
in the submit branch.
4139
Two formats are currently supported: "4" uses revision bundle format 4 and
4140
merge directive format 2. It is significantly faster and smaller than
4141
older formats. It is compatible with Bazaar 0.19 and later. It is the
4142
default. "0.9" uses revision bundle format 0.9 and merge directive
4143
format 1. It is compatible with Bazaar 0.12 - 0.18.
4145
Merge directives are applied using the merge command or the pull command.
4148
encoding_type = 'exact'
4150
_see_also = ['merge', 'pull']
4152
takes_args = ['submit_branch?', 'public_branch?']
4156
help='Do not include a bundle in the merge directive.'),
4157
Option('no-patch', help='Do not include a preview patch in the merge'
4160
help='Remember submit and public branch.'),
4162
help='Branch to generate the submission from, '
4163
'rather than the one containing the working directory.',
4166
Option('output', short_name='o',
4167
help='Write merge directive to this file; '
4168
'use - for stdout.',
4170
Option('mail-to', help='Mail the request to this address.',
4174
RegistryOption.from_kwargs('format',
4175
'Use the specified output format.',
4176
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4177
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4180
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4181
no_patch=False, revision=None, remember=False, output=None,
4182
format='4', mail_to=None, message=None, **kwargs):
4183
return self._run(submit_branch, revision, public_branch, remember,
4184
format, no_bundle, no_patch, output,
4185
kwargs.get('from', '.'), mail_to, message)
4187
def _run(self, submit_branch, revision, public_branch, remember, format,
4188
no_bundle, no_patch, output, from_, mail_to, message):
4189
from bzrlib.revision import NULL_REVISION
4190
branch = Branch.open_containing(from_)[0]
4192
outfile = StringIO()
4196
outfile = open(output, 'wb')
4197
# we may need to write data into branch's repository to calculate
4202
config = branch.get_config()
4204
mail_to = config.get_user_option('submit_to')
4205
mail_client = config.get_mail_client()
4206
if remember and submit_branch is None:
4207
raise errors.BzrCommandError(
4208
'--remember requires a branch to be specified.')
4209
stored_submit_branch = branch.get_submit_branch()
4210
remembered_submit_branch = False
4211
if submit_branch is None:
4212
submit_branch = stored_submit_branch
4213
remembered_submit_branch = True
4215
if stored_submit_branch is None or remember:
4216
branch.set_submit_branch(submit_branch)
4217
if submit_branch is None:
4218
submit_branch = branch.get_parent()
4219
remembered_submit_branch = True
4220
if submit_branch is None:
4221
raise errors.BzrCommandError('No submit branch known or'
4223
if remembered_submit_branch:
4224
note('Using saved location "%s" to determine what changes to submit.', submit_branch)
4227
submit_config = Branch.open(submit_branch).get_config()
4228
mail_to = submit_config.get_user_option("child_submit_to")
4230
stored_public_branch = branch.get_public_branch()
4231
if public_branch is None:
4232
public_branch = stored_public_branch
4233
elif stored_public_branch is None or remember:
4234
branch.set_public_branch(public_branch)
4235
if no_bundle and public_branch is None:
4236
raise errors.BzrCommandError('No public branch specified or'
4238
base_revision_id = None
4240
if revision is not None:
4241
if len(revision) > 2:
4242
raise errors.BzrCommandError('bzr send takes '
4243
'at most two one revision identifiers')
4244
revision_id = revision[-1].as_revision_id(branch)
4245
if len(revision) == 2:
4246
base_revision_id = revision[0].as_revision_id(branch)
4247
if revision_id is None:
4248
revision_id = branch.last_revision()
4249
if revision_id == NULL_REVISION:
4250
raise errors.BzrCommandError('No revisions to submit.')
4252
directive = merge_directive.MergeDirective2.from_objects(
4253
branch.repository, revision_id, time.time(),
4254
osutils.local_time_offset(), submit_branch,
4255
public_branch=public_branch, include_patch=not no_patch,
4256
include_bundle=not no_bundle, message=message,
4257
base_revision_id=base_revision_id)
4258
elif format == '0.9':
4261
patch_type = 'bundle'
4263
raise errors.BzrCommandError('Format 0.9 does not'
4264
' permit bundle with no patch')
4270
directive = merge_directive.MergeDirective.from_objects(
4271
branch.repository, revision_id, time.time(),
4272
osutils.local_time_offset(), submit_branch,
4273
public_branch=public_branch, patch_type=patch_type,
4276
outfile.writelines(directive.to_lines())
4278
subject = '[MERGE] '
4279
if message is not None:
4282
revision = branch.repository.get_revision(revision_id)
4283
subject += revision.get_summary()
4284
basename = directive.get_disk_name(branch)
4285
mail_client.compose_merge_request(mail_to, subject,
4286
outfile.getvalue(), basename)
4293
class cmd_bundle_revisions(cmd_send):
4295
"""Create a merge-directive for submiting changes.
4297
A merge directive provides many things needed for requesting merges:
4299
* A machine-readable description of the merge to perform
4301
* An optional patch that is a preview of the changes requested
4303
* An optional bundle of revision data, so that the changes can be applied
4304
directly from the merge directive, without retrieving data from a
4307
If --no-bundle is specified, then public_branch is needed (and must be
4308
up-to-date), so that the receiver can perform the merge using the
4309
public_branch. The public_branch is always included if known, so that
4310
people can check it later.
4312
The submit branch defaults to the parent, but can be overridden. Both
4313
submit branch and public branch will be remembered if supplied.
4315
If a public_branch is known for the submit_branch, that public submit
4316
branch is used in the merge instructions. This means that a local mirror
4317
can be used as your actual submit branch, once you have set public_branch
4320
Two formats are currently supported: "4" uses revision bundle format 4 and
4321
merge directive format 2. It is significantly faster and smaller than
4322
older formats. It is compatible with Bazaar 0.19 and later. It is the
4323
default. "0.9" uses revision bundle format 0.9 and merge directive
4324
format 1. It is compatible with Bazaar 0.12 - 0.18.
4329
help='Do not include a bundle in the merge directive.'),
4330
Option('no-patch', help='Do not include a preview patch in the merge'
4333
help='Remember submit and public branch.'),
4335
help='Branch to generate the submission from, '
4336
'rather than the one containing the working directory.',
4339
Option('output', short_name='o', help='Write directive to this file.',
4342
RegistryOption.from_kwargs('format',
4343
'Use the specified output format.',
4344
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4345
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4347
aliases = ['bundle']
4349
_see_also = ['send', 'merge']
4353
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4354
no_patch=False, revision=None, remember=False, output=None,
4355
format='4', **kwargs):
4358
return self._run(submit_branch, revision, public_branch, remember,
4359
format, no_bundle, no_patch, output,
4360
kwargs.get('from', '.'), None, None)
4363
class cmd_tag(Command):
4364
"""Create, remove or modify a tag naming a revision.
4366
Tags give human-meaningful names to revisions. Commands that take a -r
4367
(--revision) option can be given -rtag:X, where X is any previously
4370
Tags are stored in the branch. Tags are copied from one branch to another
4371
along when you branch, push, pull or merge.
4373
It is an error to give a tag name that already exists unless you pass
4374
--force, in which case the tag is moved to point to the new revision.
4376
To rename a tag (change the name but keep it on the same revsion), run ``bzr
4377
tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
4380
_see_also = ['commit', 'tags']
4381
takes_args = ['tag_name']
4384
help='Delete this tag rather than placing it.',
4387
help='Branch in which to place the tag.',
4392
help='Replace existing tags.',
4397
def run(self, tag_name,
4403
branch, relpath = Branch.open_containing(directory)
4407
branch.tags.delete_tag(tag_name)
4408
self.outf.write('Deleted tag %s.\n' % tag_name)
4411
if len(revision) != 1:
4412
raise errors.BzrCommandError(
4413
"Tags can only be placed on a single revision, "
4415
revision_id = revision[0].as_revision_id(branch)
4417
revision_id = branch.last_revision()
4418
if (not force) and branch.tags.has_tag(tag_name):
4419
raise errors.TagAlreadyExists(tag_name)
4420
branch.tags.set_tag(tag_name, revision_id)
4421
self.outf.write('Created tag %s.\n' % tag_name)
4426
class cmd_tags(Command):
4429
This command shows a table of tag names and the revisions they reference.
4435
help='Branch whose tags should be displayed.',
4439
RegistryOption.from_kwargs('sort',
4440
'Sort tags by different criteria.', title='Sorting',
4441
alpha='Sort tags lexicographically (default).',
4442
time='Sort tags chronologically.',
4453
branch, relpath = Branch.open_containing(directory)
4454
tags = branch.tags.get_tag_dict().items()
4459
elif sort == 'time':
4461
for tag, revid in tags:
4463
revobj = branch.repository.get_revision(revid)
4464
except errors.NoSuchRevision:
4465
timestamp = sys.maxint # place them at the end
4467
timestamp = revobj.timestamp
4468
timestamps[revid] = timestamp
4469
tags.sort(key=lambda x: timestamps[x[1]])
4471
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
4472
revno_map = branch.get_revision_id_to_revno_map()
4473
tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
4474
for tag, revid in tags ]
4475
for tag, revspec in tags:
4476
self.outf.write('%-20s %s\n' % (tag, revspec))
4479
class cmd_reconfigure(Command):
4480
"""Reconfigure the type of a bzr directory.
4482
A target configuration must be specified.
4484
For checkouts, the bind-to location will be auto-detected if not specified.
4485
The order of preference is
4486
1. For a lightweight checkout, the current bound location.
4487
2. For branches that used to be checkouts, the previously-bound location.
4488
3. The push location.
4489
4. The parent location.
4490
If none of these is available, --bind-to must be specified.
4493
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4494
takes_args = ['location?']
4495
takes_options = [RegistryOption.from_kwargs('target_type',
4496
title='Target type',
4497
help='The type to reconfigure the directory to.',
4498
value_switches=True, enum_switch=False,
4499
branch='Reconfigure to be an unbound branch '
4500
'with no working tree.',
4501
tree='Reconfigure to be an unbound branch '
4502
'with a working tree.',
4503
checkout='Reconfigure to be a bound branch '
4504
'with a working tree.',
4505
lightweight_checkout='Reconfigure to be a lightweight'
4506
' checkout (with no local history).',
4507
standalone='Reconfigure to be a standalone branch '
4508
'(i.e. stop using shared repository).',
4509
use_shared='Reconfigure to use a shared repository.'),
4510
Option('bind-to', help='Branch to bind checkout to.',
4513
help='Perform reconfiguration even if local changes'
4517
def run(self, location=None, target_type=None, bind_to=None, force=False):
4518
directory = bzrdir.BzrDir.open(location)
4519
if target_type is None:
4520
raise errors.BzrCommandError('No target configuration specified')
4521
elif target_type == 'branch':
4522
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
4523
elif target_type == 'tree':
4524
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4525
elif target_type == 'checkout':
4526
reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4528
elif target_type == 'lightweight-checkout':
4529
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
4531
elif target_type == 'use-shared':
4532
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
4533
elif target_type == 'standalone':
4534
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
4535
reconfiguration.apply(force)
4538
class cmd_switch(Command):
4539
"""Set the branch of a checkout and update.
4541
For lightweight checkouts, this changes the branch being referenced.
4542
For heavyweight checkouts, this checks that there are no local commits
4543
versus the current bound branch, then it makes the local branch a mirror
4544
of the new location and binds to it.
4546
In both cases, the working tree is updated and uncommitted changes
4547
are merged. The user can commit or revert these as they desire.
4549
Pending merges need to be committed or reverted before using switch.
4551
The path to the branch to switch to can be specified relative to the parent
4552
directory of the current branch. For example, if you are currently in a
4553
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
4557
takes_args = ['to_location']
4558
takes_options = [Option('force',
4559
help='Switch even if local commits will be lost.')
4562
def run(self, to_location, force=False):
4563
from bzrlib import switch
4565
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
4567
to_branch = Branch.open(to_location)
4568
except errors.NotBranchError:
4569
to_branch = Branch.open(
4570
control_dir.open_branch().base + '../' + to_location)
4571
switch.switch(control_dir, to_branch, force)
4572
note('Switched to branch: %s',
4573
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4576
class cmd_hooks(Command):
4577
"""Show a branch's currently registered hooks.
4581
takes_args = ['path?']
4583
def run(self, path=None):
4586
branch_hooks = Branch.open(path).hooks
4587
for hook_type in branch_hooks:
4588
hooks = branch_hooks[hook_type]
4589
self.outf.write("%s:\n" % (hook_type,))
4592
self.outf.write(" %s\n" %
4593
(branch_hooks.get_hook_name(hook),))
4595
self.outf.write(" <no hooks installed>\n")
4598
def _create_prefix(cur_transport):
4599
needed = [cur_transport]
4600
# Recurse upwards until we can create a directory successfully
4602
new_transport = cur_transport.clone('..')
4603
if new_transport.base == cur_transport.base:
4604
raise errors.BzrCommandError(
4605
"Failed to create path prefix for %s."
4606
% cur_transport.base)
4608
new_transport.mkdir('.')
4609
except errors.NoSuchFile:
4610
needed.append(new_transport)
4611
cur_transport = new_transport
4614
# Now we only need to create child directories
4616
cur_transport = needed.pop()
4617
cur_transport.ensure_base()
2861
4620
# these get imported and then picked up by the scan for cmd_*