/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-22 10:55:35 UTC
  • mto: This revision was merged to the branch mainline in revision 4573.
  • Revision ID: andrew.bennetts@canonical.com-20090722105535-t2iv2j8zbj2230q2
Add Branch.set_tags_bytes RPC, with HPSS call count acceptance test.  Also fixes serialisation of LockDir, and uses external_url() in LockDir's repr and contention message.

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
 
from bzrlib.lock import LogicalLockResult
 
56
import bzrlib.mutabletree
57
57
from bzrlib.mutabletree import needs_tree_write_lock
58
58
from bzrlib.osutils import (
59
59
    file_kind,
435
435
        return osutils.lexists(pathjoin(
436
436
                    self.basedir, row[0].decode('utf8'), row[1].decode('utf8')))
437
437
 
438
 
    def has_or_had_id(self, file_id):
439
 
        state = self.current_dirstate()
440
 
        row, parents = self._get_entry(file_id=file_id)
441
 
        return row is not None
442
 
 
443
438
    @needs_read_lock
444
439
    def id2path(self, file_id):
445
440
        "Convert a file-id to a path."
568
563
            return _mod_revision.NULL_REVISION
569
564
 
570
565
    def lock_read(self):
571
 
        """See Branch.lock_read, and WorkingTree.unlock.
572
 
 
573
 
        :return: A bzrlib.lock.LogicalLockResult.
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 LogicalLockResult(self.unlock)
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 LogicalLockResult(self.unlock)
615
605
 
616
606
    def lock_tree_write(self):
617
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
 
 
619
 
        :return: A bzrlib.lock.LogicalLockResult.
620
 
        """
 
607
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
621
608
        self.branch.lock_read()
622
 
        return self._lock_self_write()
 
609
        self._lock_self_write()
623
610
 
624
611
    def lock_write(self):
625
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
626
 
 
627
 
        :return: A bzrlib.lock.LogicalLockResult.
628
 
        """
 
612
        """See MutableTree.lock_write, and WorkingTree.unlock."""
629
613
        self.branch.lock_write()
630
 
        return self._lock_self_write()
 
614
        self._lock_self_write()
631
615
 
632
616
    @needs_tree_write_lock
633
617
    def move(self, from_paths, to_dir, after=False):
1278
1262
        if self._dirty:
1279
1263
            raise AssertionError("attempting to write an inventory when the "
1280
1264
                "dirstate is dirty will lose pending changes")
1281
 
        had_inventory = self._inventory is not None
1282
 
        # Setting self._inventory = None forces the dirstate to regenerate the
1283
 
        # working inventory. We do this because self.inventory may be inv, or
1284
 
        # may have been modified, and either case would prevent a clean delta
1285
 
        # being created.
1286
 
        self._inventory = None
1287
 
        # generate a delta,
1288
 
        delta = inv._make_delta(self.inventory)
1289
 
        # and apply it.
1290
 
        self.apply_inventory_delta(delta)
1291
 
        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:
1292
1268
            self._inventory = inv
1293
1269
        self.flush()
1294
1270
 
1319
1295
        return statvalue, sha1
1320
1296
 
1321
1297
 
1322
 
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1323
 
    """Dirstate working tree that supports content filtering.
1324
 
 
1325
 
    The dirstate holds the hash and size of the canonical form of the file, 
1326
 
    and most methods must return that.
1327
 
    """
1328
 
 
1329
 
    def _file_content_summary(self, path, stat_result):
1330
 
        # This is to support the somewhat obsolete path_content_summary method
1331
 
        # with content filtering: see
1332
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
1333
 
        #
1334
 
        # If the dirstate cache is up to date and knows the hash and size,
1335
 
        # return that.
1336
 
        # Otherwise if there are no content filters, return the on-disk size
1337
 
        # and leave the hash blank.
1338
 
        # Otherwise, read and filter the on-disk file and use its size and
1339
 
        # hash.
1340
 
        #
1341
 
        # The dirstate doesn't store the size of the canonical form so we
1342
 
        # can't trust it for content-filtered trees.  We just return None.
1343
 
        dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1344
 
        executable = self._is_executable_from_path_and_stat(path, stat_result)
1345
 
        return ('file', None, executable, dirstate_sha1)
1346
 
 
1347
 
 
1348
1298
class WorkingTree4(DirStateWorkingTree):
1349
1299
    """This is the Format 4 working tree.
1350
1300
 
1358
1308
    """
1359
1309
 
1360
1310
 
1361
 
class WorkingTree5(ContentFilteringDirStateWorkingTree):
 
1311
class WorkingTree5(DirStateWorkingTree):
1362
1312
    """This is the Format 5 working tree.
1363
1313
 
1364
1314
    This differs from WorkingTree4 by:
1368
1318
    """
1369
1319
 
1370
1320
 
1371
 
class WorkingTree6(ContentFilteringDirStateWorkingTree):
 
1321
class WorkingTree6(DirStateWorkingTree):
1372
1322
    """This is the Format 6 working tree.
1373
1323
 
1374
1324
    This differs from WorkingTree5 by:
1383
1333
 
1384
1334
 
1385
1335
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1386
 
 
1387
1336
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1388
1337
                   accelerator_tree=None, hardlink=False):
