~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-01 23:10:02 UTC
  • mto: This revision was merged to the branch mainline in revision 6338.
  • Revision ID: jelmer@samba.org-20111201231002-6u7hjlzddpjybfn3
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009-2012 Canonical Ltd.
 
1
# Copyright (C) 2007, 2009, 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
# Original author: David Allouche
20
18
 
21
19
from bzrlib import errors, merge, revision
45
43
        source_repository = control_dir.open_branch().repository
46
44
    except errors.NotBranchError:
47
45
        source_repository = to_branch.repository
48
 
    to_branch.lock_read()
49
 
    try:
50
 
        _set_branch_location(control_dir, to_branch, force)
51
 
    finally:
52
 
        to_branch.unlock()
 
46
    _set_branch_location(control_dir, to_branch, force)
53
47
    tree = control_dir.open_workingtree()
54
48
    _update(tree, source_repository, quiet, revision_id)
55
49
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
105
99
                        'Unable to connect to current master branch %(target)s: '
106
100
                        '%(error)s To switch anyway, use --force.') %
107
101
                        e.__dict__)
108
 
            b.lock_write()
109
 
            try:
110
 
                b.set_bound_location(None)
111
 
                b.pull(to_branch, overwrite=True,
112
 
                       possible_transports=possible_transports)
113
 
                b.set_bound_location(to_branch.base)
114
 
                b.set_parent(b.get_master_branch().get_parent())
115
 
            finally:
116
 
                b.unlock()
 
102
            b.set_bound_location(None)
 
103
            b.pull(to_branch, overwrite=True,
 
104
                possible_transports=possible_transports)
 
105
            b.set_bound_location(to_branch.base)
 
106
            b.set_parent(b.get_master_branch().get_parent())
117
107
        else:
118
 
            # If this is a standalone tree and the new branch
119
 
            # is derived from this one, create a lightweight checkout.
120
 
            b.lock_read()
121
 
            try:
122
 
                graph = b.repository.get_graph(to_branch.repository)
123
 
                if (b.bzrdir._format.colocated_branches and
124
 
                     (force or graph.is_ancestor(b.last_revision(),
125
 
                        to_branch.last_revision()))):
126
 
                    b.bzrdir.destroy_branch()
127
 
                    b.bzrdir.set_branch_reference(to_branch, name="")
128
 
                else:
129
 
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
130
 
                        'only a checkout.'))
131
 
            finally:
132
 
                b.unlock()
 
108
            raise errors.BzrCommandError(gettext('Cannot switch a branch, '
 
109
                'only a checkout.'))
133
110
 
134
111
 
135
112
def _any_local_commits(this_branch, possible_transports):