~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Merge prerequisite branch and tweak test to be more compact and faster.

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
462
463
        return (file_obj, stat_value)
463
464
 
464
465
    def get_file_text(self, file_id, path=None, filtered=True):
465
 
        return self.get_file(file_id, path=path, filtered=filtered).read()
 
466
        my_file = self.get_file(file_id, path=path, filtered=filtered)
 
467
        try:
 
468
            return my_file.read()
 
469
        finally:
 
470
            my_file.close()
466
471
 
467
472
    def get_file_byname(self, filename, filtered=True):
468
473
        path = self.abspath(filename)
522
527
 
523
528
        # Now we have the parents of this content
524
529
        annotator = self.branch.repository.texts.get_annotator()
525
 
        text = self.get_file(file_id).read()
 
530
        text = self.get_file_text(file_id)
526
531
        this_key =(file_id, default_revision)
527
532
        annotator.add_special_text(this_key, file_parent_keys, text)
528
533
        annotations = [(key[-1], line)
1798
1803
            raise errors.ObjectNotLocked(self)
1799
1804
 
1800
1805
    def lock_read(self):
1801
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
1806
        """Lock the tree for reading.
 
1807
 
 
1808
        This also locks the branch, and can be unlocked via self.unlock().
 
1809
 
 
1810
        :return: A bzrlib.lock.LogicalLockResult.
 
1811
        """
1802
1812
        if not self.is_locked():
1803
1813
            self._reset_data()
1804
1814
        self.branch.lock_read()
1805
1815
        try:
1806
 
            return self._control_files.lock_read()
 
1816
            self._control_files.lock_read()
 
1817
            return LogicalLockResult(self.unlock)
1807
1818
        except:
1808
1819
            self.branch.unlock()
1809
1820
            raise
1810
1821
 
1811
1822
    def lock_tree_write(self):
1812
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
1823
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
1824
 
 
1825
        :return: A bzrlib.lock.LogicalLockResult.
 
1826
        """
1813
1827
        if not self.is_locked():
1814
1828
            self._reset_data()
1815
1829
        self.branch.lock_read()
1816
1830
        try:
1817
 
            return self._control_files.lock_write()
 
1831
            self._control_files.lock_write()
 
1832
            return LogicalLockResult(self.unlock)
1818
1833
        except:
1819
1834
            self.branch.unlock()
1820
1835
            raise
1821
1836
 
1822
1837
    def lock_write(self):
1823
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
1838
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1839
 
 
1840
        :return: A bzrlib.lock.LogicalLockResult.
 
1841
        """
1824
1842
        if not self.is_locked():
1825
1843
            self._reset_data()
1826
1844
        self.branch.lock_write()
1827
1845
        try:
1828
 
            return self._control_files.lock_write()
 
1846
            self._control_files.lock_write()
 
1847
            return LogicalLockResult(self.unlock)
1829
1848
        except:
1830
1849
            self.branch.unlock()
1831
1850
            raise
2637
2656
 
2638
2657
        In Format2 WorkingTrees we have a single lock for the branch and tree
2639
2658
        so lock_tree_write() degrades to lock_write().
 
2659
 
 
2660
        :return: An object with an unlock method which will release the lock
 
2661
            obtained.
2640
2662
        """
2641
2663
        self.branch.lock_write()
2642
2664
        try:
2643
 
            return self._control_files.lock_write()
 
2665
            self._control_files.lock_write()
 
2666
            return self
2644
2667
        except:
2645
2668
            self.branch.unlock()
2646
2669
            raise