903
904
# preserve whatever source format we have.
904
905
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
905
possible_transports=[to_transport])
906
possible_transports=[to_transport],
907
accelerator_tree=accelerator_tree)
906
908
branch = dir.open_branch()
907
909
except errors.NoSuchRevision:
908
910
to_transport.delete_tree('.')
947
949
"common operations like diff and status without "
948
950
"such access, and also support local commits."
953
help="Get file contents from this tree.", type=str)
953
957
def run(self, branch_location=None, to_location=None, revision=None,
958
lightweight=False, files_from=None):
955
959
if revision is None:
956
960
revision = [None]
957
961
elif len(revision) > 1:
960
964
if branch_location is None:
961
965
branch_location = osutils.getcwd()
962
966
to_location = branch_location
963
source = Branch.open(branch_location)
967
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
969
if files_from is not None:
970
accelerator_tree = WorkingTree.open(files_from)
964
971
if len(revision) == 1 and revision[0] is not None:
965
972
revision_id = _mod_revision.ensure_null(
966
973
revision[0].in_history(source)[1])
978
985
except errors.NoWorkingTree:
979
986
source.bzrdir.create_workingtree(revision_id)
981
source.create_checkout(to_location, revision_id, lightweight)
988
source.create_checkout(to_location, revision_id, lightweight,
984
992
class cmd_renames(Command):
1392
1400
class cmd_diff(Command):
1393
"""Show differences in the working tree or between revisions.
1401
"""Show differences in the working tree, between revisions or branches.
1395
If files are listed, only the changes in those files are listed.
1396
Otherwise, all changes for the tree are listed.
1403
If no arguments are given, all changes for the current tree are listed.
1404
If files are given, only the changes in those files are listed.
1405
Remote and multiple branches can be compared by using the --old and
1406
--new options. If not provided, the default for both is derived from
1407
the first argument, if any, or the current tree if no arguments are
1398
1410
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1399
1411
produces patches suitable for "patch -p1".
1418
1430
bzr diff -r1..2
1432
Difference between revision 2 and revision 1 for branch xxx::
1436
Show just the differences for file NEWS::
1440
Show the differences in working tree xxx for file NEWS::
1444
Show the differences from branch xxx to this working tree:
1448
Show the differences between two branches for file NEWS::
1450
bzr diff --old xxx --new yyy NEWS
1420
1452
Same as 'bzr diff' but prefix paths with old/ and new/::
1422
1454
bzr diff --prefix old/:new/
1424
Show the differences between the two working trees::
1426
bzr diff bzr.mine bzr.dev
1428
Show just the differences for 'foo.c'::
1432
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1433
# or a graphical diff.
1435
# TODO: Python difflib is not exactly the same as unidiff; should
1436
# either fix it up or prefer to use an external diff.
1438
# TODO: Selected-file diff is inefficient and doesn't show you
1441
# TODO: This probably handles non-Unix newlines poorly.
1443
1456
_see_also = ['status']
1444
1457
takes_args = ['file*']
1445
1458
takes_options = [
1449
1462
short_name='p',
1450
1463
help='Set prefixes added to old and new filenames, as '
1451
1464
'two values separated by a colon. (eg "old/:new/").'),
1466
help='Branch/tree to compare from.',
1470
help='Branch/tree to compare to.',
1476
help='Use this command to compare files.',
1455
1480
aliases = ['di', 'dif']
1456
1481
encoding_type = 'exact'
1458
1483
@display_command
1459
1484
def run(self, revision=None, file_list=None, diff_options=None,
1461
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1485
prefix=None, old=None, new=None, using=None):
1486
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1463
1488
if (prefix is None) or (prefix == '0'):
1464
1489
# diff -p0 format
1478
1503
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1479
1504
' one or two revision specifiers')
1482
tree1, file_list = internal_tree_files(file_list)
1486
except errors.FileInWrongBranch:
1487
if len(file_list) != 2:
1488
raise errors.BzrCommandError("Files are in different branches")
1490
tree1, file1 = WorkingTree.open_containing(file_list[0])
1491
tree2, file2 = WorkingTree.open_containing(file_list[1])
1492
if file1 != "" or file2 != "":
1493
# FIXME diff those two files. rbc 20051123
1494
raise errors.BzrCommandError("Files are in different branches")
1496
except errors.NotBranchError:
1497
if (revision is not None and len(revision) == 2
1498
and not revision[0].needs_branch()
1499
and not revision[1].needs_branch()):
1500
# If both revision specs include a branch, we can
1501
# diff them without needing a local working tree
1502
tree1, tree2 = None, None
1506
if tree2 is not None:
1507
if revision is not None:
1508
# FIXME: but there should be a clean way to diff between
1509
# non-default versions of two trees, it's not hard to do
1511
raise errors.BzrCommandError(
1512
"Sorry, diffing arbitrary revisions across branches "
1513
"is not implemented yet")
1514
return show_diff_trees(tree1, tree2, sys.stdout,
1515
specific_files=file_list,
1516
external_diff_options=diff_options,
1517
old_label=old_label, new_label=new_label)
1519
return diff_cmd_helper(tree1, file_list, diff_options,
1520
revision_specs=revision,
1521
old_label=old_label, new_label=new_label)
1506
old_tree, new_tree, specific_files, extra_trees = \
1507
_get_trees_to_diff(file_list, revision, old, new)
1508
return show_diff_trees(old_tree, new_tree, sys.stdout,
1509
specific_files=specific_files,
1510
external_diff_options=diff_options,
1511
old_label=old_label, new_label=new_label,
1512
extra_trees=extra_trees, using=using)
1524
1515
class cmd_deleted(Command):
2231
2225
"files in the working tree."),
2232
2226
ListOption('fixes', type=str,
2233
2227
help="Mark a bug as being fixed by this revision."),
2234
Option('author', type=str,
2228
Option('author', type=unicode,
2235
2229
help="Set the author's name, if it's different "
2236
2230
"from the committer."),
2237
2231
Option('local',
2605
2599
Option('strict', help='Fail on missing dependencies or '
2606
2600
'known failures.'),
2607
2601
Option('coverage', type=str, argname="DIRECTORY",
2608
help='Generate line coverage report in this'
2602
help='Generate line coverage report in this '
2611
2605
encoding_type = 'replace'
3030
3024
" merges. Not cherrypicking or"
3031
3025
" multi-merges.")
3032
3026
repository = tree.branch.repository
3033
graph = repository.get_graph()
3034
base_revision = graph.find_unique_lca(parents[0], parents[1])
3035
base_tree = repository.revision_tree(base_revision)
3036
other_tree = repository.revision_tree(parents[1])
3037
3027
interesting_ids = None
3038
3028
new_conflicts = []
3039
3029
conflicts = tree.conflicts()
3069
3059
# list, we imply that the working tree text has seen and rejected
3070
3060
# all the changes from the other tree, when in fact those changes
3071
3061
# have not yet been seen.
3062
pb = ui.ui_factory.nested_progress_bar()
3072
3063
tree.set_parent_ids(parents[:1])
3074
conflicts = _mod_merge.merge_inner(
3075
tree.branch, other_tree, base_tree,
3077
interesting_ids=interesting_ids,
3078
other_rev_id=parents[1],
3079
merge_type=merge_type,
3080
show_base=show_base,
3081
reprocess=reprocess)
3065
merger = _mod_merge.Merger.from_revision_ids(pb,
3067
merger.interesting_ids = interesting_ids
3068
merger.merge_type = merge_type
3069
merger.show_base = show_base
3070
merger.reprocess = reprocess
3071
conflicts = merger.do_merge()
3083
3073
tree.set_parent_ids(parents)
3086
3077
if conflicts > 0:
3417
3408
def run(self, filename, all=False, long=False, revision=None,
3418
3409
show_ids=False):
3419
3410
from bzrlib.annotate import annotate_file
3420
tree, relpath = WorkingTree.open_containing(filename)
3421
branch = tree.branch
3411
wt, branch, relpath = \
3412
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
3424
3418
if revision is None:
3425
3419
revision_id = branch.last_revision()
3427
3421
raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3429
3423
revision_id = revision[0].in_history(branch).rev_id
3430
file_id = tree.path2id(relpath)
3424
tree = branch.repository.revision_tree(revision_id)
3426
file_id = wt.path2id(relpath)
3428
file_id = tree.path2id(relpath)
3431
3429
if file_id is None:
3432
3430
raise errors.NotVersionedError(filename)
3433
tree = branch.repository.revision_tree(revision_id)
3434
3431
file_version = tree.inventory[file_id].revision
3435
3432
annotate_file(branch, file_version, file_id, long, all, self.outf,
3436
3433
show_ids=show_ids)
3441
3441
class cmd_re_sign(Command):
3579
3579
Option('force', help='Say yes to all questions.')]
3580
3580
takes_args = ['location?']
3582
encoding_type = 'replace'
3583
3584
def run(self, location=None,
3584
3585
dry_run=False, verbose=False,
3720
3721
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3722
from bzrlib import lockdir
3721
3723
from bzrlib.smart import medium, server
3722
3724
from bzrlib.transport import get_transport
3723
3725
from bzrlib.transport.chroot import ChrootServer
3748
3750
# be changed with care though, as we dont want to use bandwidth sending
3749
3751
# progress over stderr to smart server clients!
3750
3752
old_factory = ui.ui_factory
3753
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
3752
3755
ui.ui_factory = ui.SilentUIFactory()
3756
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
3753
3757
smart_server.serve()
3755
3759
ui.ui_factory = old_factory
3760
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
3758
3763
class cmd_join(Command):
3812
3817
class cmd_split(Command):
3813
"""Split a tree into two trees.
3818
"""Split a subdirectory of a tree into a separate tree.
3815
This command is for experimental use only. It requires the target tree
3816
to be in dirstate-with-subtree format, which cannot be converted into
3820
This command will produce a target tree in a format that supports
3821
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
3822
converted into earlier formats like 'dirstate-tags'.
3819
3824
The TREE argument should be a subdirectory of a working tree. That
3820
3825
subdirectory will be converted into an independent tree, with its own
3821
3826
branch. Commits in the top-level tree will not apply to the new subtree.
3822
If you want that behavior, do "bzr join --reference TREE".
3825
_see_also = ['join']
3829
# join is not un-hidden yet
3830
#_see_also = ['join']
3826
3831
takes_args = ['tree']
3830
3833
def run(self, tree):
3831
3834
containing_tree, subdir = WorkingTree.open_containing(tree)
3832
3835
sub_id = containing_tree.path2id(subdir)
4025
4027
def _run(self, submit_branch, revision, public_branch, remember, format,
4026
4028
no_bundle, no_patch, output, from_, mail_to, message):
4027
4029
from bzrlib.revision import NULL_REVISION
4030
branch = Branch.open_containing(from_)[0]
4028
4031
if output is None:
4029
4032
outfile = StringIO()
4030
4033
elif output == '-':
4031
4034
outfile = self.outf
4033
4036
outfile = open(output, 'wb')
4037
# we may need to write data into branch's repository to calculate
4035
branch = Branch.open_containing(from_)[0]
4036
# we may need to write data into branch's repository to calculate
4039
4041
if output is None:
4040
4042
config = branch.get_config()
4041
4043
if mail_to is None: