/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: Andrew Bennetts
  • Date: 2009-07-15 06:39:07 UTC
  • mto: (4476.3.44 inventory-delta)
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090715063907-rw44os6ox1253nm8
Trivial improvement to test coverage in test_xml.

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."
567
563
            return _mod_revision.NULL_REVISION
568
564
 
569
565
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock.
571
 
 
572
 
        :return: An object with an unlock method which will release the lock
573
 
            obtained.
574
 
        """
 
566
        """See Branch.lock_read, and WorkingTree.unlock."""
575
567
        self.branch.lock_read()
576
568
        try:
577
569
            self._control_files.lock_read()
590
582
        except:
591
583
            self.branch.unlock()
592
584
            raise
593
 
        return self
594
585
 
595
586
    def _lock_self_write(self):
596
587
        """This should be called after the branch is locked."""
611
602
        except:
612
603
            self.branch.unlock()
613
604
            raise
614
 
        return self
615
605
 
616
606
    def lock_tree_write(self):
617
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
 
 
619
 
        :return: An object with an unlock method which will release the lock
620
 
            obtained.
621
 
        """
 
607
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
622
608
        self.branch.lock_read()
623
 
        return self._lock_self_write()
 
609
        self._lock_self_write()
624
610
 
625
611
    def lock_write(self):
626
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
627
 
 
628
 
        :return: An object with an unlock method which will release the lock
629
 
            obtained.
630
 
        """
 
612
        """See MutableTree.lock_write, and WorkingTree.unlock."""
631
613
        self.branch.lock_write()
632
 
        return self._lock_self_write()
 
614
        self._lock_self_write()
633
615
 
634
616
    @needs_tree_write_lock
635
617
    def move(self, from_paths, to_dir, after=False):
1213
1195
                # just forget the whole block.
1214
1196
                entry_index = 0
1215
1197
                while entry_index < len(block[1]):
 
1198
                    # Mark this file id as having been removed
1216
1199
                    entry = block[1][entry_index]
1217
 
                    if entry[1][0][0] in 'ar':
1218
 
                        # 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)):
1219
1204
                        entry_index += 1
1220
 
                    else:
1221
 
                        # Mark this file id as having been removed
1222
 
                        ids_to_unversion.discard(entry[0][2])
1223
 
                        if not state._make_absent(entry):
1224
 
                            # The block has not shrunk.
1225
 
                            entry_index += 1
1226
1205
                # go to the next block. (At the moment we dont delete empty
1227
1206
                # dirblocks)
1228
1207
                block_index += 1
1280
1259
        if self._dirty:
1281
1260
            raise AssertionError("attempting to write an inventory when the "
1282
1261
                "dirstate is dirty will lose pending changes")
1283
 
        had_inventory = self._inventory is not None
1284
 
        # Setting self._inventory = None forces the dirstate to regenerate the
1285
 
        # working inventory. We do this because self.inventory may be inv, or
1286
 
        # may have been modified, and either case would prevent a clean delta
1287
 
        # being created.
1288
 
        self._inventory = None
1289
 
        # generate a delta,
1290
 
        delta = inv._make_delta(self.inventory)
1291
 
        # and apply it.
1292
 
        self.apply_inventory_delta(delta)
1293
 
        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:
1294
1265
            self._inventory = inv
1295
1266
        self.flush()
1296
1267
 
1321
1292
        return statvalue, sha1
1322
1293
 
1323
1294
 
1324
 
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1325
 
    """Dirstate working tree that supports content filtering.
1326
 
 
1327
 
    The dirstate holds the hash and size of the canonical form of the file, 
1328
 
    and most methods must return that.
1329
 
    """
1330
 
 
1331
 
    def _file_content_summary(self, path, stat_result):
1332
 
        # This is to support the somewhat obsolete path_content_summary method
1333
 
        # with content filtering: see
1334
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
1335
 
        #
1336
 
        # If the dirstate cache is up to date and knows the hash and size,
1337
 
        # return that.
1338
 
        # Otherwise if there are no content filters, return the on-disk size
1339
 
        # and leave the hash blank.
1340
 
        # Otherwise, read and filter the on-disk file and use its size and
1341
 
        # hash.
1342
 
        #
1343
 
        # The dirstate doesn't store the size of the canonical form so we
1344
 
        # can't trust it for content-filtered trees.  We just return None.
1345
 
        dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1346
 
        executable = self._is_executable_from_path_and_stat(path, stat_result)
1347
 
        return ('file', None, executable, dirstate_sha1)
1348
 
 
1349
 
 
1350
1295
class WorkingTree4(DirStateWorkingTree):
1351
1296
    """This is the Format 4 working tree.
1352
1297
 
