~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-17 08:59:19 UTC
  • mfrom: (5037.2.1 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100217085919-23vc62bvq8848q65
(mbp) rest markup fixes

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
452
453
    To re-create the working tree, use "bzr checkout".
453
454
    """
454
455
    _see_also = ['checkout', 'working-trees']
455
 
    takes_args = ['location?']
 
456
    takes_args = ['location*']
456
457
    takes_options = [
457
458
        Option('force',
458
459
               help='Remove the working tree even if it has '
459
460
                    'uncommitted changes.'),
460
461
        ]
461
462
 
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()
 
463
    def run(self, location_list, force=False):
 
464
        if not location_list:
 
465
            location_list=['.']
 
466
 
 
467
        for location in location_list:
 
468
            d = bzrdir.BzrDir.open(location)
 
469
            
 
470
            try:
 
471
                working = d.open_workingtree()
 
472
            except errors.NoWorkingTree:
 
473
                raise errors.BzrCommandError("No working tree to remove")
 
474
            except errors.NotLocalUrl:
 
475
                raise errors.BzrCommandError("You cannot remove the working tree"
 
476
                                             " of a remote path")
 
477
            if not force:
 
478
                if (working.has_changes()):
 
479
                    raise errors.UncommittedChanges(working)
 
480
 
 
481
            working_path = working.bzrdir.root_transport.base
 
482
            branch_path = working.branch.bzrdir.root_transport.base
 
483
            if working_path != branch_path:
 
484
                raise errors.BzrCommandError("You cannot remove the working tree"
 
485
                                             " from a lightweight checkout")
 
486
 
 
487
            d.destroy_workingtree()
483
488
 
484
489
 
485
490
class cmd_revno(Command):
2191
2196
    :Tips & tricks:
2192
2197
 
2193
2198
      GUI tools and IDEs are often better at exploring history than command
2194
 
      line tools. You may prefer qlog or viz from the QBzr and Bzr-Gtk packages
2195
 
      respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
2196
 
      http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
2197
 
 
2198
 
      Web interfaces are often better at exploring history than command line
2199
 
      tools, particularly for branches on servers. You may prefer Loggerhead
2200
 
      or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
 
2199
      line tools: you may prefer qlog or viz from qbzr or bzr-gtk, the
 
2200
      bzr-explorer shell, or the Loggerhead web interface.  See the Plugin
 
2201
      Guide <http://doc.bazaar.canonical.com/plugins/en/> and
 
2202
      <http://wiki.bazaar.canonical.com/IDEIntegration>.  
2201
2203
 
2202
2204
      You may find it useful to add the aliases below to ``bazaar.conf``::
2203
2205
 
3444
3446
    def get_transport_type(typestring):
3445
3447
        """Parse and return a transport specifier."""
3446
3448
        if typestring == "sftp":
3447
 
            from bzrlib.transport.sftp import SFTPAbsoluteServer
3448
 
            return SFTPAbsoluteServer
 
3449
            from bzrlib.tests import stub_sftp
 
3450
            return stub_sftp.SFTPAbsoluteServer
3449
3451
        if typestring == "memory":
3450
 
            from bzrlib.transport.memory import MemoryServer
3451
 
            return MemoryServer
 
3452
            from bzrlib.tests import test_server
 
3453
            return memory.MemoryServer
3452
3454
        if typestring == "fakenfs":
3453
 
            from bzrlib.transport.fakenfs import FakeNFSServer
3454
 
            return FakeNFSServer
 
3455
            from bzrlib.tests import test_server
 
3456
            return test_server.FakeNFSServer
3455
3457
        msg = "No known transport type %s. Supported types are: sftp\n" %\
3456
3458
            (typestring)
3457
3459
        raise errors.BzrCommandError(msg)
3780
3782
                    raise errors.BzrCommandError(
3781
3783
                        'Cannot use -r with merge directives or bundles')
3782
3784
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
3783
 
                   mergeable, pb)
 
3785
                   mergeable, None)
3784
3786
 
3785
3787
        if merger is None and uncommitted:
3786
3788
            if revision is not None and len(revision) > 0:
3787
3789
                raise errors.BzrCommandError('Cannot use --uncommitted and'
3788
3790
                    ' --revision at the same time.')
3789
 
            merger = self.get_merger_from_uncommitted(tree, location, pb)
 
3791
            merger = self.get_merger_from_uncommitted(tree, location, None)
3790
3792
            allow_pending = False
3791
3793
 
3792
3794
        if merger is None:
3793
3795
            merger, allow_pending = self._get_merger_from_branch(tree,
3794
 
                location, revision, remember, possible_transports, pb)
 
3796
                location, revision, remember, possible_transports, None)
3795
3797
 
3796
3798
        merger.merge_type = merge_type
3797
3799
        merger.reprocess = reprocess
4068
4070
        # list, we imply that the working tree text has seen and rejected
4069
4071
        # all the changes from the other tree, when in fact those changes
4070
4072
        # have not yet been seen.
4071
 
        pb = ui.ui_factory.nested_progress_bar()
4072
4073
        tree.set_parent_ids(parents[:1])
4073
4074
        try:
4074
 
            merger = _mod_merge.Merger.from_revision_ids(pb,
4075
 
                                                         tree, parents[1])
 
4075
            merger = _mod_merge.Merger.from_revision_ids(None, tree, parents[1])
4076
4076
            merger.interesting_ids = interesting_ids
4077
4077
            merger.merge_type = merge_type
4078
4078
            merger.show_base = show_base
4080
4080
            conflicts = merger.do_merge()
4081
4081
        finally:
4082
4082
            tree.set_parent_ids(parents)
4083
 
            pb.finished()
4084
4083
        if conflicts > 0:
4085
4084
            return 1
4086
4085
        else:
4155
4154
    @staticmethod
4156
4155
    def _revert_tree_to_revision(tree, revision, file_list, no_backup):
4157
4156
        rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
4158
 
        pb = ui.ui_factory.nested_progress_bar()
4159
 
        try:
4160
 
            tree.revert(file_list, rev_tree, not no_backup, pb,
4161
 
                report_changes=True)
4162
 
        finally:
4163
 
            pb.finished()
 
4157
        tree.revert(file_list, rev_tree, not no_backup, None,
 
4158
            report_changes=True)
4164
4159
 
4165
4160
 
4166
4161
class cmd_assert_fail(Command):
4408
4403
    adding new commands, providing additional network transports and
4409
4404
    customizing log output.
4410
4405
 
4411
 
    See the Bazaar web site, http://bazaar-vcs.org, for further
4412
 
    information on plugins including where to find them and how to
4413
 
    install them. Instructions are also provided there on how to
4414
 
    write new plugins using the Python programming language.
 
4406
    See the Bazaar Plugin Guide <http://doc.bazaar.canonical.com/plugins/en/>
 
4407
    for further information on plugins including where to find them and how to
 
4408
    install them. Instructions are also provided there on how to write new
 
4409
    plugins using the Python programming language.
4415
4410
    """
4416
4411
    takes_options = ['verbose']
4417
4412
 
4615
4610
                    'This format does not remember old locations.')
