~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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
54
54
    )
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'
341
342
 
 
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'))
 
350
 
342
351
    @display_command
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
351
360
 
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)
355
 
            try:
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,
359
 
                    revision_id)
360
 
                raise errors.BzrCommandError(msg)
361
 
        elif revision is not None:
362
 
            for rev in revision:
363
 
                if rev is None:
364
 
                    raise errors.BzrCommandError('You cannot specify a NULL'
365
 
                                                 ' revision.')
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')
368
365
 
 
366
        b.repository.lock_read()
 
367
        try:
 
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)
 
371
                try:
 
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:
 
378
                for rev in revision:
 
379
                    if rev is 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)
 
384
        finally:
 
385
            b.repository.unlock()
 
386
        
369
387
 
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".
453
471
    """
454
472
    _see_also = ['checkout', 'working-trees']
455
 
    takes_args = ['location?']
 
473
    takes_args = ['location*']
456
474
    takes_options = [
457
475
        Option('force',
458
476
               help='Remove the working tree even if it has '
459
477
                    'uncommitted changes.'),
460
478
        ]
461
479
 
462
 
    def run(self, location='.', force=False):
463
 
        d = bzrdir.BzrDir.open(location)
464
 
 
465
 
        try:
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"
471
 
                                         " of a remote path")
472
 
        if not force:
473
 
            if (working.has_changes()):
474
 
                raise errors.UncommittedChanges(working)
475
 
 
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")
481
 
 
482
 
        d.destroy_workingtree()
 
480
    def run(self, location_list, force=False):
 
481
        if not location_list:
 
482
            location_list=['.']
 
483
 
 
484
        for location in location_list:
 
485
            d = bzrdir.BzrDir.open(location)
 
486
            
 
487
            try:
 
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"
 
493
                                             " of a remote path")
 
494
            if not force:
 
495
                if (working.has_changes()):
 
496
                    raise errors.UncommittedChanges(working)
 
497
 
 
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")
 
503
 
 
504
            d.destroy_workingtree()
483
505
 
484
506
 
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
3448
 
            return 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" %\
3453
3475
            (typestring)
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,
3780
 
                   mergeable, pb)
 
3802
                   mergeable, None)
3781
3803
 
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
3788
3810
 
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)
3792
3814
 
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])
4070
4091
        try:
4071
 
            merger = _mod_merge.Merger.from_revision_ids(pb,
4072
 
                                                         tree, parents[1])
 
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
4077
4097
            conflicts = merger.do_merge()
4078
4098
        finally:
4079
4099
            tree.set_parent_ids(parents)
4080
 
            pb.finished()
4081
4100
        if conflicts > 0:
4082
4101
            return 1
4083
4102
        else:
4152
4171
    @staticmethod
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()
4156
 
        try:
4157
 
            tree.revert(file_list, rev_tree, not no_backup, pb,
4158
 
                report_changes=True)
4159
 
        finally:
4160
 
            pb.finished()
 
4174
        tree.revert(file_list, rev_tree, not no_backup, None,
 
4175
            report_changes=True)
4161
4176
 
4162
4177
 
4163
4178
class cmd_assert_fail(Command):
5914
5929
    )
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