/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

Merge from bzr.ab.integration

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
1281
1276
    This differs from the base WorkingTree by:
1282
1277
     - having its own file lock
1283
1278
     - having its own last-revision property.
 
1279
 
 
1280
    This is new in bzr 0.8
1284
1281
    """
1285
1282
 
1286
1283
    @needs_read_lock
1460
1457
class WorkingTreeFormat3(WorkingTreeFormat):
1461
1458
    """The second working tree format updated to record a format marker.
1462
1459
 
1463
 
    This format modified the hash cache from the format 1 hash cache.
 
1460
    This format:
 
1461
        - exists within a metadir controlling .bzr
 
1462
        - includes an explicit version marker for the workingtree control
 
1463
          files, separate from the BzrDir format
 
1464
        - modifies the hash cache format
 
1465
        - is new in bzr 0.8
 
1466
        - uses a LockDir to guard access to the repository
1464
1467
    """
1465
1468
 
1466
1469
    def get_format_string(self):
1467
1470
        """See WorkingTreeFormat.get_format_string()."""
1468
1471
        return "Bazaar-NG Working Tree format 3"
1469
1472
 
 
1473
    _lock_file_name = 'lock'
 
1474
    _lock_class = LockDir
 
1475
 
 
1476
    def _open_control_files(self, a_bzrdir):
 
1477
        transport = a_bzrdir.get_workingtree_transport(None)
 
1478
        return LockableFiles(transport, self._lock_file_name, 
 
1479
                             self._lock_class)
 
1480
 
1470
1481
    def initialize(self, a_bzrdir, revision_id=None):
1471
1482
        """See WorkingTreeFormat.initialize().
1472
1483
        
1476
1487
        if not isinstance(a_bzrdir.transport, LocalTransport):
1477
1488
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1478
1489
        transport = a_bzrdir.get_workingtree_transport(self)
1479
 
        control_files = LockableFiles(transport, 'lock', TransportLock)
 
1490
        control_files = self._open_control_files(a_bzrdir)
 
1491
        control_files.create_lock()
1480
1492
        control_files.put_utf8('format', self.get_format_string())
1481
1493
        branch = a_bzrdir.open_branch()
1482
1494
        if revision_id is None:
1487
1499
                         inv,
1488
1500
                         _internal=True,
1489
1501
                         _format=self,
1490
 
                         _bzrdir=a_bzrdir)
 
1502
                         _bzrdir=a_bzrdir,
 
1503
                         _control_files=control_files)
1491
1504
        wt._write_inventory(inv)
1492
1505
        wt.set_root_id(inv.root.file_id)
1493
1506
        wt.set_last_revision(revision_id)
1510
1523
            raise NotImplementedError
1511
1524
        if not isinstance(a_bzrdir.transport, LocalTransport):
1512
1525
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
 
1526
        control_files = self._open_control_files(a_bzrdir)
1513
1527
        return WorkingTree3(a_bzrdir.root_transport.base,
1514
1528
                           _internal=True,
1515
1529
                           _format=self,
1516
 
                           _bzrdir=a_bzrdir)
 
1530
                           _bzrdir=a_bzrdir,
 
1531
                           _control_files=control_files)
1517
1532
 
1518
1533
    def __str__(self):
1519
1534
        return self.get_format_string()