/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: Canonical.com Patch Queue Manager
  • Date: 2006-03-09 08:50:48 UTC
  • mfrom: (1553.5.83 bzr.mbp.locks)
  • Revision ID: pqm@pqm.ubuntu.com-20060309085048-37f21fd146dabe93
[merge] LockDir integration into new formats

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
31
31
 
32
32
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
33
33
 
34
 
# FIXME: I don't know if writing out the cache from the destructor is really a
35
 
# good idea, because destructors are considered poor taste in Python, and it's
36
 
# not predictable when it will be written out.
37
 
 
38
34
# TODO: Give the workingtree sole responsibility for the working inventory;
39
35
# remove the variable and references to it from the branch.  This may require
40
36
# updating the commit code so as to update the inventory within the working
41
37
# copy, and making sure there's only one WorkingTree for any directory on disk.
42
 
# At the momenthey may alias the inventory and have old copies of it in memory.
 
38
# At the moment they may alias the inventory and have old copies of it in
 
39
# memory.  (Now done? -- mbp 20060309)
43
40
 
44
41
from copy import deepcopy
45
42
from cStringIO import StringIO
65
62
                           MergeModifiedFormatError)
66
63
from bzrlib.inventory import InventoryEntry, Inventory
67
64
from bzrlib.lockable_files import LockableFiles, TransportLock
 
65
from bzrlib.lockdir import LockDir
68
66
from bzrlib.merge import merge_inner, transform_tree
69
67
from bzrlib.osutils import (
70
68
                            abspath,
250
248
        if isinstance(self._format, WorkingTreeFormat2):
251
249
            # share control object
252
250
            self._control_files = self.branch.control_files
253
 
        elif _control_files is not None:
254
 
            assert False, "not done yet"
255
 
#            self._control_files = _control_files
256
251
        else:
257
252
            # only ready for format 3
258
253
            assert isinstance(self._format, WorkingTreeFormat3)
259
 
            self._control_files = LockableFiles(
260
 
                self.bzrdir.get_workingtree_transport(None),
261
 
                'lock', TransportLock)
262
 
 
 
254
            assert isinstance(_control_files, LockableFiles), \
 
255
                    "_control_files must be a LockableFiles, not %r" \
 
256
                    % _control_files
 
257
            self._control_files = _control_files
263
258
        # update the whole cache up front and write to disk if anything changed;
264
259
        # in the future we might want to do this more selectively
265
260
        # two possible ways offer themselves : in self._unlock, write the cache
1276
1271
    This differs from the base WorkingTree by:
1277
1272
     - having its own file lock
1278
1273
     - having its own last-revision property.
 
1274
 
 
1275
    This is new in bzr 0.8
1279
1276
    """
1280
1277
 
1281
1278
    @needs_read_lock
1455
1452
class WorkingTreeFormat3(WorkingTreeFormat):
1456
1453
    """The second working tree format updated to record a format marker.
1457
1454
 
1458
 
    This format modified the hash cache from the format 1 hash cache.
 
1455
    This format:
 
1456
        - exists within a metadir controlling .bzr
 
1457
        - includes an explicit version marker for the workingtree control
 
1458
          files, separate from the BzrDir format
 
1459
        - modifies the hash cache format
 
1460
        - is new in bzr 0.8
 
1461
        - uses a LockDir to guard access to the repository
1459
1462
    """
1460
1463
 
1461
1464
    def get_format_string(self):
1462
1465
        """See WorkingTreeFormat.get_format_string()."""
1463
1466
        return "Bazaar-NG Working Tree format 3"
1464
1467
 
 
1468
    _lock_file_name = 'lock'
 
1469
    _lock_class = LockDir
 
1470
 
 
1471
    def _open_control_files(self, a_bzrdir):
 
1472
        transport = a_bzrdir.get_workingtree_transport(None)
 
1473
        return LockableFiles(transport, self._lock_file_name, 
 
1474
                             self._lock_class)
 
1475
 
1465
1476
    def initialize(self, a_bzrdir, revision_id=None):
1466
1477
        """See WorkingTreeFormat.initialize().
1467
1478
        
1471
1482
        if not isinstance(a_bzrdir.transport, LocalTransport):
1472
1483
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1473
1484
        transport = a_bzrdir.get_workingtree_transport(self)
1474
 
        control_files = LockableFiles(transport, 'lock', TransportLock)
 
1485
        control_files = self._open_control_files(a_bzrdir)
 
1486
        control_files.create_lock()
1475
1487
        control_files.put_utf8('format', self.get_format_string())
1476
1488
        branch = a_bzrdir.open_branch()
1477
1489
        if revision_id is None:
1482
1494
                         inv,
1483
1495
                         _internal=True,
1484
1496
                         _format=self,
1485
 
                         _bzrdir=a_bzrdir)
 
1497
                         _bzrdir=a_bzrdir,
 
1498
                         _control_files=control_files)
1486
1499
        wt._write_inventory(inv)
1487
1500
        wt.set_root_id(inv.root.file_id)
1488
1501
        wt.set_last_revision(revision_id)
1505
1518
            raise NotImplementedError
1506
1519
        if not isinstance(a_bzrdir.transport, LocalTransport):
1507
1520
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
 
1521
        control_files = self._open_control_files(a_bzrdir)
1508
1522
        return WorkingTree3(a_bzrdir.root_transport.base,
1509
1523
                           _internal=True,
1510
1524
                           _format=self,
1511
 
                           _bzrdir=a_bzrdir)
 
1525
                           _bzrdir=a_bzrdir,
 
1526
                           _control_files=control_files)
1512
1527
 
1513
1528
    def __str__(self):
1514
1529
        return self.get_format_string()