/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2006-03-09 02:55:03 UTC
  • mto: This revision was merged to the branch mainline in revision 1602.
  • Revision ID: mbp@sourcefrog.net-20060309025503-0cb67e7cf78ba889
Convert WorkingTree format3 to use LockDirs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
WorkingTree.open(dir).
30
30
"""
31
31
 
32
 
 
33
 
# FIXME: I don't know if writing out the cache from the destructor is really a
34
 
# good idea, because destructors are considered poor taste in Python, and it's
35
 
# not predictable when it will be written out.
36
 
 
37
32
# TODO: Give the workingtree sole responsibility for the working inventory;
38
33
# remove the variable and references to it from the branch.  This may require
39
34
# updating the commit code so as to update the inventory within the working
40
35
# copy, and making sure there's only one WorkingTree for any directory on disk.
41
 
# At the momenthey may alias the inventory and have old copies of it in memory.
 
36
# At the moment they may alias the inventory and have old copies of it in
 
37
# memory.  (Now done? -- mbp 20060309)
42
38
 
43
39
from copy import deepcopy
44
40
from cStringIO import StringIO
63
59
                           NotVersionedError)
64
60
from bzrlib.inventory import InventoryEntry, Inventory
65
61
from bzrlib.lockable_files import LockableFiles, TransportLock
 
62
from bzrlib.lockdir import LockDir
66
63
from bzrlib.merge import merge_inner, transform_tree
67
64
from bzrlib.osutils import (
68
65
                            abspath,
247
244
        if isinstance(self._format, WorkingTreeFormat2):
248
245
            # share control object
249
246
            self._control_files = self.branch.control_files
250
 
        elif _control_files is not None:
251
 
            assert False, "not done yet"
252
 
#            self._control_files = _control_files
253
247
        else:
254
248
            # only ready for format 3
255
249
            assert isinstance(self._format, WorkingTreeFormat3)
256
 
            self._control_files = LockableFiles(
257
 
                self.bzrdir.get_workingtree_transport(None),
258
 
                'lock', TransportLock)
259
 
 
 
250
            assert isinstance(_control_files, LockableFiles), \
 
251
                    "_control_files must be a LockableFiles, not %r" \
 
252
                    % _control_files
 
253
            self._control_files = _control_files
260
254
        # update the whole cache up front and write to disk if anything changed;
261
255
        # in the future we might want to do this more selectively
262
256
        # two possible ways offer themselves : in self._unlock, write the cache
1234
1228
    This differs from the base WorkingTree by:
1235
1229
     - having its own file lock
1236
1230
     - having its own last-revision property.
 
1231
 
 
1232
    This is new in bzr 0.8
1237
1233
    """
1238
1234
 
1239
1235
    @needs_read_lock
1413
1409
class WorkingTreeFormat3(WorkingTreeFormat):
1414
1410
    """The second working tree format updated to record a format marker.
1415
1411
 
1416
 
    This format modified the hash cache from the format 1 hash cache.
 
1412
    This format:
 
1413
        - exists within a metadir controlling .bzr
 
1414
        - includes an explicit version marker for the workingtree control
 
1415
          files, separate from the BzrDir format
 
1416
        - modifies the hash cache format
 
1417
        - is new in bzr 0.8
 
1418
        - uses a LockDir to guard access to the repository
1417
1419
    """
1418
1420
 
1419
1421
    def get_format_string(self):
1420
1422
        """See WorkingTreeFormat.get_format_string()."""
1421
1423
        return "Bazaar-NG Working Tree format 3"
1422
1424
 
 
1425
    _lock_file_name = 'lock'
 
1426
    _lock_class = LockDir
 
1427
 
 
1428
    def _open_control_files(self, a_bzrdir):
 
1429
        transport = a_bzrdir.get_workingtree_transport(None)
 
1430
        return LockableFiles(transport, self._lock_file_name, 
 
1431
                             self._lock_class)
 
1432
 
1423
1433
    def initialize(self, a_bzrdir, revision_id=None):
1424
1434
        """See WorkingTreeFormat.initialize().
1425
1435
        
1429
1439
        if not isinstance(a_bzrdir.transport, LocalTransport):
1430
1440
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1431
1441
        transport = a_bzrdir.get_workingtree_transport(self)
1432
 
        control_files = LockableFiles(transport, 'lock', TransportLock)
 
1442
        control_files = self._open_control_files(a_bzrdir)
 
1443
        control_files.create_lock()
1433
1444
        control_files.put_utf8('format', self.get_format_string())
1434
1445
        branch = a_bzrdir.open_branch()
1435
1446
        if revision_id is None:
1440
1451
                         inv,
1441
1452
                         _internal=True,
1442
1453
                         _format=self,
1443
 
                         _bzrdir=a_bzrdir)
 
1454
                         _bzrdir=a_bzrdir,
 
1455
                         _control_files=control_files)
1444
1456
        wt._write_inventory(inv)
1445
1457
        wt.set_root_id(inv.root.file_id)
1446
1458
        wt.set_last_revision(revision_id)
1463
1475
            raise NotImplementedError
1464
1476
        if not isinstance(a_bzrdir.transport, LocalTransport):
1465
1477
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
 
1478
        control_files = self._open_control_files(a_bzrdir)
1466
1479
        return WorkingTree3(a_bzrdir.root_transport.base,
1467
1480
                           _internal=True,
1468
1481
                           _format=self,
1469
 
                           _bzrdir=a_bzrdir)
 
1482
                           _bzrdir=a_bzrdir,
 
1483
                           _control_files=control_files)
1470
1484
 
1471
1485
    def __str__(self):
1472
1486
        return self.get_format_string()