~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-11 11:47:36 UTC
  • mfrom: (5200.3.8 lock_return)
  • Revision ID: pqm@pqm.ubuntu.com-20100511114736-mc1sq9zyo3vufec7
(lifeless) Provide a consistent interface to Tree, Branch,
 Repository where lock methods return an object with an unlock method to
 unlock the lock. This breaks the API for Branch,
 Repository on their lock_write methods. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
 
78
78
from bzrlib import symbol_versioning
79
79
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
80
from bzrlib.lock import LogicalLockResult
80
81
from bzrlib.lockable_files import LockableFiles
81
82
from bzrlib.lockdir import LockDir
82
83
import bzrlib.mutabletree
1798
1799
            raise errors.ObjectNotLocked(self)
1799
1800
 
1800
1801
    def lock_read(self):
1801
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
1802
        """Lock the tree for reading.
 
1803
 
 
1804
        This also locks the branch, and can be unlocked via self.unlock().
 
1805
 
 
1806
        :return: A bzrlib.lock.LogicalLockResult.
 
1807
        """
1802
1808
        if not self.is_locked():
1803
1809
            self._reset_data()
1804
1810
        self.branch.lock_read()
1805
1811
        try:
1806
 
            return self._control_files.lock_read()
 
1812
            self._control_files.lock_read()
 
1813
            return LogicalLockResult(self.unlock)
1807
1814
        except:
1808
1815
            self.branch.unlock()
1809
1816
            raise
1810
1817
 
1811
1818
    def lock_tree_write(self):
1812
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
1819
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
1820
 
 
1821
        :return: A bzrlib.lock.LogicalLockResult.
 
1822
        """
1813
1823
        if not self.is_locked():
1814
1824
            self._reset_data()
1815
1825
        self.branch.lock_read()
1816
1826
        try:
1817
 
            return self._control_files.lock_write()
 
1827
            self._control_files.lock_write()
 
1828
            return LogicalLockResult(self.unlock)
1818
1829
        except:
1819
1830
            self.branch.unlock()
1820
1831
            raise
1821
1832
 
1822
1833
    def lock_write(self):
1823
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
1834
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1835
 
 
1836
        :return: A bzrlib.lock.LogicalLockResult.
 
1837
        """
1824
1838
        if not self.is_locked():
1825
1839
            self._reset_data()
1826
1840
        self.branch.lock_write()
1827
1841
        try:
1828
 
            return self._control_files.lock_write()
 
1842
            self._control_files.lock_write()
 
1843
            return LogicalLockResult(self.unlock)
1829
1844
        except:
1830
1845
            self.branch.unlock()
1831
1846
            raise
2637
2652
 
2638
2653
        In Format2 WorkingTrees we have a single lock for the branch and tree
2639
2654
        so lock_tree_write() degrades to lock_write().
 
2655
 
 
2656
        :return: An object with an unlock method which will release the lock
 
2657
            obtained.
2640
2658
        """
2641
2659
        self.branch.lock_write()
2642
2660
        try:
2643
 
            return self._control_files.lock_write()
 
2661
            self._control_files.lock_write()
 
2662
            return self
2644
2663
        except:
2645
2664
            self.branch.unlock()
2646
2665
            raise