/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: Aaron Bentley
  • Date: 2009-07-19 04:47:49 UTC
  • mto: This revision was merged to the branch mainline in revision 4549.
  • Revision ID: aaron@aaronbentley.com-20090719044749-mw2ddxyf7uflp18j
Fix tabs.

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,
434
435
        return osutils.lexists(pathjoin(
435
436
                    self.basedir, row[0].decode('utf8'), row[1].decode('utf8')))
436
437
 
437
 
    def has_or_had_id(self, file_id):
438
 
        state = self.current_dirstate()
439
 
        row, parents = self._get_entry(file_id=file_id)
440
 
        return row is not None
441
 
 
442
438
    @needs_read_lock
443
439
    def id2path(self, file_id):
444
440
        "Convert a file-id to a path."
1266
1262
        if self._dirty:
1267
1263
            raise AssertionError("attempting to write an inventory when the "
1268
1264
                "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:
 
1265
        self.current_dirstate().set_state_from_inventory(inv)
 
1266
        self._make_dirty(reset_inventory=False)
 
1267
        if self._inventory is not None:
1280
1268
            self._inventory = inv
1281
1269
        self.flush()
1282
1270
 
1307
1295
        return statvalue, sha1
1308
1296
 
1309
1297
 
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
1298
class WorkingTree4(DirStateWorkingTree):
1337
1299
    """This is the Format 4 working tree.
1338
1300
 
1346
1308
    """
1347
1309
 
1348
1310
 
1349
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1311
class WorkingTree5(DirStateWorkingTree):
1350
1312
    """This is the Format 5 working tree.
1351
1313
 
1352
1314
    This differs from WorkingTree4 by:
1356
1318
    """
1357
1319
 
1358
1320
 
1359
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1321
class WorkingTree6(DirStateWorkingTree):
1360
1322
    """This is the Format 6 working tree.
1361
1323
 
1362
1324
    This differs from WorkingTree5 by:
1371
1333
 
1372
1334
 
1373
1335
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1374
 
 
1375
1336
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1376
1337
                   accelerator_tree=None, hardlink=False):
1377
1338
        """See WorkingTreeFormat.initialize().
1447
1408
                if basis_root_id is not None:
1448
1409
                    wt._set_root_id(basis_root_id)
1449
1410
                    wt.flush()
 
1411
                # If content filtering is supported, do not use the accelerator
 
1412
                # tree - the cost of transforming the content both ways and
 
1413
                # checking for changed content can outweight the gains it gives.
 
1414
                # Note: do NOT move this logic up higher - using the basis from
 
1415
                # the accelerator tree is still desirable because that can save
 
1416
                # a minute or more of processing on large trees!
 
1417
                # The original tree may not have the same content filters
 
1418
                # applied so we can't safely build the inventory delta from
 
1419
                # the source tree.
1450
1420
                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.
 
1421
                    accelerator_tree = None
1454
1422
                    delta_from_tree = False
1455
1423
                else:
1456
1424
                    delta_from_tree = True
1573
1541
 
1574
1542
 
1575
1543
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
 
    """
 
1544
    """A revision tree pulling the inventory from a dirstate."""
1581
1545
 
1582
1546
    def __init__(self, dirstate, revision_id, repository):
1583
1547
        self._dirstate = dirstate
1755
1719
            return None
1756
1720
        parent_index = self._get_parent_index()
1757
1721
        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
 
1722
        return self._repository.get_revision(last_changed_revision).timestamp
1763
1723
 
1764
1724
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1765
1725
        entry = self._get_entry(file_id=file_id, path=path)
1832
1792
        entry = self._get_entry(file_id=file_id)[1]
1833
1793
        if entry is None:
1834
1794
            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]]
 
1795
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1837
1796
 
1838
1797
    def stored_kind(self, file_id):
1839
1798
        """See Tree.stored_kind"""
1979
1938
        return result
1980
1939
 
1981
1940
    @classmethod
1982
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
1983
 
                                                  target):
 
1941
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
1984
1942
        from bzrlib.tests.test__dirstate_helpers import \
1985
 
            compiled_dirstate_helpers_feature
1986
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1943
            CompiledDirstateHelpersFeature
 
1944
        if not CompiledDirstateHelpersFeature.available():
 
1945
            from bzrlib.tests import UnavailableFeature
 
1946
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
1987
1947
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
1988
1948
        result = klass.make_source_parent_tree(source, target)
1989
1949
        result[1]._iter_changes = ProcessEntryC
2020
1980
            output. An unversioned file is defined as one with (False, False)
2021
1981
            for the versioned pair.
2022
1982
        """
 
1983
        # NB: show_status depends on being able to pass in non-versioned files
 
1984
        # and report them as unknown
2023
1985
        # TODO: handle extra trees in the dirstate.
2024
1986
        if (extra_trees or specific_files == []):
2025
1987
            # we can't fast-path these cases (yet)