~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
from bzrlib.lock import LogicalLockResult
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."""
 
571
        """See Branch.lock_read, and WorkingTree.unlock.
 
572
 
 
573
        :return: A bzrlib.lock.LogicalLockResult.
 
574
        """
572
575
        self.branch.lock_read()
573
576
        try:
574
577
            self._control_files.lock_read()
587
590
        except:
588
591
            self.branch.unlock()
589
592
            raise
 
593
        return LogicalLockResult(self.unlock)
590
594
 
591
595
    def _lock_self_write(self):
592
596
        """This should be called after the branch is locked."""
607
611
        except:
608
612
            self.branch.unlock()
609
613
            raise
 
614
        return LogicalLockResult(self.unlock)
610
615
 
611
616
    def lock_tree_write(self):
612
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
617
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
618
 
 
619
        :return: A bzrlib.lock.LogicalLockResult.
 
620
        """
613
621
        self.branch.lock_read()
614
 
        self._lock_self_write()
 
622
        return self._lock_self_write()
615
623
 
616
624
    def lock_write(self):
617
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
625
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
626
 
 
627
        :return: A bzrlib.lock.LogicalLockResult.
 
628
        """
618
629
        self.branch.lock_write()
619
 
        self._lock_self_write()
 
630
        return self._lock_self_write()
620
631
 
621
632
    @needs_tree_write_lock
622
633
    def move(self, from_paths, to_dir, after=False):
1236
1247
        # have to change the legacy inventory too.
1237
1248
        if self._inventory is not None:
1238
1249
            for file_id in file_ids:
1239
 
                self._inventory.remove_recursive_id(file_id)
 
1250
                if self._inventory.has_id(file_id):
 
1251
                    self._inventory.remove_recursive_id(file_id)
1240
1252
 
1241
1253
    @needs_tree_write_lock
1242
1254
    def rename_one(self, from_rel, to_rel, after=False):
1318
1330
    def _file_content_summary(self, path, stat_result):
1319
1331
        # This is to support the somewhat obsolete path_content_summary method
1320
1332
        # with content filtering: see
1321
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1333
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1322
1334
        #
1323
1335
        # If the dirstate cache is up to date and knows the hash and size,
1324
1336
        # return that.
1372
1384
 
1373
1385
 
1374
1386
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
 
1387
 
1375
1388
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1376
1389
                   accelerator_tree=None, hardlink=False):
1377
1390
        """See WorkingTreeFormat.initialize().
1725
1738
                elif kind == 'directory':
1726
1739
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1727
1740
                elif kind == 'symlink':
1728
 
                    inv_entry.executable = False
1729
 
                    inv_entry.text_size = None
1730
1741
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1731
1742
                elif kind == 'tree-reference':
1732
1743
                    inv_entry.reference_revision = fingerprint or None
1832
1843
        entry = self._get_entry(file_id=file_id)[1]
1833
1844
        if entry is None:
1834
1845
            raise errors.NoSuchId(tree=self, file_id=file_id)
1835
 
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
 
1846
        parent_index = self._get_parent_index()
 
1847
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
1836
1848
 
1837
1849
    def stored_kind(self, file_id):
1838
1850
        """See Tree.stored_kind"""
1858
1870
            return None
1859
1871
        return ie.executable
1860
1872
 
 
1873
    def is_locked(self):
 
1874
        return self._locked
 
1875
 
1861
1876
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1862
1877
        # We use a standard implementation, because DirStateRevisionTree is
1863
1878
        # dealing with one of the parents of the current state
1876
1891
            yield path, 'V', entry.kind, entry.file_id, entry
1877
1892
 
1878
1893
    def lock_read(self):
1879
 
        """Lock the tree for a set of operations."""
 
1894
        """Lock the tree for a set of operations.
 
1895
 
 
1896
        :return: A bzrlib.lock.LogicalLockResult.
 
1897
        """
1880
1898
        if not self._locked:
1881
1899
            self._repository.lock_read()
1882
1900
            if self._dirstate._lock_token is None:
1883
1901
                self._dirstate.lock_read()
1884
1902
                self._dirstate_locked = True
1885
1903
        self._locked += 1
 
1904
        return LogicalLockResult(self.unlock)
1886
1905
 
1887
1906
    def _must_be_locked(self):
1888
1907
        if not self._locked: