~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-11 09:27:55 UTC
  • mfrom: (5017.3.46 test-servers)
  • mto: This revision was merged to the branch mainline in revision 5030.
  • Revision ID: v.ladeuil+lp@free.fr-20100211092755-3vvu4vbwiwjjte3s
Move tests servers from bzrlib.transport to bzrlib.tests.test_server

Show diffs side-by-side

added added

removed removed

Lines of Context:
1267
1267
        if self._dirty:
1268
1268
            raise AssertionError("attempting to write an inventory when the "
1269
1269
                "dirstate is dirty will lose pending changes")
1270
 
        self.current_dirstate().set_state_from_inventory(inv)
1271
 
        self._make_dirty(reset_inventory=False)
1272
 
        if self._inventory is not None:
 
1270
        had_inventory = self._inventory is not None
 
1271
        # Setting self._inventory = None forces the dirstate to regenerate the
 
1272
        # working inventory. We do this because self.inventory may be inv, or
 
1273
        # may have been modified, and either case would prevent a clean delta
 
1274
        # being created.
 
1275
        self._inventory = None
 
1276
        # generate a delta,
 
1277
        delta = inv._make_delta(self.inventory)
 
1278
        # and apply it.
 
1279
        self.apply_inventory_delta(delta)
 
1280
        if had_inventory:
1273
1281
            self._inventory = inv
1274
1282
        self.flush()
1275
1283
 
1300
1308
        return statvalue, sha1
1301
1309
 
1302
1310
 
 
1311
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
 
1312
    """Dirstate working tree that supports content filtering.
 
1313
 
 
1314
    The dirstate holds the hash and size of the canonical form of the file, 
 
1315
    and most methods must return that.
 
1316
    """
 
1317
 
 
1318
    def _file_content_summary(self, path, stat_result):
 
1319
        # This is to support the somewhat obsolete path_content_summary method
 
1320
        # with content filtering: see
 
1321
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1322
        #
 
1323
        # If the dirstate cache is up to date and knows the hash and size,
 
1324
        # return that.
 
1325
        # Otherwise if there are no content filters, return the on-disk size
 
1326
        # and leave the hash blank.
 
1327
        # Otherwise, read and filter the on-disk file and use its size and
 
1328
        # hash.
 
1329
        #
 
1330
        # The dirstate doesn't store the size of the canonical form so we
 
1331
        # can't trust it for content-filtered trees.  We just return None.
 
1332
        dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
 
1333
        executable = self._is_executable_from_path_and_stat(path, stat_result)
 
1334
        return ('file', None, executable, dirstate_sha1)
 
1335
 
 
1336
 
1303
1337
class WorkingTree4(DirStateWorkingTree):
1304
1338
    """This is the Format 4 working tree.
1305
1339
 
1313
1347
    """
1314
1348
 
1315
1349
 
1316
 
class WorkingTree5(DirStateWorkingTree):
 
1350
class WorkingTree5(ContentFilteringDirStateWorkingTree):
1317
1351
    """This is the Format 5 working tree.
1318
1352
 
1319
1353
    This differs from WorkingTree4 by:
1323
1357
    """
1324
1358
 
1325
1359
 
1326
 
class WorkingTree6(DirStateWorkingTree):
 
1360
class WorkingTree6(ContentFilteringDirStateWorkingTree):
1327
1361
    """This is the Format 6 working tree.
1328
1362
 
1329
1363
    This differs from WorkingTree5 by:
1413
1447
                if basis_root_id is not None:
1414
1448
                    wt._set_root_id(basis_root_id)
1415
1449
                    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.
1425
1450
                if wt.supports_content_filtering():
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
 
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.
1431
1454
                    delta_from_tree = False
1432
1455
                else:
1433
1456
                    delta_from_tree = True
1550
1573
 
1551
1574
 
1552
1575
class DirStateRevisionTree(Tree):
1553
 
    """A revision tree pulling the inventory from a dirstate."""
 
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
    """
1554
1581
 
1555
1582
    def __init__(self, dirstate, revision_id, repository):
1556
1583
        self._dirstate = dirstate
1728
1755
            return None
1729
1756
        parent_index = self._get_parent_index()
1730
1757
        last_changed_revision = entry[1][parent_index][4]
1731
 
        return self._repository.get_revision(last_changed_revision).timestamp
 
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
1732
1763
 
1733
1764
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1734
1765
        entry = self._get_entry(file_id=file_id, path=path)
1947
1978
        return result
1948
1979
 
1949
1980
    @classmethod
1950
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
 
1981
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
 
1982
                                                  target):
1951
1983
        from bzrlib.tests.test__dirstate_helpers import \
1952
 
            CompiledDirstateHelpersFeature
1953
 
        if not CompiledDirstateHelpersFeature.available():
1954
 
            from bzrlib.tests import UnavailableFeature
1955
 
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
 
1984
            compiled_dirstate_helpers_feature
 
1985
        test_case.requireFeature(compiled_dirstate_helpers_feature)
1956
1986
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
1957
1987
        result = klass.make_source_parent_tree(source, target)
1958
1988
        result[1]._iter_changes = ProcessEntryC
1989
2019
            output. An unversioned file is defined as one with (False, False)
1990
2020
            for the versioned pair.
1991
2021
        """
1992
 
        # NB: show_status depends on being able to pass in non-versioned files
1993
 
        # and report them as unknown
1994
2022
        # TODO: handle extra trees in the dirstate.
1995
2023
        if (extra_trees or specific_files == []):
1996
2024
            # we can't fast-path these cases (yet)