~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1798
1798
            raise errors.ObjectNotLocked(self)
1799
1799
 
1800
1800
    def lock_read(self):
1801
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
1801
        """Lock the tree for reading.
 
1802
 
 
1803
        This also locks the branch, and can be unlocked via self.unlock().
 
1804
 
 
1805
        :return: An object with an unlock method which will release the lock
 
1806
            obtained.
 
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 self
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: An object with an unlock method which will release the lock
 
1822
            obtained.
 
1823
        """
1813
1824
        if not self.is_locked():
1814
1825
            self._reset_data()
1815
1826
        self.branch.lock_read()
1816
1827
        try:
1817
 
            return self._control_files.lock_write()
 
1828
            self._control_files.lock_write()
 
1829
            return self
1818
1830
        except:
1819
1831
            self.branch.unlock()
1820
1832
            raise
1821
1833
 
1822
1834
    def lock_write(self):
1823
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
1835
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1836
 
 
1837
        :return: An object with an unlock method which will release the lock
 
1838
            obtained.
 
1839
        """
1824
1840
        if not self.is_locked():
1825
1841
            self._reset_data()
1826
1842
        self.branch.lock_write()
1827
1843
        try:
1828
 
            return self._control_files.lock_write()
 
1844
            self._control_files.lock_write()
 
1845
            return self
1829
1846
        except:
1830
1847
            self.branch.unlock()
1831
1848
            raise
2636
2653
 
2637
2654
        In Format2 WorkingTrees we have a single lock for the branch and tree
2638
2655
        so lock_tree_write() degrades to lock_write().
 
2656
 
 
2657
        :return: An object with an unlock method which will release the lock
 
2658
            obtained.
2639
2659
        """
2640
2660
        self.branch.lock_write()
2641
2661
        try:
2642
 
            return self._control_files.lock_write()
 
2662
            self._control_files.lock_write()
 
2663
            return self
2643
2664
        except:
2644
2665
            self.branch.unlock()
2645
2666
            raise