~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.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:
53
53
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
54
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
55
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
 
56
from bzrlib.lock import LogicalLockResult
56
57
from bzrlib.mutabletree import needs_tree_write_lock
57
58
from bzrlib.osutils import (
58
59
    file_kind,
567
568
            return _mod_revision.NULL_REVISION
568
569
 
569
570
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
571
        """See Branch.lock_read, and WorkingTree.unlock.
 
572
 
 
573
        :return: A bzrlib.lock.LogicalLockResult.
 
574
        """
571
575
        self.branch.lock_read()
572
576
        try:
573
577
            self._control_files.lock_read()
586
590
        except:
587
591
            self.branch.unlock()
588
592
            raise
 
593
        return LogicalLockResult(self.unlock)
589
594
 
590
595
    def _lock_self_write(self):
591
596
        """This should be called after the branch is locked."""
606
611
        except:
607
612
            self.branch.unlock()
608
613
            raise
 
614
        return LogicalLockResult(self.unlock)
609
615
 
610
616
    def lock_tree_write(self):
611
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
617
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
618
 
 
619
        :return: A bzrlib.lock.LogicalLockResult.
 
620
        """
612
621
        self.branch.lock_read()
613
 
        self._lock_self_write()
 
622
        return self._lock_self_write()
614
623
 
615
624
    def lock_write(self):
616
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
625
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
626
 
 
627
        :return: A bzrlib.lock.LogicalLockResult.
 
628
        """
617
629
        self.branch.lock_write()
618
 
        self._lock_self_write()
 
630
        return self._lock_self_write()
619
631
 
620
632
    @needs_tree_write_lock
621
633
    def move(self, from_paths, to_dir, after=False):
1859
1871
            return None
1860
1872
        return ie.executable
1861
1873
 
 
1874
    def is_locked(self):
 
1875
        return self._locked
 
1876
 
1862
1877
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1863
1878
        # We use a standard implementation, because DirStateRevisionTree is
1864
1879
        # dealing with one of the parents of the current state
1877
1892
            yield path, 'V', entry.kind, entry.file_id, entry
1878
1893
 
1879
1894
    def lock_read(self):
1880
 
        """Lock the tree for a set of operations."""
 
1895
        """Lock the tree for a set of operations.
 
1896
 
 
1897
        :return: A bzrlib.lock.LogicalLockResult.
 
1898
        """
1881
1899
        if not self._locked:
1882
1900
            self._repository.lock_read()
1883
1901
            if self._dirstate._lock_token is None:
1884
1902
                self._dirstate.lock_read()
1885
1903
                self._dirstate_locked = True
1886
1904
        self._locked += 1
 
1905
        return LogicalLockResult(self.unlock)
1887
1906
 
1888
1907
    def _must_be_locked(self):
1889
1908
        if not self._locked: