1
# Copyright (C) 2004-2010 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
55
55
from bzrlib.branch import Branch
56
56
from bzrlib.conflicts import ConflictList
57
from bzrlib.transport import memory
57
58
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
58
59
from bzrlib.smtp_connection import SMTPConnection
59
60
from bzrlib.workingtree import WorkingTree
339
340
# cat-revision is more for frontends so should be exact
340
341
encoding = 'strict'
343
def print_revision(self, revisions, revid):
344
stream = revisions.get_record_stream([(revid,)], 'unordered', True)
345
record = stream.next()
346
if record.storage_kind == 'absent':
347
raise errors.NoSuchRevision(revisions, revid)
348
revtext = record.get_bytes_as('fulltext')
349
self.outf.write(revtext.decode('utf-8'))
343
352
def run(self, revision_id=None, revision=None):
344
353
if revision_id is not None and revision is not None:
349
358
' --revision or a revision_id')
350
359
b = WorkingTree.open_containing(u'.')[0].branch
352
# TODO: jam 20060112 should cat-revision always output utf-8?
353
if revision_id is not None:
354
revision_id = osutils.safe_revision_id(revision_id, warn=False)
356
self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
357
except errors.NoSuchRevision:
358
msg = "The repository %s contains no revision %s." % (b.repository.base,
360
raise errors.BzrCommandError(msg)
361
elif revision is not None:
364
raise errors.BzrCommandError('You cannot specify a NULL'
366
rev_id = rev.as_revision_id(b)
367
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
361
revisions = b.repository.revisions
362
if revisions is None:
363
raise errors.BzrCommandError('Repository %r does not support '
364
'access to raw revision texts')
366
b.repository.lock_read()
368
# TODO: jam 20060112 should cat-revision always output utf-8?
369
if revision_id is not None:
370
revision_id = osutils.safe_revision_id(revision_id, warn=False)
372
self.print_revision(revisions, revision_id)
373
except errors.NoSuchRevision:
374
msg = "The repository %s contains no revision %s." % (
375
b.repository.base, revision_id)
376
raise errors.BzrCommandError(msg)
377
elif revision is not None:
380
raise errors.BzrCommandError(
381
'You cannot specify a NULL revision.')
382
rev_id = rev.as_revision_id(b)
383
self.print_revision(revisions, rev_id)
385
b.repository.unlock()
370
388
class cmd_dump_btree(Command):
371
389
"""Dump the contents of a btree index file to stdout.
452
470
To re-create the working tree, use "bzr checkout".
454
472
_see_also = ['checkout', 'working-trees']
455
takes_args = ['location?']
473
takes_args = ['location*']
456
474
takes_options = [
458
476
help='Remove the working tree even if it has '
459
477
'uncommitted changes.'),
462
def run(self, location='.', force=False):
463
d = bzrdir.BzrDir.open(location)
466
working = d.open_workingtree()
467
except errors.NoWorkingTree:
468
raise errors.BzrCommandError("No working tree to remove")
469
except errors.NotLocalUrl:
470
raise errors.BzrCommandError("You cannot remove the working tree"
473
if (working.has_changes()):
474
raise errors.UncommittedChanges(working)
476
working_path = working.bzrdir.root_transport.base
477
branch_path = working.branch.bzrdir.root_transport.base
478
if working_path != branch_path:
479
raise errors.BzrCommandError("You cannot remove the working tree"
480
" from a lightweight checkout")
482
d.destroy_workingtree()
480
def run(self, location_list, force=False):
481
if not location_list:
484
for location in location_list:
485
d = bzrdir.BzrDir.open(location)
488
working = d.open_workingtree()
489
except errors.NoWorkingTree:
490
raise errors.BzrCommandError("No working tree to remove")
491
except errors.NotLocalUrl:
492
raise errors.BzrCommandError("You cannot remove the working tree"
495
if (working.has_changes()):
496
raise errors.UncommittedChanges(working)
498
working_path = working.bzrdir.root_transport.base
499
branch_path = working.branch.bzrdir.root_transport.base
500
if working_path != branch_path:
501
raise errors.BzrCommandError("You cannot remove the working tree"
502
" from a lightweight checkout")
504
d.destroy_workingtree()
485
507
class cmd_revno(Command):
3441
3463
def get_transport_type(typestring):
3442
3464
"""Parse and return a transport specifier."""
3443
3465
if typestring == "sftp":
3444
from bzrlib.transport.sftp import SFTPAbsoluteServer
3445
return SFTPAbsoluteServer
3466
from bzrlib.tests import stub_sftp
3467
return stub_sftp.SFTPAbsoluteServer
3446
3468
if typestring == "memory":
3447
from bzrlib.transport.memory import MemoryServer
3469
from bzrlib.tests import test_server
3470
return memory.MemoryServer
3449
3471
if typestring == "fakenfs":
3450
from bzrlib.transport.fakenfs import FakeNFSServer
3451
return FakeNFSServer
3472
from bzrlib.tests import test_server
3473
return test_server.FakeNFSServer
3452
3474
msg = "No known transport type %s. Supported types are: sftp\n" %\
3454
3476
raise errors.BzrCommandError(msg)
3777
3799
raise errors.BzrCommandError(
3778
3800
'Cannot use -r with merge directives or bundles')
3779
3801
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3782
3804
if merger is None and uncommitted:
3783
3805
if revision is not None and len(revision) > 0:
3784
3806
raise errors.BzrCommandError('Cannot use --uncommitted and'
3785
3807
' --revision at the same time.')
3786
merger = self.get_merger_from_uncommitted(tree, location, pb)
3808
merger = self.get_merger_from_uncommitted(tree, location, None)
3787
3809
allow_pending = False
3789
3811
if merger is None:
3790
3812
merger, allow_pending = self._get_merger_from_branch(tree,
3791
location, revision, remember, possible_transports, pb)
3813
location, revision, remember, possible_transports, None)
3793
3815
merger.merge_type = merge_type
3794
3816
merger.reprocess = reprocess
4065
4087
# list, we imply that the working tree text has seen and rejected
4066
4088
# all the changes from the other tree, when in fact those changes
4067
4089
# have not yet been seen.
4068
pb = ui.ui_factory.nested_progress_bar()
4069
4090
tree.set_parent_ids(parents[:1])
4071
merger = _mod_merge.Merger.from_revision_ids(pb,
4092
merger = _mod_merge.Merger.from_revision_ids(None, tree, parents[1])
4073
4093
merger.interesting_ids = interesting_ids
4074
4094
merger.merge_type = merge_type
4075
4095
merger.show_base = show_base
4153
4172
def _revert_tree_to_revision(tree, revision, file_list, no_backup):
4154
4173
rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
4155
pb = ui.ui_factory.nested_progress_bar()
4157
tree.revert(file_list, rev_tree, not no_backup, pb,
4158
report_changes=True)
4174
tree.revert(file_list, rev_tree, not no_backup, None,
4175
report_changes=True)
4163
4178
class cmd_assert_fail(Command):
5915
5930
from bzrlib.foreign import cmd_dpush
5916
5931
from bzrlib.sign_my_commits import cmd_sign_my_commits
5917
from bzrlib.weave_commands import cmd_versionedfile_list, \
5918
cmd_weave_plan_merge, cmd_weave_merge_text