1389
1338
        """See WorkingTreeFormat.initialize().
1459
1408
                if basis_root_id is not None:
1460
1409
                    wt._set_root_id(basis_root_id)
1461
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.
1462
1420
                if wt.supports_content_filtering():
1463
 
                    # The original tree may not have the same content filters
1464
 
                    # applied so we can't safely build the inventory delta from
1465
 
                    # the source tree.
 
1421
                    accelerator_tree = None
1466
1422
                    delta_from_tree = False
1467
1423
                else:
1468
1424
                    delta_from_tree = True
1585
1541
 
1586
1542
 
1587
1543
class DirStateRevisionTree(Tree):
1588
 
    """A revision tree pulling the inventory from a dirstate.
1589
 
    
1590
 
    Note that this is one of the historical (ie revision) trees cached in the
1591
 
    dirstate for easy access, not the workingtree.
1592
 
    """
 
1544
    """A revision tree pulling the inventory from a dirstate."""
1593
1545
 
1594
1546
    def __init__(self, dirstate, revision_id, repository):
1595
1547
        self._dirstate = dirstate
1767
1719
            return None
1768
1720
        parent_index = self._get_parent_index()
1769
1721
        last_changed_revision = entry[1][parent_index][4]
1770
 
        try:
1771
 
            rev = self._repository.get_revision(last_changed_revision)
1772
 
        except errors.NoSuchRevision:
1773
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1774
 
        return rev.timestamp
 
1722
        return self._repository.get_revision(last_changed_revision).timestamp
1775
1723
 
1776
1724
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1777
1725
        entry = self._get_entry(file_id=file_id, path=path)
1844
1792
        entry = self._get_entry(file_id=file_id)[1]
1845
1793
        if entry is None:
1846
1794
            raise errors.NoSuchId(tree=self, file_id=file_id)
1847
 
        parent_index = self._get_parent_index()
1848
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1795
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1849
1796
 
1850
1797
    def stored_kind(self, file_id):
1851
1798
        """See Tree.stored_kind"""
1871
1818
            return None
1872
1819
        return ie.executable
1873
1820
 
1874
 
    def is_locked(self):
1875
 
        return self._locked
1876
 
 
1877
1821
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1878
1822
        # We use a standard implementation, because DirStateRevisionTree is
1879
1823
        # dealing with one of the parents of the current state
1892
1836
            yield path, 'V', entry.kind, entry.file_id, entry
1893
1837
 
1894
1838
    def lock_read(self):
1895
 
        """Lock the tree for a set of operations.
1896
 
 
1897
 
        :return: A bzrlib.lock.LogicalLockResult.
1898
 
        """
 
1839
        """Lock the tree for a set of operations."""
1899
1840
        if not self._locked:
1900
1841
            self._repository.lock_read()
1901
1842
            if self._dirstate._lock_token is None:
1902
1843
                self._dirstate.lock_read()
1903
1844
                self._dirstate_locked = True
1904
1845
        self._locked += 1
1905
 
        return LogicalLockResult(self.unlock)
1906
1846
 
1907
1847
    def _must_be_locked(self):
1908
1848
        if not self._locked:
1998
1938
        return result
1999
1939
 
2000
1940
    @classmethod
2001
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
2002
 
                                                  target):
 
1941
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
2003
1942
        from bzrlib.tests.test__dirstate_helpers import \
2004
 
            compiled_dirstate_helpers_feature
2005
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1943
            CompiledDirstateHelpersFeature
 
1944
        if not CompiledDirstateHelpersFeature.available():
 
1945
            from bzrlib.tests import UnavailableFeature
 
1946
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
2006
1947
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
2007
1948
        result = klass.make_source_parent_tree(source, target)
2008
1949
        result[1]._iter_changes = ProcessEntryC
2039
1980
            output. An unversioned file is defined as one with (False, False)
2040
1981
            for the versioned pair.
2041
1982
        """
 
1983
        # NB: show_status depends on being able to pass in non-versioned files
 
1984
        # and report them as unknown
2042
1985
        # TODO: handle extra trees in the dirstate.
2043
1986
        if (extra_trees or specific_files == []):
2044
1987
            # we can't fast-path these cases (yet)