~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to switch.py

  • Committer: Aaron Bentley
  • Date: 2006-04-20 23:22:19 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060420232219-04cb6657e7e3aa73
Switch fix from ddaa

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
    def run(self, to_location):
33
33
        to_branch = Branch.open(to_location)
34
 
        url = '.'
35
 
        wt = WorkingTree.open_containing(url)[0]
36
 
        branch = wt.branch
37
 
        unlockables = []
 
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()
38
43
        try:
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)
 
44
            self._check_switch_branch_format(tree_location)
 
45
            self.set_branch_location(tree.bzrdir, to_branch.base)
45
46
            note('Switched to branch: %s' % (to_branch.base,))
46
 
            wt.update()
 
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()
47
59
            note('Updated to revision %d' %
48
 
                 (wt.branch.revision_id_to_revno(wt.last_revision()),))
 
60
                 (tree.branch.revision_id_to_revno(tree.last_revision()),))
49
61
        finally:
50
 
            for unlockable in unlockables:
51
 
                unlockable.unlock()
 
62
            tree.unlock()
52
63
 
53
64
    def _check_switch_branch_format(self, url):
54
65
        transport = get_transport(url)