/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_4.py

  • Committer: Robert Collins
  • Date: 2009-08-26 01:18:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4656.
  • Revision ID: robertc@robertcollins.net-20090826011813-46x8kcuzwz97opoi
Deserialise IncompatibleRepositories errors in the client, generating
nicer feedback when the smart server encounters such a situation.

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
import bzrlib.mutabletree
56
57
from bzrlib.mutabletree import needs_tree_write_lock
57
58
from bzrlib.osutils import (
58
59
    file_kind,
1266
1267
        if self._dirty:
1267
1268
            raise AssertionError("attempting to write an inventory when the "
1268
1269
                "dirstate is dirty will lose pending changes")
1269
 
        had_inventory = self._inventory is not None
1270
 
        # Setting self._inventory = None forces the dirstate to regenerate the
1271
 
        # working inventory. We do this because self.inventory may be inv, or
1272
 
        # may have been modified, and either case would prevent a clean delta
1273
 
        # being created.
1274
 
        self._inventory = None
1275
 
        # generate a delta,
1276
 
        delta = inv._make_delta(self.inventory)
1277
 
        # and apply it.
1278
 
        self.apply_inventory_delta(delta)
1279
 
        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:
1280
1273
            self._inventory = inv
1281
1274
        self.flush()
1282
1275
 
1307
1300
        return statvalue, sha1
1308
1301
 
1309
1302
 
1310
 
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1311
 
    """Dirstate working tree that supports content filtering.
1312
 
 
1313
 
    The dirstate holds the hash and size of the canonical form of the file, 
1314
 
    and most methods must return that.
1315
 
    """
1316
 
 
1317
 
    def _file_content_summary(self, path, stat_result):
1318
 
        # This is to support the somewhat obsolete path_content_summary method
1319
 
        # with content filtering: see
1320
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
1321
 
        #
1322
 
        # If the dirstate cache is up to date and knows the hash and size,
1323
 
        # return that.
1324
 
        # Otherwise if there are no content filters, return the on-disk size
1325
 
        # and leave the hash blank.
1326
 
        # Otherwise, read and filter the on-disk file and use its size and
1327
 
        # hash.
1328
 
        #
1329
 
        # The dirstate doesn't store the size of the canonical form so we
1330
 
        # can't trust it for content-filtered trees.  We just return None.
1331
 
        dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1332
 
        executable = self._is_executable_from_path_and_stat(path, stat_result)
1333
 
        return ('file', None, executable, dirstate_sha1)
1334
 
 
1335
 
 
1336
1303
class WorkingTree4(DirStateWorkingTree):
1337
1304
    """This is the Format 4 working tree.
1338
1305
 
1346
1313
    """
1347
1314
 
1348
1315
 
1349
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1316
class WorkingTree5(DirStateWorkingTree):
1350
1317
    """This is the Format 5 working tree.
1351
1318
 
1352
1319
    This differs from WorkingTree4 by:
1356
1323
    """
1357
1324
 
1358
1325
 
1359
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1326
class WorkingTree6(DirStateWorkingTree):
1360
1327
    """This is the Format 6 working tree.
1361
1328
 
1362
1329
    This differs from WorkingTree5 by:
1371
1338
 
1372
1339
 
1373
1340
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1374
 
 
1375
1341
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1376
1342
                   accelerator_tree=None, hardlink=False):
1377
1343
        """See WorkingTreeFormat.initialize().
1447
1413
                if basis_root_id is not None:
1448
1414
                    wt._set_root_id(basis_root_id)
1449
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.
1450
1425
                if wt.supports_content_filtering():
1451
 
                    # The original tree may not have the same content filters
1452
 
                    # applied so we can't safely build the inventory delta from
1453
 
                    # 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
1454
1431
                    delta_from_tree = False
1455
1432
                else:
1456
1433
                    delta_from_tree = True
1573
1550
 
1574
1551
 
1575
1552
class DirStateRevisionTree(Tree):
1576
 
    """A revision tree pulling the inventory from a dirstate.
1577
 
    
1578
 
    Note that this is one of the historical (ie revision) trees cached in the
1579
 
    dirstate for easy access, not the workingtree.
1580
 
    """
 
1553
    """A revision tree pulling the inventory from a dirstate."""
1581
1554
 
1582
1555
    def __init__(self, dirstate, revision_id, repository):
1583
1556
        self._dirstate = dirstate
1755
1728
            return None
1756
1729
        parent_index = self._get_parent_index()
1757
1730
        last_changed_revision = entry[1][parent_index][4]
1758
 
        try:
1759
 
            rev = self._repository.get_revision(last_changed_revision)
1760
 
        except errors.NoSuchRevision:
1761
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1762
 
        return rev.timestamp
 
1731
        return self._repository.get_revision(last_changed_revision).timestamp
1763
1732
 
1764
1733
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1765
1734
        entry = self._get_entry(file_id=file_id, path=path)
1832
1801
        entry = self._get_entry(file_id=file_id)[1]
1833
1802
        if entry is None:
1834
1803
            raise errors.NoSuchId(tree=self, file_id=file_id)
1835
 
        parent_index = self._get_parent_index()
1836
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1804
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1837
1805
 
1838
1806
    def stored_kind(self, file_id):
1839
1807
        """See Tree.stored_kind"""
1979
1947
        return result
1980
1948
 
1981
1949
    @classmethod
1982
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
1983
 
                                                  target):
 
1950
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
1984
1951
        from bzrlib.tests.test__dirstate_helpers import \
1985
 
            compiled_dirstate_helpers_feature
1986
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1952
            CompiledDirstateHelpersFeature
 
1953
        if not CompiledDirstateHelpersFeature.available():
 
1954
            from bzrlib.tests import UnavailableFeature
 
1955
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
1987
1956
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
1988
1957
        result = klass.make_source_parent_tree(source, target)
1989
1958
        result[1]._iter_changes = ProcessEntryC
2020
1989
            output. An unversioned file is defined as one with (False, False)
2021
1990
            for the versioned pair.
2022
1991
        """
 
1992
        # NB: show_status depends on being able to pass in non-versioned files
 
1993
        # and report them as unknown
2023
1994
        # TODO: handle extra trees in the dirstate.
2024
1995
        if (extra_trees or specific_files == []):
2025
1996
            # we can't fast-path these cases (yet)