~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Refactor workingtree.unlock to be cleaner, adding a trivial test for unlock. Introduces an explicit Format2 tree type, making the base WorkingTree cleaner to derive from.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1362
1362
        between multiple working trees, i.e. via shared storage, then we 
1363
1363
        would probably want to lock both the local tree, and the branch.
1364
1364
        """
1365
 
        # FIXME: We want to write out the hashcache only when the last lock on
1366
 
        # this working copy is released.  Peeking at the lock count is a bit
1367
 
        # of a nasty hack; probably it's better to have a transaction object,
1368
 
        # which can do some finalization when it's either successfully or
1369
 
        # unsuccessfully completed.  (Denys's original patch did that.)
1370
 
        # RBC 20060206 hooking into transaction will couple lock and transaction
1371
 
        # wrongly. Hooking into unlock on the control files object is fine though.
1372
 
        
1373
 
        # TODO: split this per format so there is no ugly if block
1374
 
        if self._hashcache.needs_write and (
1375
 
            # dedicated lock files
1376
 
            self._control_files._lock_count==1 or 
1377
 
            # shared lock files
1378
 
            (self._control_files is self.branch.control_files and 
1379
 
             self._control_files._lock_count==3)):
1380
 
            self._hashcache.write()
1381
 
        # reverse order of locking.
1382
 
        try:
1383
 
            return self._control_files.unlock()
1384
 
        finally:
1385
 
            self.branch.unlock()
 
1365
        raise NotImplementedError(self.unlock)
1386
1366
 
1387
1367
    @needs_write_lock
1388
1368
    def update(self):
1483
1463
        return conflicts
1484
1464
 
1485
1465
 
 
1466
class WorkingTree2(WorkingTree):
 
1467
    """This is the Format 2 working tree.
 
1468
 
 
1469
    This was the first weave based working tree. 
 
1470
     - uses os locks for locking.
 
1471
     - uses the branch last-revision.
 
1472
    """
 
1473
 
 
1474
    def unlock(self):
 
1475
        # we share control files:
 
1476
        if self._hashcache.needs_write and self._control_files._lock_count==3:
 
1477
            self._hashcache.write()
 
1478
        # reverse order of locking.
 
1479
        try:
 
1480
            return self._control_files.unlock()
 
1481
        finally:
 
1482
            self.branch.unlock()
 
1483
 
 
1484
 
1486
1485
class WorkingTree3(WorkingTree):
1487
1486
    """This is the Format 3 working tree.
1488
1487
 
1542
1541
            raise ConflictFormatError()
1543
1542
        return ConflictList.from_stanzas(RioReader(confile))
1544
1543
 
 
1544
    def unlock(self):
 
1545
        if self._hashcache.needs_write and self._control_files._lock_count==1:
 
1546
            self._hashcache.write()
 
1547
        # reverse order of locking.
 
1548
        try:
 
1549
            return self._control_files.unlock()
 
1550
        finally:
 
1551
            self.branch.unlock()
 
1552
 
1545
1553
 
1546
1554
def get_conflicted_stem(path):
1547
1555
    for suffix in CONFLICT_SUFFIXES:
1681
1689
                branch.unlock()
1682
1690
        revision = branch.last_revision()
1683
1691
        inv = Inventory() 
1684
 
        wt = WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
 
1692
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
1685
1693
                         branch,
1686
1694
                         inv,
1687
1695
                         _internal=True,
1709
1717
            raise NotImplementedError
1710
1718
        if not isinstance(a_bzrdir.transport, LocalTransport):
1711
1719
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1712
 
        return WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
 
1720
        return WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
1713
1721
                           _internal=True,
1714
1722
                           _format=self,
1715
1723
                           _bzrdir=a_bzrdir)