35
35
from bzrlib.workingtree import WorkingTree
38
def branch_files(file_list, default_branch='.'):
38
def tree_files(file_list, default_branch='.'):
40
40
Return a branch and list of branch-relative paths.
41
41
If supplied file_list is empty or None, the branch default will be used,
42
42
and returned file_list will match the original.
44
44
if file_list is None or len(file_list) == 0:
45
return Branch.open_containing(default_branch)[0], file_list
46
b = Branch.open_containing(file_list[0])[0]
48
# note that if this is a remote branch, we would want
49
# relpath against the transport. RBC 20051018
50
# Most branch ops can't meaningfully operate on files in remote branches;
51
# the above comment was in cmd_status. ADHB 20051026
52
tree = WorkingTree(b.base, b)
45
return WorkingTree.open_containing(default_branch)[0], file_list
46
tree = WorkingTree.open_containing(file_list[0])[0]
54
48
for filename in file_list:
56
50
new_list.append(tree.relpath(filename))
57
51
except NotBranchError:
58
raise BzrCommandError("%s is not in the same branch as %s" %
52
raise BzrCommandError("%s is not in the same tree as %s" %
59
53
(filename, file_list[0]))
63
57
# TODO: Make sure no commands unconditionally use the working directory as a
119
113
def run(self, all=False, show_ids=False, file_list=None, revision=None):
120
b, file_list = branch_files(file_list)
114
tree, file_list = tree_files(file_list)
122
116
from bzrlib.status import show_status
123
show_status(b, show_unchanged=all, show_ids=show_ids,
117
show_status(tree.branch, show_unchanged=all, show_ids=show_ids,
124
118
specific_files=file_list, revision=revision)
142
136
raise BzrCommandError('You can only supply one of revision_id or --revision')
143
137
if revision_id is None and revision is None:
144
138
raise BzrCommandError('You must supply either --revision or a revision_id')
145
b = Branch.open_containing('.')[0]
139
b = WorkingTree.open_containing('.')[0].branch
146
140
if revision_id is not None:
147
141
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
148
142
elif revision is not None:
261
256
def run(self, revision=None, show_ids=False):
262
b = Branch.open_containing('.')[0]
257
tree = WorkingTree.open_containing('.')[0]
263
258
if revision is None:
264
inv = b.working_tree().read_working_inventory()
259
inv = tree.read_working_inventory()
266
261
if len(revision) > 1:
267
262
raise BzrCommandError('bzr inventory --revision takes'
268
263
' exactly one revision identifier')
269
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
264
inv = tree.branch.get_revision_inventory(
265
revision[0].in_history(tree.branch).rev_id)
271
267
for path, entry in inv.entries():
286
282
takes_args = ['source$', 'dest']
287
283
def run(self, source_list, dest):
288
b, source_list = branch_files(source_list)
284
tree, source_list = tree_files(source_list)
290
286
# TODO: glob expansion on windows?
291
tree = WorkingTree(b.base, b)
292
b.move(source_list, tree.relpath(dest))
287
tree.branch.move(source_list, tree.relpath(dest))
295
290
class cmd_rename(Command):
309
304
takes_args = ['from_name', 'to_name']
311
306
def run(self, from_name, to_name):
312
b, (from_name, to_name) = branch_files((from_name, to_name))
313
b.rename_one(from_name, to_name)
307
tree, (from_name, to_name) = tree_files((from_name, to_name))
308
tree.branch.rename_one(from_name, to_name)
316
311
class cmd_mv(Command):
330
325
def run(self, names_list):
331
326
if len(names_list) < 2:
332
327
raise BzrCommandError("missing file argument")
333
b, rel_names = branch_files(names_list)
328
tree, rel_names = tree_files(names_list)
335
330
if os.path.isdir(names_list[-1]):
336
331
# move into existing directory
337
for pair in b.move(rel_names[:-1], rel_names[-1]):
332
for pair in tree.branch.move(rel_names[:-1], rel_names[-1]):
338
333
print "%s => %s" % pair
340
335
if len(names_list) != 2:
341
336
raise BzrCommandError('to mv multiple files the destination '
342
337
'must be a versioned directory')
343
b.rename_one(rel_names[0], rel_names[1])
338
tree.branch.rename_one(rel_names[0], rel_names[1])
344
339
print "%s => %s" % (rel_names[0], rel_names[1])
370
365
from shutil import rmtree
373
br_to = Branch.open_containing('.')[0]
374
stored_loc = br_to.get_parent()
368
tree_to = WorkingTree.open_containing('.')[0]
369
stored_loc = tree_to.branch.get_parent()
375
370
if location is None:
376
371
if stored_loc is None:
377
372
raise BzrCommandError("No pull location known or specified.")
380
375
location = stored_loc
381
376
br_from = Branch.open(location)
383
old_rh = br_to.revision_history()
384
br_to.working_tree().pull(br_from, overwrite)
378
old_rh = tree_to.branch.revision_history()
379
tree_to.pull(br_from, overwrite)
385
380
except DivergedBranches:
386
381
raise BzrCommandError("These branches have diverged."
388
if br_to.get_parent() is None or remember:
389
br_to.set_parent(location)
383
if tree_to.branch.get_parent() is None or remember:
384
tree_to.branch.set_parent(location)
392
new_rh = br_to.revision_history()
387
new_rh = tree_to.branch.revision_history()
393
388
if old_rh != new_rh:
394
389
# Something changed
395
390
from bzrlib.log import show_changed_revisions
396
show_changed_revisions(br_to, old_rh, new_rh)
391
show_changed_revisions(tree_to.branch, old_rh, new_rh)
399
394
class cmd_push(Command):
431
426
from shutil import rmtree
432
427
from bzrlib.transport import get_transport
434
br_from = Branch.open_containing('.')[0]
435
stored_loc = br_from.get_push_location()
429
tree_from = WorkingTree.open_containing('.')[0]
430
stored_loc = tree_from.branch.get_push_location()
436
431
if location is None:
437
432
if stored_loc is None:
438
433
raise BzrCommandError("No push location known or specified.")
470
465
br_to = Branch.initialize(location)
472
467
old_rh = br_to.revision_history()
473
br_to.pull(br_from, overwrite)
468
br_to.pull(tree_from.branch, overwrite)
474
469
except DivergedBranches:
475
470
raise BzrCommandError("These branches have diverged."
476
471
" Try a merge then push with overwrite.")
477
if br_from.get_push_location() is None or remember:
478
br_from.set_push_location(location)
472
if tree_from.branch.get_push_location() is None or remember:
473
tree_from.branch.set_push_location(location)
481
476
new_rh = br_to.revision_history()
484
479
from bzrlib.log import show_changed_revisions
485
480
show_changed_revisions(br_to, old_rh, new_rh)
487
483
class cmd_branch(Command):
488
484
"""Create a new copy of a branch.
574
570
def run(self, dir='.'):
575
b = Branch.open_containing(dir)[0]
576
old_inv = b.basis_tree().inventory
577
new_inv = b.working_tree().read_working_inventory()
571
tree = WorkingTree.open_containing(dir)[0]
572
old_inv = tree.branch.basis_tree().inventory
573
new_inv = tree.read_working_inventory()
579
575
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
606
602
def run(self, file_list, verbose=False):
607
b, file_list = branch_files(file_list)
608
tree = b.working_tree()
603
tree, file_list = tree_files(file_list)
609
604
tree.remove(file_list, verbose=verbose)
620
615
takes_args = ['filename']
622
617
def run(self, filename):
623
b, relpath = Branch.open_containing(filename)
624
i = b.inventory.path2id(relpath)
618
tree, relpath = WorkingTree.open_containing(filename)
619
i = tree.inventory.path2id(relpath)
626
621
raise BzrError("%r is not a versioned file" % filename)
637
632
takes_args = ['filename']
639
634
def run(self, filename):
640
b, relpath = Branch.open_containing(filename)
635
tree, relpath = WorkingTree.open_containing(filename)
642
637
fid = inv.path2id(relpath)
644
639
raise BzrError("%r is not a versioned file" % filename)
663
b = Branch.open_containing('.')[0]
659
tree = WorkingTree.open_containing('.')[0]
661
# FIXME. should be tree.last_revision
664
662
for revision_id in b.get_ancestry(b.last_revision()):
665
663
print revision_id
668
666
class cmd_directories(Command):
669
"""Display list of versioned directories in this branch."""
667
"""Display list of versioned directories in this tree."""
672
for name, ie in (Branch.open_containing('.')[0].working_tree().
670
for name, ie in (WorkingTree.open_containing('.')[0].
673
671
read_working_inventory().directories()):
739
737
def run(self, revision=None, file_list=None, diff_options=None):
740
738
from bzrlib.diff import show_diff
742
b, file_list = branch_files(file_list)
740
tree, file_list = tree_files(file_list)
743
741
if revision is not None:
744
742
if len(revision) == 1:
745
return show_diff(b, revision[0], specific_files=file_list,
743
return show_diff(tree.branch, revision[0], specific_files=file_list,
746
744
external_diff_options=diff_options)
747
745
elif len(revision) == 2:
748
return show_diff(b, revision[0], specific_files=file_list,
746
return show_diff(tree.branch, revision[0], specific_files=file_list,
749
747
external_diff_options=diff_options,
750
748
revision2=revision[1])
752
750
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
754
return show_diff(b, None, specific_files=file_list,
752
return show_diff(tree.branch, None, specific_files=file_list,
755
753
external_diff_options=diff_options)
766
764
# if the directories are very large...)
768
766
def run(self, show_ids=False):
769
b = Branch.open_containing('.')[0]
771
new = b.working_tree()
767
tree = WorkingTree.open_containing('.')[0]
768
old = tree.branch.basis_tree()
772
769
for path, ie in old.inventory.iter_entries():
773
if not new.has_id(ie.file_id):
770
if not tree.has_id(ie.file_id):
775
772
print '%-50s %s' % (path, ie.file_id)
785
782
from bzrlib.delta import compare_trees
787
b = Branch.open_containing('.')[0]
788
td = compare_trees(b.basis_tree(), b.working_tree())
784
tree = WorkingTree.open_containing('.')[0]
785
td = compare_trees(tree.branch.basis_tree(), tree)
790
787
for path, id, kind, text_modified, meta_modified in td.modified:
821
817
def run(self, filename=None):
822
818
"""Print the branch root."""
823
b = Branch.open_containing(filename)[0]
819
tree = WorkingTree.open_containing(filename)[0]
827
823
class cmd_log(Command):
863
859
direction = (forward and 'forward') or 'reverse'
866
b, fp = Branch.open_containing(filename)
865
tree, fp = WorkingTree.open_containing(filename)
868
inv = tree.read_working_inventory()
869
except NotBranchError:
872
b, fp = Branch.open_containing(filename)
874
inv = b.get_inventory(b.last_revision())
869
inv = b.working_tree().read_working_inventory()
870
except NoWorkingTree:
871
inv = b.get_inventory(b.last_revision())
872
876
file_id = inv.path2id(fp)
874
878
file_id = None # points to branch root
876
b, relpath = Branch.open_containing('.')
880
tree, relpath = WorkingTree.open_containing('.')
879
884
if revision is None:
927
932
takes_args = ["filename"]
929
934
def run(self, filename):
930
b, relpath = Branch.open_containing(filename)[0]
931
inv = b.working_tree().read_working_inventory()
935
tree, relpath = WorkingTree.open_containing(filename)
937
inv = tree.read_working_inventory()
932
938
file_id = inv.path2id(relpath)
933
939
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
934
940
print "%6d %s" % (revno, what)
963
969
selection = {'I':ignored, '?':unknown, 'V':versioned}
965
b, relpath = Branch.open_containing('.')
971
tree, relpath = WorkingTree.open_containing('.')
971
tree = b.working_tree()
973
tree = b.revision_tree(revision[0].in_history(b).rev_id)
976
if revision is not None:
977
tree = tree.branch.revision_tree(
978
revision[0].in_history(tree.branch).rev_id)
974
979
for fp, fc, kind, fid, entry in tree.list_files():
975
980
if fp.startswith(relpath):
976
981
fp = fp[len(relpath):]
993
997
class cmd_unknowns(Command):
994
998
"""List unknown files."""
997
1001
from bzrlib.osutils import quotefn
998
for f in Branch.open_containing('.')[0].unknowns():
1002
for f in WorkingTree.open_containing('.')[0].branch.unknowns():
999
1003
print quotefn(f)
1003
1006
class cmd_ignore(Command):
1004
1007
"""Ignore a command or pattern.
1025
1028
from bzrlib.atomicfile import AtomicFile
1028
b, relpath = Branch.open_containing('.')
1029
ifn = b.abspath('.bzrignore')
1031
tree, relpath = WorkingTree.open_containing('.')
1032
ifn = tree.abspath('.bzrignore')
1031
1034
if os.path.exists(ifn):
1032
1035
f = open(ifn, 'rt')
1054
inv = b.working_tree().inventory
1057
inv = tree.inventory
1055
1058
if inv.path2id('.bzrignore'):
1056
1059
mutter('.bzrignore is already versioned')
1058
1061
mutter('need to make new .bzrignore file versioned')
1059
b.add(['.bzrignore'])
1062
tree.branch.add(['.bzrignore'])
1063
1065
class cmd_ignored(Command):
1066
1068
See also: bzr ignore"""
1067
1069
@display_command
1069
tree = Branch.open_containing('.')[0].working_tree()
1071
tree = WorkingTree.open_containing('.')[0]
1070
1072
for path, file_class, kind, file_id, entry in tree.list_files():
1071
1073
if file_class != 'I':
1091
1093
except ValueError:
1092
1094
raise BzrCommandError("not a valid revision-number: %r" % revno)
1094
print Branch.open_containing('.')[0].get_rev_id(revno)
1096
print WorkingTree.open_containing('.')[0].branch.get_rev_id(revno)
1097
1099
class cmd_export(Command):
1110
1112
takes_options = ['revision', 'format', 'root']
1111
1113
def run(self, dest, revision=None, format=None, root=None):
1113
b = Branch.open_containing('.')[0]
1115
tree = WorkingTree.open_containing('.')[0]
1114
1117
if revision is None:
1115
rev_id = b.last_revision()
1118
# should be tree.last_revision FIXME
1119
rev_id = tree.branch.last_revision()
1117
1121
if len(revision) != 1:
1118
1122
raise BzrError('bzr export --revision takes exactly 1 argument')
1150
1154
raise BzrCommandError("bzr cat requires a revision number")
1151
1155
elif len(revision) != 1:
1152
1156
raise BzrCommandError("bzr cat --revision takes exactly one number")
1153
b, relpath = Branch.open_containing(filename)
1159
tree, relpath = WorkingTree.open_containing(filename)
1161
except NotBranchError:
1164
b, relpath = Branch.open_containing(filename)
1154
1165
b.print_file(relpath, revision[0].in_history(b).revno)
1206
1217
from bzrlib.status import show_status
1207
1218
from cStringIO import StringIO
1209
b, selected_list = branch_files(selected_list)
1220
tree, selected_list = tree_files(selected_list)
1210
1221
if message is None and not file:
1211
1222
catcher = StringIO()
1212
show_status(b, specific_files=selected_list,
1223
show_status(tree.branch, specific_files=selected_list,
1213
1224
to_file=catcher)
1214
1225
message = edit_commit_message(catcher.getvalue())
1227
1238
raise BzrCommandError("empty commit message specified")
1230
b.working_tree().commit(message, specific_files=selected_list,
1231
allow_pointless=unchanged, strict=strict)
1241
tree.commit(message, specific_files=selected_list,
1242
allow_pointless=unchanged, strict=strict)
1232
1243
except PointlessCommit:
1233
1244
# FIXME: This should really happen before the file is read in;
1234
1245
# perhaps prepare the commit; get the message; then actually commit
1254
1265
def run(self, dir='.', verbose=False):
1255
1266
from bzrlib.check import check
1256
check(Branch.open_containing(dir)[0], verbose)
1267
check(WorkingTree.open_containing(dir)[0].branch, verbose)
1259
1270
class cmd_scan_cache(Command):
1299
1310
@display_command
1300
1311
def run(self, email=False):
1302
b = bzrlib.branch.Branch.open_containing('.')[0]
1313
b = WorkingTree.open_containing('.')[0].branch
1303
1314
config = bzrlib.config.BranchConfig(b)
1304
1315
except NotBranchError:
1305
1316
config = bzrlib.config.GlobalConfig()
1525
1536
if revision is None:
1527
b = Branch.open_containing('.')[0]
1528
rev_id = b.last_revision()
1538
tree = WorkingTree.open_containing('.')[0]
1539
# FIXME should be tree.last_revision
1540
rev_id = tree.branch.last_revision()
1529
1541
elif len(revision) != 1:
1530
1542
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1532
b, file_list = branch_files(file_list)
1533
rev_id = revision[0].in_history(b).rev_id
1534
b.working_tree().revert(file_list, b.revision_tree(rev_id),
1544
tree, file_list = tree_files(file_list)
1545
rev_id = revision[0].in_history(tree.branch).rev_id
1546
tree.revert(file_list, tree.branch.revision_tree(rev_id),
1614
1626
if verbose and quiet:
1615
1627
raise BzrCommandError('Cannot pass both quiet and verbose')
1617
b = Branch.open_containing('.')[0]
1618
parent = b.get_parent()
1629
tree = WorkingTree.open_containing('.')[0]
1630
parent = tree.branch.get_parent()
1619
1631
if remote is None:
1620
1632
if parent is None:
1621
1633
raise BzrCommandError("No missing location known or specified.")
1626
1638
elif parent is None:
1627
1639
# We only update parent if it did not exist, missing
1628
1640
# should not change the parent
1629
b.set_parent(remote)
1641
tree.branch.set_parent(remote)
1630
1642
br_remote = Branch.open_containing(remote)[0]
1631
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1643
return show_missing(tree.branch, br_remote, verbose=verbose, quiet=quiet)
1634
1646
class cmd_plugins(Command):
1658
1670
@display_command
1659
1671
def run(self, branch='.', revision=None, long=False):
1660
1672
from bzrlib.testament import Testament
1661
b = Branch.open_containing(branch)[0]
1673
b = WorkingTree.open_containing(branch)[0].branch
1664
1676
if revision is None:
1696
1708
@display_command
1697
1709
def run(self, filename, all=False, long=False):
1698
1710
from bzrlib.annotate import annotate_file
1699
b, relpath = Branch.open_containing(filename)
1711
tree, relpath = WorkingTree.open_containing(filename)
1712
branch = tree.branch
1702
tree = WorkingTree(b.base, b)
1703
tree = b.revision_tree(b.last_revision())
1704
1715
file_id = tree.inventory.path2id(relpath)
1716
tree = branch.revision_tree(branch.last_revision())
1705
1717
file_version = tree.inventory[file_id].revision
1706
annotate_file(b, file_version, file_id, long, all, sys.stdout)
1718
annotate_file(branch, file_version, file_id, long, all, sys.stdout)
1711
1723
class cmd_re_sign(Command):
1723
1735
raise BzrCommandError('You can only supply one of revision_id or --revision')
1724
1736
if revision_id is None and revision is None:
1725
1737
raise BzrCommandError('You must supply either --revision or a revision_id')
1726
b = Branch.open_containing('.')[0]
1738
b = WorkingTree.open_containing('.')[0].branch
1727
1739
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1728
1740
if revision_id is not None:
1729
1741
b.sign_revision(revision_id, gpg_strategy)