~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Aaron Bentley
  • Date: 2012-07-18 19:55:04 UTC
  • mto: This revision was merged to the branch mainline in revision 6540.
  • Revision ID: aaron@aaronbentley.com-20120718195504-hrl4w190lynohkhd
Cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# Original author: David Allouche
20
20
 
21
 
from bzrlib import errors, merge, revision
 
21
from bzrlib import (
 
22
    errors,
 
23
    lock,
 
24
    merge,
 
25
    revision
 
26
    )
22
27
from bzrlib.branch import Branch
23
28
from bzrlib.i18n import gettext
24
29
from bzrlib.trace import note
40
45
    :param to_branch: branch that the checkout is to reference
41
46
    :param force: skip the check for local commits in a heavy checkout
42
47
    :param revision_id: revision ID to switch to.
 
48
    :param store_uncommitted: If True, store uncommitted changes in the
 
49
        branch.
43
50
    """
44
51
    _check_pending_merges(control_dir, force)
45
52
    try:
47
54
    except errors.NotBranchError:
48
55
        source_repository = to_branch.repository
49
56
    if store_uncommitted:
50
 
        control_dir.open_workingtree().store_uncommitted()
 
57
        with lock.write_locked(control_dir.open_workingtree()) as tree:
 
58
            tree.store_uncommitted()
51
59
    to_branch.lock_read()
52
60
    try:
53
61
        _set_branch_location(control_dir, to_branch, force)
54
62
    finally:
55
63
        to_branch.unlock()
56
 
    tree = control_dir.open_workingtree()
57
 
    _update(tree, source_repository, quiet, revision_id, store_uncommitted)
 
64
    with lock.write_locked(control_dir.open_workingtree()) as tree:
 
65
        _update(tree, source_repository, quiet, revision_id, store_uncommitted)
58
66
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
59
67
 
60
68
def _check_pending_merges(control, force=False):
160
168
 
161
169
    :param tree: the working tree
162
170
    :param source_repository: repository holding the revisions
 
171
    :param restore_uncommitted: restore any uncommitted changes in the branch.
163
172
    """
164
173
    tree.lock_tree_write()
165
174
    try: