22
22
import bzrlib.trace
23
23
from bzrlib.trace import mutter, note, log_error, warning
24
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
from bzrlib.branch import Branch
25
from bzrlib.branch import find_branch
26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command
73
73
def run(self, all=False, show_ids=False, file_list=None):
75
b = Branch.open_containing(file_list[0])
75
b = find_branch(file_list[0])
76
76
file_list = [b.relpath(x) for x in file_list]
77
77
# special case: only one path was given and it's the root
79
79
if file_list == ['']:
82
b = Branch.open_containing('.')
84
84
from bzrlib.status import show_status
85
85
show_status(b, show_unchanged=all, show_ids=show_ids,
89
89
class cmd_cat_revision(Command):
90
"""Write out metadata for a revision.
92
The revision to print can either be specified by a specific
93
revision identifier, or you can use --revision.
90
"""Write out metadata for a revision."""
97
takes_args = ['revision_id?']
98
takes_options = ['revision']
93
takes_args = ['revision_id']
100
def run(self, revision_id=None, revision=None):
101
from bzrlib.revisionspec import RevisionSpec
95
def run(self, revision_id):
97
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
103
if revision_id is not None and revision is not None:
104
raise BzrCommandError('You can only supply one of revision_id or --revision')
105
if revision_id is None and revision is None:
106
raise BzrCommandError('You must supply either --revision or a revision_id')
107
b = Branch.open_containing('.')
108
if revision_id is not None:
109
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
110
elif revision is not None:
113
raise BzrCommandError('You cannot specify a NULL revision.')
114
revno, rev_id = rev.in_history(b)
115
sys.stdout.write(b.get_revision_xml_file(rev_id).read())
118
100
class cmd_revno(Command):
119
101
"""Show current revision number.
121
103
This is equal to the number of revisions on this branch."""
123
print Branch.open_containing('.').revno()
105
print find_branch('.').revno()
126
108
class cmd_revision_info(Command):
130
112
takes_args = ['revision_info*']
131
113
takes_options = ['revision']
132
def run(self, revision=None, revision_info_list=[]):
133
from bzrlib.revisionspec import RevisionSpec
114
def run(self, revision=None, revision_info_list=None):
115
from bzrlib.branch import find_branch
136
118
if revision is not None:
137
119
revs.extend(revision)
138
120
if revision_info_list is not None:
139
for rev in revision_info_list:
140
revs.append(RevisionSpec(rev))
121
revs.extend(revision_info_list)
141
122
if len(revs) == 0:
142
123
raise BzrCommandError('You must supply a revision identifier')
144
b = Branch.open_containing('.')
147
revinfo = rev.in_history(b)
148
if revinfo.revno is None:
149
print ' %s' % revinfo.rev_id
151
print '%4d %s' % (revinfo.revno, revinfo.rev_id)
128
print '%4d %s' % b.get_revision_info(rev)
154
131
class cmd_add(Command):
217
194
takes_options = ['revision', 'show-ids']
219
196
def run(self, revision=None, show_ids=False):
220
b = Branch.open_containing('.')
222
199
inv = b.read_working_inventory()
224
201
if len(revision) > 1:
225
202
raise BzrCommandError('bzr inventory --revision takes'
226
203
' exactly one revision identifier')
227
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
204
inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
229
206
for path, entry in inv.entries():
244
221
takes_args = ['source$', 'dest']
245
222
def run(self, source_list, dest):
246
b = Branch.open_containing('.')
248
225
# TODO: glob expansion on windows?
249
226
b.move([b.relpath(s) for s in source_list], b.relpath(dest))
266
243
takes_args = ['from_name', 'to_name']
268
245
def run(self, from_name, to_name):
269
b = Branch.open_containing('.')
270
247
b.rename_one(b.relpath(from_name), b.relpath(to_name))
288
265
def run(self, names_list):
289
266
if len(names_list) < 2:
290
267
raise BzrCommandError("missing file argument")
291
b = Branch.open_containing(names_list[0])
268
b = find_branch(names_list[0])
293
270
rel_names = [b.relpath(x) for x in names_list]
328
305
from shutil import rmtree
331
br_to = Branch.open_containing('.')
332
stored_loc = br_to.get_parent()
308
br_to = find_branch('.')
311
stored_loc = br_to.controlfile("x-pull", "rb").read().rstrip('\n')
313
if e.errno != errno.ENOENT:
333
315
if location is None:
334
316
if stored_loc is None:
335
317
raise BzrCommandError("No pull location known or specified.")
337
319
print "Using last location: %s" % stored_loc
338
320
location = stored_loc
339
321
cache_root = tempfile.mkdtemp()
340
from bzrlib.errors import DivergedBranches
341
br_from = Branch.open_containing(location)
322
from bzrlib.branch import DivergedBranches
323
br_from = find_branch(location)
342
324
location = br_from.base
343
325
old_revno = br_to.revno()
345
from bzrlib.errors import DivergedBranches
346
br_from = Branch.open(location)
347
br_from.setup_caching(cache_root)
327
from branch import find_cached_branch, DivergedBranches
328
br_from = find_cached_branch(location, cache_root)
348
329
location = br_from.base
349
330
old_revno = br_to.revno()
356
337
merge(('.', -1), ('.', old_revno), check_clean=False)
357
338
if location != stored_loc:
358
br_to.set_parent(location)
339
br_to.controlfile("x-pull", "wb").write(location + "\n")
360
341
rmtree(cache_root)
375
356
aliases = ['get', 'clone']
377
358
def run(self, from_location, to_location=None, revision=None):
378
from bzrlib.branch import copy_branch
359
from bzrlib.branch import copy_branch, find_cached_branch
381
362
from shutil import rmtree
387
368
raise BzrCommandError(
388
369
'bzr branch --revision takes exactly 1 revision value')
390
br_from = Branch.open(from_location)
371
br_from = find_cached_branch(from_location, cache_root)
391
372
except OSError, e:
392
373
if e.errno == errno.ENOENT:
393
374
raise BzrCommandError('Source location "%s" does not'
394
375
' exist.' % to_location)
397
br_from.setup_caching(cache_root)
398
378
if to_location is None:
399
379
to_location = os.path.basename(from_location.rstrip("/\\"))
459
439
takes_options = ['verbose']
461
441
def run(self, file_list, verbose=False):
462
b = Branch.open_containing(file_list[0])
442
b = find_branch(file_list[0])
463
443
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
474
454
takes_args = ['filename']
475
455
def run(self, filename):
476
b = Branch.open_containing(filename)
456
b = find_branch(filename)
477
457
i = b.inventory.path2id(b.relpath(filename))
479
459
raise BzrError("%r is not a versioned file" % filename)
502
482
"""Display list of revision ids on this branch."""
505
for patchid in Branch.open_containing('.').revision_history():
485
for patchid in find_branch('.').revision_history():
509
489
class cmd_directories(Command):
510
490
"""Display list of versioned directories in this branch."""
512
for name, ie in Branch.open_containing('.').read_working_inventory().directories():
492
for name, ie in find_branch('.').read_working_inventory().directories():
569
549
from bzrlib.diff import show_diff
572
b = Branch.open_containing(file_list[0])
552
b = find_branch(file_list[0])
573
553
file_list = [b.relpath(f) for f in file_list]
574
554
if file_list == ['']:
575
555
# just pointing to top-of-tree
578
b = Branch.open_containing('.')
580
560
if revision is not None:
581
561
if len(revision) == 1:
624
604
from bzrlib.delta import compare_trees
626
b = Branch.open_containing('.')
627
607
td = compare_trees(b.basis_tree(), b.working_tree())
629
609
for path, id, kind in td.modified:
657
637
takes_args = ['filename?']
658
638
def run(self, filename=None):
659
639
"""Print the branch root."""
660
b = Branch.open_containing(filename)
640
b = find_branch(filename)
693
673
direction = (forward and 'forward') or 'reverse'
696
b = Branch.open_containing(filename)
676
b = find_branch(filename)
697
677
fp = b.relpath(filename)
699
679
file_id = b.read_working_inventory().path2id(fp)
701
681
file_id = None # points to branch root
703
b = Branch.open_containing('.')
706
686
if revision is None:
709
689
elif len(revision) == 1:
710
rev1 = rev2 = revision[0].in_history(b).revno
690
rev1 = rev2 = b.get_revision_info(revision[0])[0]
711
691
elif len(revision) == 2:
712
rev1 = revision[0].in_history(b).revno
713
rev2 = revision[1].in_history(b).revno
692
rev1 = b.get_revision_info(revision[0])[0]
693
rev2 = b.get_revision_info(revision[1])[0]
715
695
raise BzrCommandError('bzr log --revision takes one or two values.')
753
733
takes_args = ["filename"]
754
734
def run(self, filename):
755
b = Branch.open_containing(filename)
735
b = find_branch(filename)
756
736
inv = b.read_working_inventory()
757
737
file_id = inv.path2id(b.relpath(filename))
758
738
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
768
748
def run(self, revision=None, verbose=False):
769
b = Branch.open_containing('.')
770
750
if revision == None:
771
751
tree = b.working_tree()
773
tree = b.revision_tree(revision.in_history(b).rev_id)
753
tree = b.revision_tree(b.lookup_revision(revision))
775
755
for fp, fc, kind, fid in tree.list_files():
860
840
See also: bzr ignore"""
862
tree = Branch.open_containing('.').working_tree()
842
tree = find_branch('.').working_tree()
863
843
for path, file_class, kind, file_id in tree.list_files():
864
844
if file_class != 'I':
902
882
takes_options = ['revision', 'format', 'root']
903
883
def run(self, dest, revision=None, format=None, root=None):
905
b = Branch.open_containing('.')
906
886
if revision is None:
907
887
rev_id = b.last_patch()
909
889
if len(revision) != 1:
910
890
raise BzrError('bzr export --revision takes exactly 1 argument')
911
rev_id = revision[0].in_history(b).rev_id
891
revno, rev_id = b.get_revision_info(revision[0])
912
892
t = b.revision_tree(rev_id)
913
893
root, ext = os.path.splitext(dest)
930
910
takes_args = ['filename']
932
912
def run(self, filename, revision=None):
934
914
raise BzrCommandError("bzr cat requires a revision number")
935
915
elif len(revision) != 1:
936
916
raise BzrCommandError("bzr cat --revision takes exactly one number")
937
b = Branch.open_containing('.')
938
b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
918
b.print_file(b.relpath(filename), revision[0])
941
921
class cmd_local_time_offset(Command):
1013
993
This command checks various invariants about the branch storage to
1014
994
detect data corruption or bzr bugs.
996
If given the --update flag, it will update some optional fields
997
to help ensure data consistency.
1016
999
takes_args = ['dir?']
1018
1001
def run(self, dir='.'):
1019
1002
from bzrlib.check import check
1021
check(Branch.open_containing(dir))
1004
check(find_branch(dir))
1024
1007
class cmd_scan_cache(Command):
1133
1116
def run(self, branch, other):
1134
1117
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1136
branch1 = Branch.open_containing(branch)
1137
branch2 = Branch.open_containing(other)
1119
branch1 = find_branch(branch)
1120
branch2 = find_branch(other)
1139
1122
history_1 = branch1.revision_history()
1140
1123
history_2 = branch2.revision_history()
1203
1186
other = [branch, -1]
1205
1188
if len(revision) == 1:
1189
other = [branch, revision[0]]
1206
1190
base = [None, None]
1207
other = [branch, revision[0].in_history(branch).revno]
1209
1192
assert len(revision) == 2
1210
1193
if None in revision:
1211
1194
raise BzrCommandError(
1212
1195
"Merge doesn't permit that revision specifier.")
1213
from bzrlib.branch import Branch
1214
b = Branch.open(branch)
1216
base = [branch, revision[0].in_history(b).revno]
1217
other = [branch, revision[1].in_history(b).revno]
1196
base = [branch, revision[0]]
1197
other = [branch, revision[1]]
1220
1200
merge(other, base, check_clean=(not force), merge_type=merge_type)
1248
1228
if len(file_list) == 0:
1249
1229
raise BzrCommandError("No files specified")
1250
1230
if revision is None:
1252
1232
elif len(revision) != 1:
1253
1233
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1255
b = Branch.open_containing('.')
1256
revno = revision[0].in_history(b).revno
1257
merge(('.', revno), parse_spec('.'),
1234
merge(('.', revision[0]), parse_spec('.'),
1258
1235
check_clean=False,
1259
1236
ignore_zero=True,
1260
1237
backup_files=not no_backup,
1261
1238
file_list=file_list)
1262
1239
if not file_list:
1263
Branch.open_containing('.').set_pending_merges([])
1240
Branch('.').set_pending_merges([])
1266
1243
class cmd_assert_fail(Command):
1324
1301
print "Using last location: %s" % parent
1325
1302
remote = parent
1326
1303
elif parent is None:
1327
# We only update parent if it did not exist, missing
1328
# should not change the parent
1329
b.set_parent(remote)
1330
br_remote = Branch.open_containing(remote)
1304
# We only update x-pull if it did not exist, missing should not change the parent
1305
b.controlfile('x-pull', 'wb').write(remote + '\n')
1306
br_remote = find_branch(remote)
1331
1308
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1334
1312
class cmd_plugins(Command):
1335
1313
"""List plugins"""