1360
1305
    """
1361
1306
 
1362
1307
 
1363
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1308
class WorkingTree5(DirStateWorkingTree):
1364
1309
    """This is the Format 5 working tree.
1365
1310
 
1366
1311
    This differs from WorkingTree4 by:
1370
1315
    """
1371
1316
 
1372
1317
 
1373
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1318
class WorkingTree6(DirStateWorkingTree):
1374
1319
    """This is the Format 6 working tree.
1375
1320
 
1376
1321
    This differs from WorkingTree5 by:
1385
1330
 
1386
1331
 
1387
1332
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1388
 
 
1389
1333
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1390
1334
                   accelerator_tree=None, hardlink=False):
1391
1335
        """See WorkingTreeFormat.initialize().
1461
1405
                if basis_root_id is not None:
1462
1406
                    wt._set_root_id(basis_root_id)
1463
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.
1464
1417
                if wt.supports_content_filtering():
1465
 
                    # The original tree may not have the same content filters
1466
 
                    # applied so we can't safely build the inventory delta from
1467
 
                    # the source tree.
 
1418
                    accelerator_tree = None
1468
1419
                    delta_from_tree = False
1469
1420
                else:
1470
1421
                    delta_from_tree = True
1587
1538
 
1588
1539
 
1589
1540
class DirStateRevisionTree(Tree):
1590
 
    """A revision tree pulling the inventory from a dirstate.
1591
 
    
1592
 
    Note that this is one of the historical (ie revision) trees cached in the
1593
 
    dirstate for easy access, not the workingtree.
1594
 
    """
 
1541
    """A revision tree pulling the inventory from a dirstate."""
1595
1542
 
1596
1543
    def __init__(self, dirstate, revision_id, repository):
1597
1544
        self._dirstate = dirstate
1769
1716
            return None
1770
1717
        parent_index = self._get_parent_index()
1771
1718
        last_changed_revision = entry[1][parent_index][4]
1772
 
        try:
1773
 
            rev = self._repository.get_revision(last_changed_revision)
1774
 
        except errors.NoSuchRevision:
1775
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1776
 
        return rev.timestamp
 
1719
        return self._repository.get_revision(last_changed_revision).timestamp
1777
1720
 
1778
1721
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1779
1722
        entry = self._get_entry(file_id=file_id, path=path)
1846
1789
        entry = self._get_entry(file_id=file_id)[1]
1847
1790
        if entry is None:
1848
1791
            raise errors.NoSuchId(tree=self, file_id=file_id)
1849
 
        parent_index = self._get_parent_index()
1850
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1792
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1851
1793
 
1852
1794
    def stored_kind(self, file_id):
1853
1795
        """See Tree.stored_kind"""
1873
1815
            return None
1874
1816
        return ie.executable
1875
1817
 
1876
 
    def is_locked(self):
1877
 
        return self._locked
1878
 
 
1879
1818
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1880
1819
        # We use a standard implementation, because DirStateRevisionTree is
1881
1820
        # dealing with one of the parents of the current state
1894
1833
            yield path, 'V', entry.kind, entry.file_id, entry
1895
1834
 
1896
1835
    def lock_read(self):
1897
 
        """Lock the tree for a set of operations.
1898
 
 
1899
 
        :return: An object with an unlock method which will release the lock
1900
 
            obtained.
1901
 
        """
 
1836
        """Lock the tree for a set of operations."""
1902
1837
        if not self._locked:
1903
1838
            self._repository.lock_read()
1904
1839
            if self._dirstate._lock_token is None:
1905
1840
                self._dirstate.lock_read()
1906
1841
                self._dirstate_locked = True
1907
1842
        self._locked += 1
1908
 
        return self
1909
1843
 
1910
1844
    def _must_be_locked(self):
1911
1845
        if not self._locked:
2001
1935
        return result
2002
1936
 
2003
1937
    @classmethod
2004
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
2005
 
                                                  target):
 
1938
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
2006
1939
        from bzrlib.tests.test__dirstate_helpers import \
2007
 
            compiled_dirstate_helpers_feature
2008
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1940
            CompiledDirstateHelpersFeature
 
1941
        if not CompiledDirstateHelpersFeature.available():
 
1942
            from bzrlib.tests import UnavailableFeature
 
1943
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
2009
1944
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
2010
1945
        result = klass.make_source_parent_tree(source, target)
2011
1946
        result[1]._iter_changes = ProcessEntryC
2042
1977
            output. An unversioned file is defined as one with (False, False)
2043
1978
            for the versioned pair.
2044
1979
        """
 
1980
        # NB: show_status depends on being able to pass in non-versioned files
 
1981
        # and report them as unknown
2045
1982
        # TODO: handle extra trees in the dirstate.
2046
1983
        if (extra_trees or specific_files == []):
2047
1984
            # we can't fast-path these cases (yet)