4616
4611
            else:
4617
4612
                if location is None:
4618
 
                    raise errors.BzrCommandError('No location supplied and no '
4619
 
                        'previous location known')
 
4613
                    if b.get_bound_location() is not None:
 
4614
                        raise errors.BzrCommandError('Branch is already bound')
 
4615
                    else:
 
4616
                        raise errors.BzrCommandError('No location supplied '
 
4617
                            'and no previous location known')
4620
4618
        b_other = Branch.open(location)
4621
4619
        try:
4622
4620
            b.bind(b_other)
4719
4717
                rev_id = b.get_rev_id(revno)
4720
4718
 
4721
4719
        if rev_id is None or _mod_revision.is_null(rev_id):
4722
 
            self.outf.write('No revisions to uncommit.\n')
 
4720
            ui.ui_factory.note('No revisions to uncommit.')
4723
4721
            return 1
4724
4722
 
 
4723
        log_collector = ui.ui_factory.make_output_stream()
4725
4724
        lf = log_formatter('short',
4726
 
                           to_file=self.outf,
 
4725
                           to_file=log_collector,
4727
4726
                           show_timezone='original')
4728
4727
 
4729
4728
        show_log(b,
4734
4733
                 end_revision=last_revno)
4735
4734
 
4736
4735
        if dry_run:
4737
 
            print 'Dry-run, pretending to remove the above revisions.'
4738
 
            if not force:
4739
 
                val = raw_input('Press <enter> to continue')
 
4736
            ui.ui_factory.note('Dry-run, pretending to remove the above revisions.')
4740
4737
        else:
4741
 
            print 'The above revision(s) will be removed.'
4742
 
            if not force:
4743
 
                val = raw_input('Are you sure [y/N]? ')
4744
 
                if val.lower() not in ('y', 'yes'):
4745
 
                    print 'Canceled'
4746
 
                    return 0
 
4738
            ui.ui_factory.note('The above revision(s) will be removed.')
 
4739
 
 
4740
        if not force:
 
4741
            if not ui.ui_factory.get_boolean('Are you sure [y/N]? '):
 
4742
                ui.ui_factory.note('Canceled')
 
4743
                return 0
4747
4744
 
4748
4745
        mutter('Uncommitting from {%s} to {%s}',
4749
4746
               last_rev_id, rev_id)
4750
4747
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
4751
4748
                 revno=revno, local=local)
4752
 
        note('You can restore the old tip by running:\n'
4753
 
             '  bzr pull . -r revid:%s', last_rev_id)
 
4749
        ui.ui_factory.note('You can restore the old tip by running:\n'
 
4750
             '  bzr pull . -r revid:%s' % last_rev_id)
4754
4751
 
4755
4752
 
4756
4753
class cmd_break_lock(Command):
5915
5912
    )
5916
5913
from bzrlib.foreign import cmd_dpush
5917
5914
from bzrlib.sign_my_commits import cmd_sign_my_commits
5918
 
from bzrlib.weave_commands import cmd_versionedfile_list, \
5919
 
        cmd_weave_plan_merge, cmd_weave_merge_text