~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-09-10 22:50:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2000.
  • Revision ID: robertc@robertcollins.net-20060910225011-c46f2b78a0f5cb7d
Add WorkingTree.lock_tree_write.

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
    return gen_file_id('TREE_ROOT')
160
160
 
161
161
 
 
162
def needs_tree_write_lock(unbound):
 
163
    """Decorate unbound to take out and release a tree_write lock."""
 
164
    def tree_write_locked(self, *args, **kwargs):
 
165
        self.lock_tree_write()
 
166
        try:
 
167
            return unbound(self, *args, **kwargs)
 
168
        finally:
 
169
            self.unlock()
 
170
    tree_write_locked.__doc__ = unbound.__doc__
 
171
    tree_write_locked.__name__ = unbound.__name__
 
172
    return tree_write_locked
 
173
 
 
174
 
162
175
class TreeEntry(object):
163
176
    """An entry that implements the minimum interface used by commands.
164
177
 
1386
1399
            self.branch.unlock()
1387
1400
            raise
1388
1401
 
 
1402
    def lock_tree_write(self):
 
1403
        """Lock the working tree for write, and the branch for read.
 
1404
 
 
1405
        This is useful for operations which only need to mutate the working
 
1406
        tree. Taking out branch write locks is a relatively expensive process
 
1407
        and may fail if the branch is on read only media. So branch write locks
 
1408
        should only be taken out when we are modifying branch data - such as in
 
1409
        operations like commit, pull, uncommit and update.
 
1410
        """
 
1411
        self.branch.lock_read()
 
1412
        try:
 
1413
            return self._control_files.lock_write()
 
1414
        except:
 
1415
            self.branch.unlock()
 
1416
            raise
 
1417
 
1389
1418
    def lock_write(self):
1390
1419
        """See Branch.lock_write, and WorkingTree.unlock."""
1391
1420
        self.branch.lock_write()
1711
1740
     - uses the branch last-revision.
1712
1741
    """
1713
1742
 
 
1743
    def lock_tree_write(self):
 
1744
        """See WorkingTree.lock_tree_write().
 
1745
 
 
1746
        In Format2 WorkingTrees we have a single lock for the branch and tree
 
1747
        so lock_tree_write() degrades to lock_write().
 
1748
        """
 
1749
        self.branch.lock_write()
 
1750
        try:
 
1751
            return self._control_files.lock_write()
 
1752
        except:
 
1753
            self.branch.unlock()
 
1754
            raise
 
1755
 
1714
1756
    def unlock(self):
1715
1757
        # we share control files:
1716
1758
        if self._hashcache.needs_write and self._control_files._lock_count==3: