430
438
raise errors.BzrCommandError('invalid kind specified')
432
440
work_tree, file_list = tree_files(file_list)
434
if revision is not None:
435
if len(revision) > 1:
436
raise errors.BzrCommandError('bzr inventory --revision takes'
437
' exactly one revision identifier')
438
revision_id = revision[0].in_history(work_tree.branch).rev_id
439
tree = work_tree.branch.repository.revision_tree(revision_id)
441
# We include work_tree as well as 'tree' here
442
# So that doing '-r 10 path/foo' will lookup whatever file
443
# exists now at 'path/foo' even if it has been renamed, as
444
# well as whatever files existed in revision 10 at path/foo
445
trees = [tree, work_tree]
450
if file_list is not None:
451
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
452
require_versioned=True)
453
# find_ids_across_trees may include some paths that don't
455
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
456
for file_id in file_ids if file_id in tree)
458
entries = tree.inventory.entries()
441
work_tree.lock_read()
443
if revision is not None:
444
if len(revision) > 1:
445
raise errors.BzrCommandError(
446
'bzr inventory --revision takes exactly one revision'
448
revision_id = revision[0].in_history(work_tree.branch).rev_id
449
tree = work_tree.branch.repository.revision_tree(revision_id)
451
extra_trees = [work_tree]
457
if file_list is not None:
458
file_ids = tree.paths2ids(file_list, trees=extra_trees,
459
require_versioned=True)
460
# find_ids_across_trees may include some paths that don't
462
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
463
for file_id in file_ids if file_id in tree)
465
entries = tree.inventory.entries()
468
if tree is not work_tree:
460
471
for path, entry in entries:
461
472
if kind and kind != entry.kind:
598
610
old_rh = branch_to.revision_history()
599
611
if tree_to is not None:
600
count = tree_to.pull(branch_from, overwrite, rev_id,
601
delta.ChangeReporter(tree_to.inventory))
612
result = tree_to.pull(branch_from, overwrite, rev_id,
613
delta.ChangeReporter(unversioned_filter=tree_to.is_ignored))
603
count = branch_to.pull(branch_from, overwrite, rev_id)
604
note('%d revision(s) pulled.' % (count,))
615
result = branch_to.pull(branch_from, overwrite, rev_id)
617
result.report(self.outf)
619
from bzrlib.log import show_changed_revisions
607
620
new_rh = branch_to.revision_history()
610
from bzrlib.log import show_changed_revisions
611
show_changed_revisions(branch_to, old_rh, new_rh,
621
show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
615
624
class cmd_push(Command):
784
792
except errors.NotLocalUrl:
785
793
warning('This transport does not update the working '
786
794
'tree of: %s' % (br_to.base,))
787
count = br_from.push(br_to, overwrite)
795
push_result = br_from.push(br_to, overwrite)
788
796
except errors.NoWorkingTree:
789
count = br_from.push(br_to, overwrite)
797
push_result = br_from.push(br_to, overwrite)
791
799
tree_to.lock_write()
793
count = br_from.push(tree_to.branch, overwrite)
801
push_result = br_from.push(tree_to.branch, overwrite)
797
805
except errors.DivergedBranches:
798
806
raise errors.BzrCommandError('These branches have diverged.'
799
807
' Try using "merge" and then "push".')
800
note('%d revision(s) pushed.' % (count,))
808
if push_result is not None:
809
push_result.report(self.outf)
803
811
new_rh = br_to.revision_history()
804
812
if old_rh != new_rh:
805
813
# Something changed
806
814
from bzrlib.log import show_changed_revisions
807
815
show_changed_revisions(br_to, old_rh, new_rh,
808
816
to_file=self.outf)
818
# we probably did a clone rather than a push, so a message was
811
823
class cmd_branch(Command):
968
982
def run(self, dir=u'.'):
969
983
tree = WorkingTree.open_containing(dir)[0]
970
old_inv = tree.basis_tree().inventory
971
new_inv = tree.read_working_inventory()
972
renames = list(_mod_tree.find_renames(old_inv, new_inv))
974
for old_name, new_name in renames:
975
self.outf.write("%s => %s\n" % (old_name, new_name))
986
new_inv = tree.inventory
987
old_tree = tree.basis_tree()
990
old_inv = old_tree.inventory
991
renames = list(_mod_tree.find_renames(old_inv, new_inv))
993
for old_name, new_name in renames:
994
self.outf.write("%s => %s\n" % (old_name, new_name))
978
1001
class cmd_update(Command):
1693
1732
elif tree is None:
1694
1733
tree = branch.basis_tree()
1696
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1697
if fp.startswith(relpath):
1698
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1699
if non_recursive and '/' in fp:
1701
if not all and not selection[fc]:
1703
if kind is not None and fkind != kind:
1706
kindch = entry.kind_character()
1707
outstring = '%-8s %s%s' % (fc, fp, kindch)
1708
if show_ids and fid is not None:
1709
outstring = "%-50s %s" % (outstring, fid)
1710
self.outf.write(outstring + '\n')
1712
self.outf.write(fp + '\0')
1737
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1738
if fp.startswith(relpath):
1739
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1740
if non_recursive and '/' in fp:
1742
if not all and not selection[fc]:
1744
if kind is not None and fkind != kind:
1747
kindch = entry.kind_character()
1748
outstring = '%-8s %s%s' % (fc, fp, kindch)
1749
if show_ids and fid is not None:
1750
outstring = "%-50s %s" % (outstring, fid)
1751
self.outf.write(outstring + '\n')
1753
self.outf.write(fp + '\0')
1756
self.outf.write(fid)
1757
self.outf.write('\0')
1714
1760
if fid is not None:
1715
self.outf.write(fid)
1716
self.outf.write('\0')
1724
self.outf.write('%-50s %s\n' % (fp, my_id))
1726
self.outf.write(fp + '\n')
1765
self.outf.write('%-50s %s\n' % (fp, my_id))
1767
self.outf.write(fp + '\n')
1729
1772
class cmd_unknowns(Command):
1834
1876
@display_command
1836
1878
tree = WorkingTree.open_containing(u'.')[0]
1837
for path, file_class, kind, file_id, entry in tree.list_files():
1838
if file_class != 'I':
1840
## XXX: Slightly inefficient since this was already calculated
1841
pat = tree.is_ignored(path)
1842
print '%-50s %s' % (path, pat)
1881
for path, file_class, kind, file_id, entry in tree.list_files():
1882
if file_class != 'I':
1884
## XXX: Slightly inefficient since this was already calculated
1885
pat = tree.is_ignored(path)
1886
print '%-50s %s' % (path, pat)
1845
1891
class cmd_lookup_revision(Command):
2257
2308
' without running tests'),
2258
2309
Option('first',
2259
2310
help='run all tests, but run specified tests first',
2312
Option('numbered-dirs',
2313
help='use numbered dirs for TestCaseInTempDir'),
2262
2315
encoding_type = 'replace'
2264
2317
def run(self, testspecs_list=None, verbose=None, one=False,
2265
2318
keep_output=False, transport=None, benchmark=None,
2266
2319
lsprof_timed=None, cache_dir=None, clean_output=False,
2320
first=False, numbered_dirs=None):
2268
2321
import bzrlib.ui
2269
2322
from bzrlib.tests import selftest
2270
2323
import bzrlib.benchmarks as benchmarks
2428
2485
uncommitted=False, pull=False,
2429
2486
directory=None,
2488
from bzrlib.tag import _merge_tags_if_possible
2431
2489
if merge_type is None:
2432
2490
merge_type = _mod_merge.Merge3Merger
2434
2492
if directory is None: directory = u'.'
2493
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2494
# inventory. Because merge is a mutating operation, it really
2495
# should be a lock_write() for the whole cmd_merge operation.
2496
# However, cmd_merge open's its own tree in _merge_helper, which
2497
# means if we lock here, the later lock_write() will always block.
2498
# Either the merge helper code should be updated to take a tree,
2499
# (What about tree.merge_from_branch?)
2435
2500
tree = WorkingTree.open_containing(directory)[0]
2436
change_reporter = delta.ChangeReporter(tree.inventory)
2501
change_reporter = delta.ChangeReporter(
2502
unversioned_filter=tree.is_ignored)
2438
2504
if branch is not None:
3151
3222
t = get_transport(url)
3153
3224
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3154
elif port is not None:
3156
host, port = port.split(':')
3227
port = smart.BZR_DEFAULT_PORT
3158
3228
host = '127.0.0.1'
3159
server = smart.SmartTCPServer(t, host=host, port=int(port))
3231
host, port = port.split(':')
3235
server = smart.SmartTCPServer(t, host=host, port=port)
3160
3236
print 'listening on port: ', server.port
3161
3237
sys.stdout.flush()
3163
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3240
class cmd_join(Command):
3241
"""Combine a subtree into its containing tree.
3243
This is marked as a merge of the subtree into the containing tree, and all
3244
history is preserved.
3247
takes_args = ['tree']
3248
takes_options = [Option('reference', 'join by reference')]
3250
def run(self, tree, reference=False):
3251
sub_tree = WorkingTree.open(tree)
3252
parent_dir = osutils.dirname(sub_tree.basedir)
3253
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3254
repo = containing_tree.branch.repository
3255
if not repo.supports_rich_root():
3256
raise errors.BzrCommandError(
3257
"Can't join trees because %s doesn't support rich root data.\n"
3258
"You can use bzr upgrade on the repository."
3262
containing_tree.add_reference(sub_tree)
3263
except errors.BadReferenceTarget, e:
3264
# XXX: Would be better to just raise a nicely printable
3265
# exception from the real origin. Also below. mbp 20070306
3266
raise errors.BzrCommandError("Cannot join %s. %s" %
3270
containing_tree.subsume(sub_tree)
3271
except errors.BadSubsumeSource, e:
3272
raise errors.BzrCommandError("Cannot join %s. %s" %
3276
class cmd_split(Command):
3277
"""Split a tree into two trees.
3280
takes_args = ['tree']
3282
def run(self, tree):
3283
containing_tree, subdir = WorkingTree.open_containing(tree)
3284
sub_id = containing_tree.path2id(subdir)
3286
raise errors.NotVersionedError(subdir)
3288
containing_tree.extract(sub_id)
3289
except errors.RootNotRich:
3290
raise errors.UpgradeRequired(containing_tree.branch.base)
3294
class cmd_tag(Command):
3295
"""Create a tag naming a revision.
3297
Tags give human-meaningful names to revisions. Commands that take a -r
3298
(--revision) option can be given -rtag:X, where X is any previously
3301
Tags are stored in the branch. Tags are copied from one branch to another
3302
along when you branch, push, pull or merge.
3304
It is an error to give a tag name that already exists unless you pass
3305
--force, in which case the tag is moved to point to the new revision.
3308
takes_args = ['tag_name']
3311
help='Delete this tag rather than placing it.',
3314
help='Branch in which to place the tag.',
3319
help='Replace existing tags',
3324
def run(self, tag_name,
3330
branch, relpath = Branch.open_containing(directory)
3334
branch.tags.delete_tag(tag_name)
3335
self.outf.write('Deleted tag %s.\n' % tag_name)
3338
if len(revision) != 1:
3339
raise errors.BzrCommandError(
3340
"Tags can only be placed on a single revision, "
3342
revision_id = revision[0].in_history(branch).rev_id
3344
revision_id = branch.last_revision()
3345
if (not force) and branch.tags.has_tag(tag_name):
3346
raise errors.TagAlreadyExists(tag_name)
3347
branch.tags.set_tag(tag_name, revision_id)
3348
self.outf.write('Created tag %s.\n' % tag_name)
3353
class cmd_tags(Command):
3356
This tag shows a table of tag names and the revisions they reference.
3361
help='Branch whose tags should be displayed',
3371
branch, relpath = Branch.open_containing(directory)
3372
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3373
self.outf.write('%-20s %s\n' % (tag_name, target))
3167
3376
# command-line interpretation helper for merge-related commands
3168
3377
def _merge_helper(other_revision, base_revision,
3214
3423
" type %s." % merge_type)
3215
3424
if reprocess and show_base:
3216
3425
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3426
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3427
# only want to take out a lock_tree_write() if we don't have to pull
3428
# any ancestry. But merge might fetch ancestry in the middle, in
3429
# which case we would need a lock_write().
3430
# Because we cannot upgrade locks, for now we live with the fact that
3431
# the tree will be locked multiple times during a merge. (Maybe
3432
# read-only some of the time, but it means things will get read
3218
3435
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3219
3436
pb=pb, change_reporter=change_reporter)