23
from bzrlib.trace import mutter, note, log_error, warning
22
from bzrlib import BZRDIR
23
from bzrlib.commands import Command
24
from bzrlib.branch import Branch
24
25
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
25
26
from bzrlib.errors import DivergedBranches
26
from bzrlib.branch import Branch
27
from bzrlib import BZRDIR
28
from bzrlib.commands import Command
29
27
from bzrlib.option import Option
28
from bzrlib.revisionspec import RevisionSpec
30
from bzrlib.trace import mutter, note, log_error, warning
30
31
from bzrlib.workingtree import WorkingTree
79
80
def run(self, all=False, show_ids=False, file_list=None, revision=None):
81
b = Branch.open_containing(file_list[0])
82
tree = WorkingTree(b.base, b)
83
file_list = [tree.relpath(x) for x in file_list]
84
# special case: only one path was given and it's the root
82
b, relpath = Branch.open_containing(file_list[0])
83
if relpath == '' and len(file_list) == 1:
86
# generate relative paths.
87
# note that if this is a remote branch, we would want
88
# relpath against the transport. RBC 20051018
89
tree = WorkingTree(b.base, b)
90
file_list = [tree.relpath(x) for x in file_list]
89
b = Branch.open_containing('.')
92
b = Branch.open_containing('.')[0]
91
94
from bzrlib.status import show_status
92
95
show_status(b, show_unchanged=all, show_ids=show_ids,
105
108
takes_options = ['revision']
107
110
def run(self, revision_id=None, revision=None):
108
from bzrlib.revisionspec import RevisionSpec
110
112
if revision_id is not None and revision is not None:
111
113
raise BzrCommandError('You can only supply one of revision_id or --revision')
112
114
if revision_id is None and revision is None:
113
115
raise BzrCommandError('You must supply either --revision or a revision_id')
114
b = Branch.open_containing('.')
116
b = Branch.open_containing('.')[0]
115
117
if revision_id is not None:
116
118
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
117
119
elif revision is not None:
219
220
def run(self, filename):
220
branch = Branch.open_containing(filename)
221
print WorkingTree(branch.base, branch).relpath(filename)
221
branch, relpath = Branch.open_containing(filename)
224
225
class cmd_inventory(Command):
226
227
takes_options = ['revision', 'show-ids']
228
229
def run(self, revision=None, show_ids=False):
229
b = Branch.open_containing('.')
230
b = Branch.open_containing('.')[0]
230
231
if revision is None:
231
232
inv = b.read_working_inventory()
253
254
takes_args = ['source$', 'dest']
254
255
def run(self, source_list, dest):
255
b = Branch.open_containing('.')
256
b = Branch.open_containing('.')[0]
257
258
# TODO: glob expansion on windows?
258
259
tree = WorkingTree(b.base, b)
276
277
takes_args = ['from_name', 'to_name']
278
279
def run(self, from_name, to_name):
279
b = Branch.open_containing('.')
280
b = Branch.open_containing('.')[0]
280
281
tree = WorkingTree(b.base, b)
281
282
b.rename_one(tree.relpath(from_name), tree.relpath(to_name))
298
299
def run(self, names_list):
299
300
if len(names_list) < 2:
300
301
raise BzrCommandError("missing file argument")
301
b = Branch.open_containing(names_list[0])
302
b = Branch.open_containing(names_list[0])[0]
302
303
tree = WorkingTree(b.base, b)
303
304
rel_names = [tree.relpath(x) for x in names_list]
486
487
def run(self, file_list, verbose=False):
487
b = Branch.open_containing(file_list[0])
488
b = Branch.open_containing(file_list[0])[0]
488
489
tree = WorkingTree(b.base, b)
489
b.remove([tree.relpath(f) for f in file_list], verbose=verbose)
490
tree.remove([tree.relpath(f) for f in file_list], verbose=verbose)
492
493
class cmd_file_id(Command):
500
501
takes_args = ['filename']
501
502
def run(self, filename):
502
b = Branch.open_containing(filename)
503
tree = WorkingTree(b.base, b)
504
i = b.inventory.path2id(tree.relpath(filename))
503
b, relpath = Branch.open_containing(filename)
504
i = b.inventory.path2id(relpath)
506
506
raise BzrError("%r is not a versioned file" % filename)
517
517
takes_args = ['filename']
518
518
def run(self, filename):
519
b = Branch.open_containing(filename)
519
b, relpath = Branch.open_containing(filename)
520
520
inv = b.inventory
521
tree = WorkingTree(b.base, b)
522
fid = inv.path2id(tree.relpath(filename))
521
fid = inv.path2id(relpath)
524
523
raise BzrError("%r is not a versioned file" % filename)
525
524
for fip in inv.get_idpath(fid):
546
545
class cmd_directories(Command):
547
546
"""Display list of versioned directories in this branch."""
549
for name, ie in Branch.open_containing('.').read_working_inventory().directories():
548
for name, ie in Branch.open_containing('.')[0].read_working_inventory().directories():
603
602
from bzrlib.diff import show_diff
606
b = Branch.open_containing(file_list[0])
605
b = Branch.open_containing(file_list[0])[0]
607
606
tree = WorkingTree(b.base, b)
608
607
file_list = [tree.relpath(f) for f in file_list]
609
608
if file_list == ['']:
610
609
# just pointing to top-of-tree
613
b = Branch.open_containing('.')
612
b = Branch.open_containing('.')[0]
615
614
if revision is not None:
616
615
if len(revision) == 1:
639
638
# level of effort but possibly much less IO. (Or possibly not,
640
639
# if the directories are very large...)
641
640
def run(self, show_ids=False):
642
b = Branch.open_containing('.')
641
b = Branch.open_containing('.')[0]
643
642
old = b.basis_tree()
644
643
new = b.working_tree()
645
644
for path, ie in old.inventory.iter_entries():
657
656
from bzrlib.delta import compare_trees
659
b = Branch.open_containing('.')
658
b = Branch.open_containing('.')[0]
660
659
td = compare_trees(b.basis_tree(), b.working_tree())
662
661
for path, id, kind, text_modified, meta_modified in td.modified:
690
689
takes_args = ['filename?']
691
690
def run(self, filename=None):
692
691
"""Print the branch root."""
693
b = Branch.open_containing(filename)
692
b = Branch.open_containing(filename)[0]
733
732
direction = (forward and 'forward') or 'reverse'
736
b = Branch.open_containing(filename)
737
tree = WorkingTree(b.base, b)
738
fp = tree.relpath(filename)
735
b, fp = Branch.open_containing(filename)
740
737
file_id = b.read_working_inventory().path2id(fp)
742
739
file_id = None # points to branch root
744
b = Branch.open_containing('.')
741
b, relpath = Branch.open_containing('.')
747
744
if revision is None:
795
792
takes_args = ["filename"]
796
793
def run(self, filename):
797
b = Branch.open_containing(filename)
794
b, relpath = Branch.open_containing(filename)[0]
798
795
inv = b.read_working_inventory()
799
tree = WorkingTree(b.base, b)
800
file_id = inv.path2id(tree.relpath(filename))
796
file_id = inv.path2id(relpath)
801
797
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
802
798
print "%6d %s" % (revno, what)
808
804
# TODO: Take a revision or remote path and list that tree instead.
810
806
def run(self, revision=None, verbose=False):
811
b = Branch.open_containing('.')
807
b, relpath = Branch.open_containing('.')[0]
812
808
if revision == None:
813
809
tree = b.working_tree()
897
893
See also: bzr ignore"""
899
tree = Branch.open_containing('.').working_tree()
895
tree = Branch.open_containing('.')[0].working_tree()
900
896
for path, file_class, kind, file_id, entry in tree.list_files():
901
897
if file_class != 'I':
939
935
takes_options = ['revision', 'format', 'root']
940
936
def run(self, dest, revision=None, format=None, root=None):
942
b = Branch.open_containing('.')
938
b = Branch.open_containing('.')[0]
943
939
if revision is None:
944
940
rev_id = b.last_revision()
978
974
raise BzrCommandError("bzr cat requires a revision number")
979
975
elif len(revision) != 1:
980
976
raise BzrCommandError("bzr cat --revision takes exactly one number")
981
b = Branch.open_containing('.')
982
tree = WorkingTree(b.base, b)
983
b.print_file(tree.relpath(filename), revision[0].in_history(b).revno)
977
b, relpath = Branch.open_containing(filename)
978
b.print_file(relpath, revision[0].in_history(b).revno)
986
981
class cmd_local_time_offset(Command):
1034
1029
from bzrlib.status import show_status
1035
1030
from cStringIO import StringIO
1037
b = Branch.open_containing('.')
1032
b = Branch.open_containing('.')[0]
1038
1033
tree = WorkingTree(b.base, b)
1039
1034
if selected_list:
1040
1035
selected_list = [tree.relpath(s) for s in selected_list]
1085
1080
def run(self, dir='.', verbose=False):
1086
1081
from bzrlib.check import check
1087
check(Branch.open_containing(dir), verbose)
1082
check(Branch.open_containing(dir)[0], verbose)
1090
1085
class cmd_scan_cache(Command):
1130
1125
def run(self, email=False):
1132
b = bzrlib.branch.Branch.open_containing('.')
1127
b = bzrlib.branch.Branch.open_containing('.')[0]
1133
1128
config = bzrlib.config.BranchConfig(b)
1134
1129
except NotBranchError:
1135
1130
config = bzrlib.config.GlobalConfig()
1221
1216
def run(self, branch, other):
1222
1217
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1224
branch1 = Branch.open_containing(branch)
1225
branch2 = Branch.open_containing(other)
1219
branch1 = Branch.open_containing(branch)[0]
1220
branch2 = Branch.open_containing(other)[0]
1227
1222
history_1 = branch1.revision_history()
1228
1223
history_2 = branch2.revision_history()
1343
1338
elif len(revision) != 1:
1344
1339
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1346
b = Branch.open_containing('.')
1341
b = Branch.open_containing('.')[0]
1347
1342
revno = revision[0].in_history(b).revno
1348
1343
merge(('.', revno), parse_spec('.'),
1349
1344
check_clean=False,
1436
1431
# We only update parent if it did not exist, missing
1437
1432
# should not change the parent
1438
1433
b.set_parent(remote)
1439
br_remote = Branch.open_containing(remote)
1434
br_remote = Branch.open_containing(remote)[0]
1440
1435
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1465
1460
takes_args = ['branch?']
1466
1461
def run(self, branch='.', revision=None, long=False):
1467
1462
from bzrlib.testament import Testament
1468
b = Branch.open_containing(branch)
1463
b = Branch.open_containing(branch)[0]
1471
1466
if revision is None:
1503
1498
def run(self, filename, all=False, long=False):
1504
1499
from bzrlib.annotate import annotate_file
1505
b = Branch.open_containing(filename)
1500
b, relpath = Branch.open_containing(filename)
1508
1503
tree = WorkingTree(b.base, b)
1509
rp = tree.relpath(filename)
1510
1504
tree = b.revision_tree(b.last_revision())
1511
file_id = tree.inventory.path2id(rp)
1505
file_id = tree.inventory.path2id(relpath)
1512
1506
file_version = tree.inventory[file_id].revision
1513
1507
annotate_file(b, file_version, file_id, long, all, sys.stdout)
1512
class cmd_re_sign(Command):
1513
"""Create a digital signature for an existing revision."""
1514
# TODO be able to replace existing ones.
1516
hidden = True # is this right ?
1517
takes_args = ['revision_id?']
1518
takes_options = ['revision']
1520
def run(self, revision_id=None, revision=None):
1521
import bzrlib.config as config
1522
import bzrlib.gpg as gpg
1523
if revision_id is not None and revision is not None:
1524
raise BzrCommandError('You can only supply one of revision_id or --revision')
1525
if revision_id is None and revision is None:
1526
raise BzrCommandError('You must supply either --revision or a revision_id')
1527
b = Branch.open_containing('.')[0]
1528
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1529
if revision_id is not None:
1530
b.sign_revision(revision_id, gpg_strategy)
1531
elif revision is not None:
1532
for rev in revision:
1534
raise BzrCommandError('You cannot specify a NULL revision.')
1535
revno, rev_id = rev.in_history(b)
1536
b.sign_revision(rev_id, gpg_strategy)
1517
1539
# these get imported and then picked up by the scan for cmd_*
1518
1540
# TODO: Some more consistent way to split command definitions across files;
1519
1541
# we do need to load at least some information about them to know of