/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# Original author: David Allouche
20
20
 
21
 
from . import (
 
21
from bzrlib import (
22
22
    errors,
23
23
    lock,
24
24
    merge,
25
25
    revision
26
26
    )
27
 
from .branch import Branch
28
 
from .i18n import gettext
29
 
from .trace import note
 
27
from bzrlib.branch import Branch
 
28
from bzrlib.i18n import gettext
 
29
from bzrlib.trace import note
30
30
 
31
31
def _run_post_switch_hooks(control_dir, to_branch, force, revision_id):
32
 
    from .branch import SwitchHookParams
 
32
    from bzrlib.branch import SwitchHookParams
33
33
    hooks = Branch.hooks['post_switch']
34
34
    if not hooks:
35
35
        return
56
56
    if store_uncommitted:
57
57
        with lock.write_locked(control_dir.open_workingtree()) as tree:
58
58
            tree.store_uncommitted()
59
 
    with to_branch.lock_read():
 
59
    to_branch.lock_read()
 
60
    try:
60
61
        _set_branch_location(control_dir, to_branch, force)
 
62
    finally:
 
63
        to_branch.unlock()
61
64
    tree = control_dir.open_workingtree()
62
65
    _update(tree, source_repository, quiet, revision_id, store_uncommitted)
63
66
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
69
72
    """
70
73
    try:
71
74
        tree = control.open_workingtree()
72
 
    except errors.NotBranchError as ex:
 
75
    except errors.NotBranchError, ex:
73
76
        # Lightweight checkout and branch is no longer there
74
77
        if force:
75
78
            return
108
111
                        'Cannot switch as local commits found in the checkout. '
109
112
                        'Commit these to the bound branch or use --force to '
110
113
                        'throw them away.'))
111
 
            except errors.BoundBranchConnectionFailure as e:
 
114
            except errors.BoundBranchConnectionFailure, e:
112
115
                raise errors.BzrCommandError(gettext(
113
116
                        'Unable to connect to current master branch %(target)s: '
114
117
                        '%(error)s To switch anyway, use --force.') %
125
128
        else:
126
129
            # If this is a standalone tree and the new branch
127
130
            # is derived from this one, create a lightweight checkout.
128
 
            with b.lock_read():
 
131
            b.lock_read()
 
132
            try:
129
133
                graph = b.repository.get_graph(to_branch.repository)
130
 
                if (b.controldir._format.colocated_branches and
 
134
                if (b.bzrdir._format.colocated_branches and
131
135
                     (force or graph.is_ancestor(b.last_revision(),
132
136
                        to_branch.last_revision()))):
133
 
                    b.controldir.destroy_branch()
134
 
                    b.controldir.set_branch_reference(to_branch, name="")
 
137
                    b.bzrdir.destroy_branch()
 
138
                    b.bzrdir.set_branch_reference(to_branch, name="")
135
139
                else:
136
140
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
137
141
                        'only a checkout.'))
 
142
            finally:
 
143
                b.unlock()
138
144
 
139
145
 
140
146
def _any_local_commits(this_branch, possible_transports):
142
148
    last_rev = revision.ensure_null(this_branch.last_revision())
143
149
    if last_rev != revision.NULL_REVISION:
144
150
        other_branch = this_branch.get_master_branch(possible_transports)
145
 
        with this_branch.lock_read(), other_branch.lock_read():
 
151
        this_branch.lock_read()
 
152
        other_branch.lock_read()
 
153
        try:
146
154
            other_last_rev = other_branch.last_revision()
147
155
            graph = this_branch.repository.get_graph(
148
156
                other_branch.repository)
149
157
            if not graph.is_ancestor(last_rev, other_last_rev):
150
158
                return True
 
159
        finally:
 
160
            other_branch.unlock()
 
161
            this_branch.unlock()
151
162
    return False
152
163
 
153
164