~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.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:
567
567
            return _mod_revision.NULL_REVISION
568
568
 
569
569
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
570
        """See Branch.lock_read, and WorkingTree.unlock.
 
571
 
 
572
        :return: An object with an unlock method which will release the lock
 
573
            obtained.
 
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 self
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 self
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: An object with an unlock method which will release the lock
 
620
            obtained.
 
621
        """
612
622
        self.branch.lock_read()
613
 
        self._lock_self_write()
 
623
        return self._lock_self_write()
614
624
 
615
625
    def lock_write(self):
616
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
626
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
627
 
 
628
        :return: An object with an unlock method which will release the lock
 
629
            obtained.
 
630
        """
617
631
        self.branch.lock_write()
618
 
        self._lock_self_write()
 
632
        return self._lock_self_write()
619
633
 
620
634
    @needs_tree_write_lock
621
635
    def move(self, from_paths, to_dir, after=False):
1859
1873
            return None
1860
1874
        return ie.executable
1861
1875
 
 
1876
    def is_locked(self):
 
1877
        return self._locked
 
1878
 
1862
1879
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1863
1880
        # We use a standard implementation, because DirStateRevisionTree is
1864
1881
        # dealing with one of the parents of the current state
1877
1894
            yield path, 'V', entry.kind, entry.file_id, entry
1878
1895
 
1879
1896
    def lock_read(self):
1880
 
        """Lock the tree for a set of operations."""
 
1897
        """Lock the tree for a set of operations.
 
1898
 
 
1899
        :return: An object with an unlock method which will release the lock
 
1900
            obtained.
 
1901
        """
1881
1902
        if not self._locked:
1882
1903
            self._repository.lock_read()
1883
1904
            if self._dirstate._lock_token is None:
1884
1905
                self._dirstate.lock_read()
1885
1906
                self._dirstate_locked = True
1886
1907
        self._locked += 1
 
1908
        return self
1887
1909
 
1888
1910
    def _must_be_locked(self):
1889
1911
        if not self._locked: