~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to switch.py

  • Committer: Aaron Bentley
  • Date: 2006-05-03 18:54:10 UTC
  • mto: This revision was merged to the branch mainline in revision 366.
  • Revision ID: abentley@panoramicfeedback.com-20060503185410-2e0cc2db4fad30a0
Merge progress bar updates from robertc

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib.workingtree import WorkingTree
26
26
 
27
27
class cmd_switch(Command):
28
 
    """Set the branch of a lightweight checkout and update."""
 
28
    """Set the branch of a lightweight checkout and update.  <BZRTOOLS>"""
29
29
 
30
30
    takes_args = ['to_location']
31
31
 
32
32
    def run(self, to_location):
33
33
        to_branch = Branch.open(to_location)
34
 
        tree_location = '.'
35
 
        self._switch(tree_location, to_branch)
36
 
        # need to re-open tree to get the new branch
37
 
        tree = WorkingTree.open_containing(tree_location)[0]
38
 
        self._update(tree)
39
 
 
40
 
    def _switch(self, tree_location, to_branch):
41
 
        tree = WorkingTree.open_containing(tree_location)[0]
42
 
        tree.lock_write()
 
34
        url = '.'
 
35
        wt = WorkingTree.open_containing(url)[0]
 
36
        branch = wt.branch
 
37
        unlockables = []
43
38
        try:
44
 
            self._check_switch_branch_format(tree_location)
45
 
            self.set_branch_location(tree.bzrdir, to_branch.base)
 
39
            wt.lock_write()
 
40
            unlockables.append(wt)
 
41
            branch.lock_write()
 
42
            unlockables.append(branch)
 
43
            self._check_switch_branch_format(url)
 
44
            self.set_branch_location(wt.bzrdir, to_branch.base)
46
45
            note('Switched to branch: %s' % (to_branch.base,))
47
 
        finally:
48
 
            tree.unlock()
49
 
 
50
 
    def _update(self, tree):
51
 
        tree.lock_write()
52
 
        try:
53
 
            if tree.last_revision() == tree.branch.last_revision():
54
 
                assert tree.branch.get_master_branch() is None, (
55
 
                    "switch tried to update a fat checkout")
56
 
                note("Tree is up to date.")
57
 
                return
58
 
            tree.update()
 
46
            wt.update()
59
47
            note('Updated to revision %d' %
60
 
                 (tree.branch.revision_id_to_revno(tree.last_revision()),))
 
48
                 (wt.branch.revision_id_to_revno(wt.last_revision()),))
61
49
        finally:
62
 
            tree.unlock()
 
50
            for unlockable in unlockables:
 
51
                unlockable.unlock()
63
52
 
64
53
    def _check_switch_branch_format(self, url):
65
54
        transport = get_transport(url)
94
83
        branch_format = BranchFormat.find_format(control)
95
84
        transport = control.get_branch_transport(None)
96
85
        branch = branch_format.open(control)
97
 
        location = transport.put_bytes('location', location)
 
86
        location = transport.put('location', location)