~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 16:38:10 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309163810-ujn8hcx08f75nlf1
Refined test to make use of locking hooks and also validate if lock is truly a checkout-lock.

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,
568
568
            return _mod_revision.NULL_REVISION
569
569
 
570
570
    def lock_read(self):
571
 
        """See Branch.lock_read, and WorkingTree.unlock.
572
 
 
573
 
        :return: A bzrlib.lock.LogicalLockResult.
574
 
        """
 
571
        """See Branch.lock_read, and WorkingTree.unlock."""
575
572
        self.branch.lock_read()
576
573
        try:
577
574
            self._control_files.lock_read()
590
587
        except:
591
588
            self.branch.unlock()
592
589
            raise
593
 
        return LogicalLockResult(self.unlock)
594
590
 
595
591
    def _lock_self_write(self):
596
592
        """This should be called after the branch is locked."""
611
607
        except:
612
608
            self.branch.unlock()
613
609
            raise
614
 
        return LogicalLockResult(self.unlock)
615
610
 
616
611
    def lock_tree_write(self):
617
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
 
 
619
 
        :return: A bzrlib.lock.LogicalLockResult.
620
 
        """
 
612
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
621
613
        self.branch.lock_read()
622
 
        return self._lock_self_write()
 
614
        self._lock_self_write()
623
615
 
624
616
    def lock_write(self):
625
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
626
 
 
627
 
        :return: A bzrlib.lock.LogicalLockResult.
628
 
        """
 
617
        """See MutableTree.lock_write, and WorkingTree.unlock."""
629
618
        self.branch.lock_write()
630
 
        return self._lock_self_write()
 
619
        self._lock_self_write()
631
620
 
632
621
    @needs_tree_write_lock
633
622
    def move(self, from_paths, to_dir, after=False):
1247
1236
        # have to change the legacy inventory too.
1248
1237
        if self._inventory is not None:
1249
1238
            for file_id in file_ids:
1250
 
                if self._inventory.has_id(file_id):
1251
 
                    self._inventory.remove_recursive_id(file_id)
 
1239
                self._inventory.remove_recursive_id(file_id)
1252
1240
 
1253
1241
    @needs_tree_write_lock
1254
1242
    def rename_one(self, from_rel, to_rel, after=False):
1330
1318
    def _file_content_summary(self, path, stat_result):
1331
1319
        # This is to support the somewhat obsolete path_content_summary method
1332
1320
        # with content filtering: see
1333
 
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
 
1321
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
1334
1322
        #
1335
1323
        # If the dirstate cache is up to date and knows the hash and size,
1336
1324
        # return that.
1384
1372
 
1385
1373
 
1386
1374
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1387
 
 
1388
1375
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1389
1376
                   accelerator_tree=None, hardlink=False):
1390
1377
        """See WorkingTreeFormat.initialize().
1460
1447
                if basis_root_id is not None:
1461
1448
                    wt._set_root_id(basis_root_id)
1462
1449
                    wt.flush()
 
1450
                # If content filtering is supported, do not use the accelerator
 
1451
                # tree - the cost of transforming the content both ways and
 
1452
                # checking for changed content can outweight the gains it gives.
 
1453
                # Note: do NOT move this logic up higher - using the basis from
 
1454
                # the accelerator tree is still desirable because that can save
 
1455
                # a minute or more of processing on large trees!
 
1456
                # The original tree may not have the same content filters
 
1457
                # applied so we can't safely build the inventory delta from
 
1458
                # the source tree.
1463
1459
                if wt.supports_content_filtering():
1464
 
                    # The original tree may not have the same content filters
1465
 
                    # applied so we can't safely build the inventory delta from
1466
 
                    # the source tree.
 
1460
                    if hardlink:
 
1461
                        # see https://bugs.edge.launchpad.net/bzr/+bug/408193
 
1462
                        trace.warning("hardlinking working copy files is not currently "
 
1463
                            "supported in %r" % (wt,))
 
1464
                    accelerator_tree = None
1467
1465
                    delta_from_tree = False
1468
1466
                else:
1469
1467
                    delta_from_tree = True
1738
1736
                elif kind == 'directory':
1739
1737
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1740
1738
                elif kind == 'symlink':
 
1739
                    inv_entry.executable = False
 
1740
                    inv_entry.text_size = None
1741
1741
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1742
1742
                elif kind == 'tree-reference':
1743
1743
                    inv_entry.reference_revision = fingerprint or None
1766
1766
            return None
1767
1767
        parent_index = self._get_parent_index()
1768
1768
        last_changed_revision = entry[1][parent_index][4]
1769
 
        try:
1770
 
            rev = self._repository.get_revision(last_changed_revision)
1771
 
        except errors.NoSuchRevision:
1772
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1773
 
        return rev.timestamp
 
1769
        return self._repository.get_revision(last_changed_revision).timestamp
1774
1770
 
1775
1771
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1776
1772
        entry = self._get_entry(file_id=file_id, path=path)
1843
1839
        entry = self._get_entry(file_id=file_id)[1]
1844
1840
        if entry is None:
1845
1841
            raise errors.NoSuchId(tree=self, file_id=file_id)
1846
 
        parent_index = self._get_parent_index()
1847
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1842
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1848
1843
 
1849
1844
    def stored_kind(self, file_id):
1850
1845
        """See Tree.stored_kind"""
1870
1865
            return None
1871
1866
        return ie.executable
1872
1867
 
1873
 
    def is_locked(self):
1874
 
        return self._locked
1875
 
 
1876
1868
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1877
1869
        # We use a standard implementation, because DirStateRevisionTree is
1878
1870
        # dealing with one of the parents of the current state
1891
1883
            yield path, 'V', entry.kind, entry.file_id, entry
1892
1884
 
1893
1885
    def lock_read(self):
1894
 
        """Lock the tree for a set of operations.
1895
 
 
1896
 
        :return: A bzrlib.lock.LogicalLockResult.
1897
 
        """
 
1886
        """Lock the tree for a set of operations."""
1898
1887
        if not self._locked:
1899
1888
            self._repository.lock_read()
1900
1889
            if self._dirstate._lock_token is None:
1901
1890
                self._dirstate.lock_read()
1902
1891
                self._dirstate_locked = True
1903
1892
        self._locked += 1
1904
 
        return LogicalLockResult(self.unlock)
1905
1893
 
1906
1894
    def _must_be_locked(self):
1907
1895
        if not self._locked:
1997
1985
        return result
1998
1986
 
1999
1987
    @classmethod
2000
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
2001
 
                                                  target):
 
1988
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
2002
1989
        from bzrlib.tests.test__dirstate_helpers import \
2003
 
            compiled_dirstate_helpers_feature
2004
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1990
            CompiledDirstateHelpersFeature
 
1991
        if not CompiledDirstateHelpersFeature.available():
 
1992
            from bzrlib.tests import UnavailableFeature
 
1993
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
2005
1994
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
2006
1995
        result = klass.make_source_parent_tree(source, target)
2007
1996
        result[1]._iter_changes = ProcessEntryC
2038
2027
            output. An unversioned file is defined as one with (False, False)
2039
2028
            for the versioned pair.
2040
2029
        """
 
2030
        # NB: show_status depends on being able to pass in non-versioned files
 
2031
        # and report them as unknown
2041
2032
        # TODO: handle extra trees in the dirstate.
2042
2033
        if (extra_trees or specific_files == []):
2043
2034
            # we can't fast-path these cases (yet)