~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-14 05:49:27 UTC
  • mfrom: (4476.3.86 inventory-delta)
  • Revision ID: pqm@pqm.ubuntu.com-20090814054927-k0k18dn46ax4b91f
(andrew) Add inventory-delta streaming for cross-format fetch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
53
53
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
54
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
55
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
56
 
from bzrlib.lock import LogicalLockResult
 
56
import bzrlib.mutabletree
57
57
from bzrlib.mutabletree import needs_tree_write_lock
58
58
from bzrlib.osutils import (
59
59
    file_kind,
568
568
            return _mod_revision.NULL_REVISION
569
569
 
570
570
    def lock_read(self):
571
 
        """See Branch.lock_read, and WorkingTree.unlock.
572
 
 
573
 
        :return: A bzrlib.lock.LogicalLockResult.
574
 
        """
 
571
        """See Branch.lock_read, and WorkingTree.unlock."""
575
572
        self.branch.lock_read()
576
573
        try:
577
574
            self._control_files.lock_read()
590
587
        except:
591
588
            self.branch.unlock()
592
589
            raise
593
 
        return LogicalLockResult(self.unlock)
594
590
 
595
591
    def _lock_self_write(self):
596
592
        """This should be called after the branch is locked."""
611
607
        except:
612
608
            self.branch.unlock()
613
609
            raise
614
 
        return LogicalLockResult(self.unlock)
615
610
 
616
611
    def lock_tree_write(self):
617
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
 
 
619
 
        :return: A bzrlib.lock.LogicalLockResult.
620
 
        """
 
612
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
621
613
        self.branch.lock_read()
622
 
        return self._lock_self_write()
 
614
        self._lock_self_write()
623
615
 
624
616
    def lock_write(self):
625
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
626
 
 
627
 
        :return: A bzrlib.lock.LogicalLockResult.
628
 
        """
 
617
        """See MutableTree.lock_write, and WorkingTree.unlock."""
629
618
        self.branch.lock_write()
630
 
        return self._lock_self_write()
 
619
        self._lock_self_write()
631
620
 
632
621
    @needs_tree_write_lock
633
622
    def move(self, from_paths, to_dir, after=False):
1247
1236
        # have to change the legacy inventory too.
1248
1237
        if self._inventory is not None:
1249
1238
            for file_id in file_ids:
1250
 
                if self._inventory.has_id(file_id):
1251
 
                    self._inventory.remove_recursive_id(file_id)
 
1239
                self._inventory.remove_recursive_id(file_id)
1252
1240
 
1253
1241
    @needs_tree_write_lock
1254
1242
    def rename_one(self, from_rel, to_rel, after=False):
1279
1267
        if self._dirty:
1280
1268
            raise AssertionError("attempting to write an inventory when the "
1281
1269
                "dirstate is dirty will lose pending changes")
1282
 
        had_inventory = self._inventory is not None
1283
 
        # Setting self._inventory = None forces the dirstate to regenerate the
1284
 
        # working inventory. We do this because self.inventory may be inv, or
1285
 
        # may have been modified, and either case would prevent a clean delta
1286
 
        # being created.
1287
 
        self._inventory = None
1288
 
        # generate a delta,
1289
 
        delta = inv._make_delta(self.inventory)
1290
 
        # and apply it.
1291
 
        self.apply_inventory_delta(delta)
1292
 
        if had_inventory:
 
1270
        self.current_dirstate().set_state_from_inventory(inv)
 
1271
        self._make_dirty(reset_inventory=False)
 
1272
        if self._inventory is not None:
1293
1273
            self._inventory = inv
1294
1274
        self.flush()
1295
1275
 
1320
1300
        return statvalue, sha1
1321
1301
 
1322
1302
 
1323
 
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1324
 
    """Dirstate working tree that supports content filtering.
1325
 
 
1326
 
    The dirstate holds the hash and size of the canonical form of the file, 
1327
 
    and most methods must return that.
1328
 
    """
1329
 
 
1330
 
    def _file_content_summary(self, path, stat_result):
1331
 
        # This is to support the somewhat obsolete path_content_summary method
1332
 
        # with content filtering: see
1333
 
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1334
 
        #
1335
 
        # If the dirstate cache is up to date and knows the hash and size,
1336
 
        # return that.
1337
 
        # Otherwise if there are no content filters, return the on-disk size
1338
 
        # and leave the hash blank.
1339
 
        # Otherwise, read and filter the on-disk file and use its size and
1340
 
        # hash.
1341
 
        #
1342
 
        # The dirstate doesn't store the size of the canonical form so we
1343
 
        # can't trust it for content-filtered trees.  We just return None.
1344
 
        dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1345
 
        executable = self._is_executable_from_path_and_stat(path, stat_result)
1346
 
        return ('file', None, executable, dirstate_sha1)
1347
 
 
1348
 
 
1349
1303
class WorkingTree4(DirStateWorkingTree):
1350
1304
    """This is the Format 4 working tree.
1351
1305
 
1359
1313
    """
1360
1314
 
1361
1315
 
1362
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1316
class WorkingTree5(DirStateWorkingTree):
1363
1317
    """This is the Format 5 working tree.
1364
1318
 
1365
1319
    This differs from WorkingTree4 by:
1369
1323
    """
1370
1324
 
1371
1325
 
1372
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1326
class WorkingTree6(DirStateWorkingTree):
1373
1327
    """This is the Format 6 working tree.
1374
1328
 
1375
1329
    This differs from WorkingTree5 by:
1384
1338
 
1385
1339
 
1386
1340
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1387
 
 
1388
1341
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1389
1342
                   accelerator_tree=None, hardlink=False):
1390
1343
        """See WorkingTreeFormat.initialize().
1460
1413
                if basis_root_id is not None:
1461
1414
                    wt._set_root_id(basis_root_id)
1462
1415
                    wt.flush()
 
1416
                # If content filtering is supported, do not use the accelerator
 
1417
                # tree - the cost of transforming the content both ways and
 
1418
                # checking for changed content can outweight the gains it gives.
 
1419
                # Note: do NOT move this logic up higher - using the basis from
 
1420
                # the accelerator tree is still desirable because that can save
 
1421
                # a minute or more of processing on large trees!
 
1422
                # The original tree may not have the same content filters
 
1423
                # applied so we can't safely build the inventory delta from
 
1424
                # the source tree.
1463
1425
                if wt.supports_content_filtering():
1464
 
                    # The original tree may not have the same content filters
1465
 
                    # applied so we can't safely build the inventory delta from
1466
 
                    # the source tree.
 
1426
                    if hardlink:
 
1427
                        # see https://bugs.edge.launchpad.net/bzr/+bug/408193
 
1428
                        trace.warning("hardlinking working copy files is not currently "
 
1429
                            "supported in %r" % (wt,))
 
1430
                    accelerator_tree = None
1467
1431
                    delta_from_tree = False
1468
1432
                else:
1469
1433
                    delta_from_tree = True
1586
1550
 
1587
1551
 
1588
1552
class DirStateRevisionTree(Tree):
1589
 
    """A revision tree pulling the inventory from a dirstate.
1590
 
    
1591
 
    Note that this is one of the historical (ie revision) trees cached in the
1592
 
    dirstate for easy access, not the workingtree.
1593
 
    """
 
1553
    """A revision tree pulling the inventory from a dirstate."""
1594
1554
 
1595
1555
    def __init__(self, dirstate, revision_id, repository):
1596
1556
        self._dirstate = dirstate
1738
1698
                elif kind == 'directory':
1739
1699
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1740
1700
                elif kind == 'symlink':
 
1701
                    inv_entry.executable = False
 
1702
                    inv_entry.text_size = None
1741
1703
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1742
1704
                elif kind == 'tree-reference':
1743
1705
                    inv_entry.reference_revision = fingerprint or None
1766
1728
            return None
1767
1729
        parent_index = self._get_parent_index()
1768
1730
        last_changed_revision = entry[1][parent_index][4]
1769
 
        try:
1770
 
            rev = self._repository.get_revision(last_changed_revision)
1771
 
        except errors.NoSuchRevision:
1772
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1773
 
        return rev.timestamp
 
1731
        return self._repository.get_revision(last_changed_revision).timestamp
1774
1732
 
1775
1733
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1776
1734
        entry = self._get_entry(file_id=file_id, path=path)
1843
1801
        entry = self._get_entry(file_id=file_id)[1]
1844
1802
        if entry is None:
1845
1803
            raise errors.NoSuchId(tree=self, file_id=file_id)
1846
 
        parent_index = self._get_parent_index()
1847
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1804
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1848
1805
 
1849
1806
    def stored_kind(self, file_id):
1850
1807
        """See Tree.stored_kind"""
1870
1827
            return None
1871
1828
        return ie.executable
1872
1829
 
1873
 
    def is_locked(self):
1874
 
        return self._locked
1875
 
 
1876
1830
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1877
1831
        # We use a standard implementation, because DirStateRevisionTree is
1878
1832
        # dealing with one of the parents of the current state
1891
1845
            yield path, 'V', entry.kind, entry.file_id, entry
1892
1846
 
1893
1847
    def lock_read(self):
1894
 
        """Lock the tree for a set of operations.
1895
 
 
1896
 
        :return: A bzrlib.lock.LogicalLockResult.
1897
 
        """
 
1848
        """Lock the tree for a set of operations."""
1898
1849
        if not self._locked:
1899
1850
            self._repository.lock_read()
1900
1851
            if self._dirstate._lock_token is None:
1901
1852
                self._dirstate.lock_read()
1902
1853
                self._dirstate_locked = True
1903
1854
        self._locked += 1
1904
 
        return LogicalLockResult(self.unlock)
1905
1855
 
1906
1856
    def _must_be_locked(self):
1907
1857
        if not self._locked:
1997
1947
        return result
1998
1948
 
1999
1949
    @classmethod
2000
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
2001
 
                                                  target):
 
1950
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
2002
1951
        from bzrlib.tests.test__dirstate_helpers import \
2003
 
            compiled_dirstate_helpers_feature
2004
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1952
            CompiledDirstateHelpersFeature
 
1953
        if not CompiledDirstateHelpersFeature.available():
 
1954
            from bzrlib.tests import UnavailableFeature
 
1955
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
2005
1956
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
2006
1957
        result = klass.make_source_parent_tree(source, target)
2007
1958
        result[1]._iter_changes = ProcessEntryC
2038
1989
            output. An unversioned file is defined as one with (False, False)
2039
1990
            for the versioned pair.
2040
1991
        """
 
1992
        # NB: show_status depends on being able to pass in non-versioned files
 
1993
        # and report them as unknown
2041
1994
        # TODO: handle extra trees in the dirstate.
2042
1995
        if (extra_trees or specific_files == []):
2043
1996
            # we can't fast-path these cases (yet)