/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 breezy/switch.py

Use new context stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    if store_uncommitted:
57
57
        with lock.write_locked(control_dir.open_workingtree()) as tree:
58
58
            tree.store_uncommitted()
59
 
    to_branch.lock_read()
60
 
    try:
 
59
    with to_branch.lock_read():
61
60
        _set_branch_location(control_dir, to_branch, force)
62
 
    finally:
63
 
        to_branch.unlock()
64
61
    tree = control_dir.open_workingtree()
65
62
    _update(tree, source_repository, quiet, revision_id, store_uncommitted)
66
63
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
128
125
        else:
129
126
            # If this is a standalone tree and the new branch
130
127
            # is derived from this one, create a lightweight checkout.
131
 
            b.lock_read()
132
 
            try:
 
128
            with b.lock_read():
133
129
                graph = b.repository.get_graph(to_branch.repository)
134
130
                if (b.controldir._format.colocated_branches and
135
131
                     (force or graph.is_ancestor(b.last_revision(),
139
135
                else:
140
136
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
141
137
                        'only a checkout.'))
142
 
            finally:
143
 
                b.unlock()
144
138
 
145
139
 
146
140
def _any_local_commits(this_branch, possible_transports):
148
142
    last_rev = revision.ensure_null(this_branch.last_revision())
149
143
    if last_rev != revision.NULL_REVISION:
150
144
        other_branch = this_branch.get_master_branch(possible_transports)
151
 
        this_branch.lock_read()
152
 
        other_branch.lock_read()
153
 
        try:
 
145
        with this_branch.lock_read(), other_branch.lock_read():
154
146
            other_last_rev = other_branch.last_revision()
155
147
            graph = this_branch.repository.get_graph(
156
148
                other_branch.repository)
157
149
            if not graph.is_ancestor(last_rev, other_last_rev):
158
150
                return True
159
 
        finally:
160
 
            other_branch.unlock()
161
 
            this_branch.unlock()
162
151
    return False
163
152
 
164
153