~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

[merge] bzr.dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1377
1377
        between multiple working trees, i.e. via shared storage, then we 
1378
1378
        would probably want to lock both the local tree, and the branch.
1379
1379
        """
1380
 
        # FIXME: We want to write out the hashcache only when the last lock on
1381
 
        # this working copy is released.  Peeking at the lock count is a bit
1382
 
        # of a nasty hack; probably it's better to have a transaction object,
1383
 
        # which can do some finalization when it's either successfully or
1384
 
        # unsuccessfully completed.  (Denys's original patch did that.)
1385
 
        # RBC 20060206 hooking into transaction will couple lock and transaction
1386
 
        # wrongly. Hooking into unlock on the control files object is fine though.
1387
 
        
1388
 
        # TODO: split this per format so there is no ugly if block
1389
 
        if self._hashcache.needs_write and (
1390
 
            # dedicated lock files
1391
 
            self._control_files._lock_count==1 or 
1392
 
            # shared lock files
1393
 
            (self._control_files is self.branch.control_files and 
1394
 
             self._control_files._lock_count==3)):
1395
 
            self._hashcache.write()
1396
 
        # reverse order of locking.
1397
 
        try:
1398
 
            return self._control_files.unlock()
1399
 
        finally:
1400
 
            self.branch.unlock()
 
1380
        raise NotImplementedError(self.unlock)
1401
1381
 
1402
1382
    @needs_write_lock
1403
1383
    def update(self):
1498
1478
        return conflicts
1499
1479
 
1500
1480
 
 
1481
class WorkingTree2(WorkingTree):
 
1482
    """This is the Format 2 working tree.
 
1483
 
 
1484
    This was the first weave based working tree. 
 
1485
     - uses os locks for locking.
 
1486
     - uses the branch last-revision.
 
1487
    """
 
1488
 
 
1489
    def unlock(self):
 
1490
        # we share control files:
 
1491
        if self._hashcache.needs_write and self._control_files._lock_count==3:
 
1492
            self._hashcache.write()
 
1493
        # reverse order of locking.
 
1494
        try:
 
1495
            return self._control_files.unlock()
 
1496
        finally:
 
1497
            self.branch.unlock()
 
1498
 
 
1499
 
1501
1500
class WorkingTree3(WorkingTree):
1502
1501
    """This is the Format 3 working tree.
1503
1502
 
1557
1556
            raise ConflictFormatError()
1558
1557
        return ConflictList.from_stanzas(RioReader(confile))
1559
1558
 
 
1559
    def unlock(self):
 
1560
        if self._hashcache.needs_write and self._control_files._lock_count==1:
 
1561
            self._hashcache.write()
 
1562
        # reverse order of locking.
 
1563
        try:
 
1564
            return self._control_files.unlock()
 
1565
        finally:
 
1566
            self.branch.unlock()
 
1567
 
1560
1568
 
1561
1569
def get_conflicted_stem(path):
1562
1570
    for suffix in CONFLICT_SUFFIXES:
1696
1704
                branch.unlock()
1697
1705
        revision = branch.last_revision()
1698
1706
        inv = Inventory() 
1699
 
        wt = WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
 
1707
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
1700
1708
                         branch,
1701
1709
                         inv,
1702
1710
                         _internal=True,
1724
1732
            raise NotImplementedError
1725
1733
        if not isinstance(a_bzrdir.transport, LocalTransport):
1726
1734
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1727
 
        return WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
 
1735
        return WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
1728
1736
                           _internal=True,
1729
1737
                           _format=self,
1730
1738
                           _bzrdir=a_bzrdir)