/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: Canonical.com Patch Queue Manager
  • Date: 2009-07-02 11:37:38 UTC
  • mfrom: (4496.3.16 pyflakes-nits)
  • Revision ID: pqm@pqm.ubuntu.com-20090702113738-5qda6d3y80z4l3o5
(andrew) Fix some trivial bugs and unused/redundant imports reported
        by pyflakes.

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."
691
687
            from_entry = self._get_entry(path=from_rel)
692
688
            if from_entry == (None, None):
693
689
                raise errors.BzrMoveFailedError(from_rel,to_dir,
694
 
                    errors.NotVersionedError(path=from_rel))
 
690
                    errors.NotVersionedError(path=str(from_rel)))
695
691
 
696
692
            from_id = from_entry[0][2]
697
693
            to_rel = pathjoin(to_dir, from_tail)
1199
1195
                # just forget the whole block.
1200
1196
                entry_index = 0
1201
1197
                while entry_index < len(block[1]):
 
1198
                    # Mark this file id as having been removed
1202
1199
                    entry = block[1][entry_index]
1203
 
                    if entry[1][0][0] in 'ar':
1204
 
                        # don't remove absent or renamed entries
 
1200
                    ids_to_unversion.discard(entry[0][2])
 
1201
                    if (entry[1][0][0] in 'ar' # don't remove absent or renamed
 
1202
                                               # entries
 
1203
                        or not state._make_absent(entry)):
1205
1204
                        entry_index += 1
1206
 
                    else:
1207
 
                        # Mark this file id as having been removed
1208
 
                        ids_to_unversion.discard(entry[0][2])
1209
 
                        if not state._make_absent(entry):
1210
 
                            # The block has not shrunk.
1211
 
                            entry_index += 1
1212
1205
                # go to the next block. (At the moment we dont delete empty
1213
1206
                # dirblocks)
1214
1207
                block_index += 1
1266
1259
        if self._dirty:
1267
1260
            raise AssertionError("attempting to write an inventory when the "
1268
1261
                "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:
 
1262
        self.current_dirstate().set_state_from_inventory(inv)
 
1263
        self._make_dirty(reset_inventory=False)
 
1264
        if self._inventory is not None:
1280
1265
            self._inventory = inv
1281
1266
        self.flush()
1282
1267
 
1307
1292
        return statvalue, sha1
1308
1293
 
1309
1294
 
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
1295
class WorkingTree4(DirStateWorkingTree):
1337
1296
    """This is the Format 4 working tree.
1338
1297
 
1346
1305
    """
1347
1306
 
1348
1307
 
1349
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1308
class WorkingTree5(DirStateWorkingTree):
1350
1309
    """This is the Format 5 working tree.
1351
1310
 
1352
1311
    This differs from WorkingTree4 by:
1356
1315
    """
1357
1316
 
1358
1317
 
1359
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1318
class WorkingTree6(DirStateWorkingTree):
1360
1319
    """This is the Format 6 working tree.
1361
1320
 
1362
1321
    This differs from WorkingTree5 by:
1371
1330
 
1372
1331
 
1373
1332
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1374
 
 
1375
1333
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1376
1334
                   accelerator_tree=None, hardlink=False):
1377
1335
        """See WorkingTreeFormat.initialize().
1447
1405
                if basis_root_id is not None:
1448
1406
                    wt._set_root_id(basis_root_id)
1449
1407
                    wt.flush()
 
1408
                # If content filtering is supported, do not use the accelerator
 
1409
                # tree - the cost of transforming the content both ways and
 
1410
                # checking for changed content can outweight the gains it gives.
 
1411
                # Note: do NOT move this logic up higher - using the basis from
 
1412
                # the accelerator tree is still desirable because that can save
 
1413
                # a minute or more of processing on large trees!
 
1414
                # The original tree may not have the same content filters
 
1415
                # applied so we can't safely build the inventory delta from
 
1416
                # the source tree.
1450
1417
                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.
 
1418
                    accelerator_tree = None
1454
1419
                    delta_from_tree = False
1455
1420
                else:
1456
1421
                    delta_from_tree = True
1573
1538
 
1574
1539
 
1575
1540
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
 
    """
 
1541
    """A revision tree pulling the inventory from a dirstate."""
1581
1542
 
1582
1543
    def __init__(self, dirstate, revision_id, repository):
1583
1544
        self._dirstate = dirstate
1755
1716
            return None
1756
1717
        parent_index = self._get_parent_index()
1757
1718
        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
 
1719
        return self._repository.get_revision(last_changed_revision).timestamp
1763
1720
 
1764
1721
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1765
1722
        entry = self._get_entry(file_id=file_id, path=path)
1832
1789
        entry = self._get_entry(file_id=file_id)[1]
1833
1790
        if entry is None:
1834
1791
            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]]
 
1792
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1837
1793
 
1838
1794
    def stored_kind(self, file_id):
1839
1795
        """See Tree.stored_kind"""
1979
1935
        return result
1980
1936
 
1981
1937
    @classmethod
1982
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
1983
 
                                                  target):
 
1938
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
1984
1939
        from bzrlib.tests.test__dirstate_helpers import \
1985
 
            compiled_dirstate_helpers_feature
1986
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1940
            CompiledDirstateHelpersFeature
 
1941
        if not CompiledDirstateHelpersFeature.available():
 
1942
            from bzrlib.tests import UnavailableFeature
 
1943
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
1987
1944
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
1988
1945
        result = klass.make_source_parent_tree(source, target)
1989
1946
        result[1]._iter_changes = ProcessEntryC
2020
1977
            output. An unversioned file is defined as one with (False, False)
2021
1978
            for the versioned pair.
2022
1979
        """
 
1980
        # NB: show_status depends on being able to pass in non-versioned files
 
1981
        # and report them as unknown
2023
1982
        # TODO: handle extra trees in the dirstate.
2024
1983
        if (extra_trees or specific_files == []):
2025
1984
            # we can't fast-path these cases (yet)