358
359
action = bzrlib.add.AddAction(to_file=self.outf,
359
360
should_print=(not is_quiet()))
361
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
362
action=action, save=not dry_run)
363
base_tree.lock_read()
365
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
366
action=action, save=not dry_run)
368
if base_tree is not None:
363
370
if len(ignored) > 0:
365
372
for glob in sorted(ignored.keys()):
431
438
raise errors.BzrCommandError('invalid kind specified')
433
440
work_tree, file_list = tree_files(file_list)
435
if revision is not None:
436
if len(revision) > 1:
437
raise errors.BzrCommandError('bzr inventory --revision takes'
438
' exactly one revision identifier')
439
revision_id = revision[0].in_history(work_tree.branch).rev_id
440
tree = work_tree.branch.repository.revision_tree(revision_id)
442
# We include work_tree as well as 'tree' here
443
# So that doing '-r 10 path/foo' will lookup whatever file
444
# exists now at 'path/foo' even if it has been renamed, as
445
# well as whatever files existed in revision 10 at path/foo
446
trees = [tree, work_tree]
451
if file_list is not None:
452
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
453
require_versioned=True)
454
# find_ids_across_trees may include some paths that don't
456
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
457
for file_id in file_ids if file_id in tree)
459
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:
461
471
for path, entry in entries:
462
472
if kind and kind != entry.kind:
600
610
old_rh = branch_to.revision_history()
601
611
if tree_to is not None:
602
612
result = tree_to.pull(branch_from, overwrite, rev_id,
603
delta.ChangeReporter(tree_to.inventory))
613
delta.ChangeReporter(unversioned_filter=tree_to.is_ignored))
605
615
result = branch_to.pull(branch_from, overwrite, rev_id)
972
982
def run(self, dir=u'.'):
973
983
tree = WorkingTree.open_containing(dir)[0]
974
old_inv = tree.basis_tree().inventory
975
new_inv = tree.read_working_inventory()
976
renames = list(_mod_tree.find_renames(old_inv, new_inv))
978
for old_name, new_name in renames:
979
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))
982
1001
class cmd_update(Command):
1087
1106
@display_command
1088
1107
def run(self, filename):
1089
1108
tree, relpath = WorkingTree.open_containing(filename)
1090
i = tree.inventory.path2id(relpath)
1109
i = tree.path2id(relpath)
1092
1111
raise errors.NotVersionedError(filename)
1107
1126
@display_command
1108
1127
def run(self, filename):
1109
1128
tree, relpath = WorkingTree.open_containing(filename)
1110
inv = tree.inventory
1111
fid = inv.path2id(relpath)
1129
fid = tree.path2id(relpath)
1112
1130
if fid is None:
1113
1131
raise errors.NotVersionedError(filename)
1114
for fip in inv.get_idpath(fid):
1115
self.outf.write(fip + '\n')
1132
segments = osutils.splitpath(relpath)
1133
for pos in range(1, len(segments) + 1):
1134
path = osutils.joinpath(segments[:pos])
1135
self.outf.write("%s\n" % tree.path2id(path))
1118
1138
class cmd_reconcile(Command):
1423
1443
@display_command
1424
1444
def run(self, show_ids=False):
1425
1445
tree = WorkingTree.open_containing(u'.')[0]
1426
old = tree.basis_tree()
1427
for path, ie in old.inventory.iter_entries():
1428
if not tree.has_id(ie.file_id):
1429
self.outf.write(path)
1431
self.outf.write(' ')
1432
self.outf.write(ie.file_id)
1433
self.outf.write('\n')
1448
old = tree.basis_tree()
1451
for path, ie in old.inventory.iter_entries():
1452
if not tree.has_id(ie.file_id):
1453
self.outf.write(path)
1455
self.outf.write(' ')
1456
self.outf.write(ie.file_id)
1457
self.outf.write('\n')
1436
1464
class cmd_modified(Command):
1460
1488
@display_command
1462
1490
wt = WorkingTree.open_containing(u'.')[0]
1463
basis_inv = wt.basis_tree().inventory
1466
if file_id in basis_inv:
1468
if inv.is_root(file_id) and len(basis_inv) == 0:
1470
path = inv.id2path(file_id)
1471
if not os.access(osutils.abspath(path), os.F_OK):
1473
self.outf.write(path + '\n')
1493
basis = wt.basis_tree()
1496
basis_inv = basis.inventory
1499
if file_id in basis_inv:
1501
if inv.is_root(file_id) and len(basis_inv) == 0:
1503
path = inv.id2path(file_id)
1504
if not os.access(osutils.abspath(path), os.F_OK):
1506
self.outf.write(path + '\n')
1476
1513
class cmd_root(Command):
1637
1673
def run(self, filename):
1638
1674
tree, relpath = WorkingTree.open_containing(filename)
1639
1675
b = tree.branch
1640
inv = tree.read_working_inventory()
1641
file_id = inv.path2id(relpath)
1676
file_id = tree.path2id(relpath)
1642
1677
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
1643
1678
self.outf.write("%6d %s\n" % (revno, what))
1697
1732
elif tree is None:
1698
1733
tree = branch.basis_tree()
1700
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1701
if fp.startswith(relpath):
1702
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1703
if non_recursive and '/' in fp:
1705
if not all and not selection[fc]:
1707
if kind is not None and fkind != kind:
1710
kindch = entry.kind_character()
1711
outstring = '%-8s %s%s' % (fc, fp, kindch)
1712
if show_ids and fid is not None:
1713
outstring = "%-50s %s" % (outstring, fid)
1714
self.outf.write(outstring + '\n')
1716
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')
1718
1760
if fid is not None:
1719
self.outf.write(fid)
1720
self.outf.write('\0')
1728
self.outf.write('%-50s %s\n' % (fp, my_id))
1730
self.outf.write(fp + '\n')
1765
self.outf.write('%-50s %s\n' % (fp, my_id))
1767
self.outf.write(fp + '\n')
1733
1772
class cmd_unknowns(Command):
1841
1876
@display_command
1843
1878
tree = WorkingTree.open_containing(u'.')[0]
1844
for path, file_class, kind, file_id, entry in tree.list_files():
1845
if file_class != 'I':
1847
## XXX: Slightly inefficient since this was already calculated
1848
pat = tree.is_ignored(path)
1849
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)
1852
1891
class cmd_lookup_revision(Command):
2123
2162
value_switches=True, title='Branch format'),
2127
2165
def run(self, url='.', format=None):
2128
2166
from bzrlib.upgrade import upgrade
2129
2167
if format is None:
2439
2477
merge_type = _mod_merge.Merge3Merger
2441
2479
if directory is None: directory = u'.'
2480
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2481
# inventory. Because merge is a mutating operation, it really
2482
# should be a lock_write() for the whole cmd_merge operation.
2483
# However, cmd_merge open's its own tree in _merge_helper, which
2484
# means if we lock here, the later lock_write() will always block.
2485
# Either the merge helper code should be updated to take a tree,
2486
# (What about tree.merge_from_branch?)
2442
2487
tree = WorkingTree.open_containing(directory)[0]
2443
change_reporter = delta.ChangeReporter(tree.inventory)
2488
change_reporter = delta.ChangeReporter(
2489
unversioned_filter=tree.is_ignored)
2445
2491
if branch is not None:
2910
2956
raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
2912
2958
revision_id = revision[0].in_history(branch).rev_id
2913
file_id = tree.inventory.path2id(relpath)
2959
file_id = tree.path2id(relpath)
2914
2960
tree = branch.repository.revision_tree(revision_id)
2915
2961
file_version = tree.inventory[file_id].revision
2916
2962
annotate_file(branch, file_version, file_id, long, all, sys.stdout,
3178
3224
sys.stdout.flush()
3227
class cmd_join(Command):
3228
"""Combine a subtree into its containing tree.
3230
This is marked as a merge of the subtree into the containing tree, and all
3231
history is preserved.
3234
takes_args = ['tree']
3235
takes_options = [Option('reference', 'join by reference')]
3237
def run(self, tree, reference=False):
3238
sub_tree = WorkingTree.open(tree)
3239
parent_dir = osutils.dirname(sub_tree.basedir)
3240
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3241
repo = containing_tree.branch.repository
3242
if not repo.supports_rich_root():
3243
raise errors.BzrCommandError(
3244
"Can't join trees because %s doesn't support rich root data.\n"
3245
"You can use bzr upgrade on the repository."
3249
containing_tree.add_reference(sub_tree)
3250
except errors.BadReferenceTarget, e:
3251
# XXX: Would be better to just raise a nicely printable
3252
# exception from the real origin. Also below. mbp 20070306
3253
raise errors.BzrCommandError("Cannot join %s. %s" %
3257
containing_tree.subsume(sub_tree)
3258
except errors.BadSubsumeSource, e:
3259
raise errors.BzrCommandError("Cannot join %s. %s" %
3263
class cmd_split(Command):
3264
"""Split a tree into two trees.
3267
takes_args = ['tree']
3269
def run(self, tree):
3270
containing_tree, subdir = WorkingTree.open_containing(tree)
3271
sub_id = containing_tree.path2id(subdir)
3273
raise errors.NotVersionedError(subdir)
3275
containing_tree.extract(sub_id)
3276
except errors.RootNotRich:
3277
raise errors.UpgradeRequired(containing_tree.branch.base)
3182
3281
class cmd_tag(Command):
3183
3282
"""Create a tag naming a revision.
3311
3410
" type %s." % merge_type)
3312
3411
if reprocess and show_base:
3313
3412
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3413
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3414
# only want to take out a lock_tree_write() if we don't have to pull
3415
# any ancestry. But merge might fetch ancestry in the middle, in
3416
# which case we would need a lock_write().
3417
# Because we cannot upgrade locks, for now we live with the fact that
3418
# the tree will be locked multiple times during a merge. (Maybe
3419
# read-only some of the time, but it means things will get read
3315
3422
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3316
3423
pb=pb, change_reporter=change_reporter)