~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: INADA Naoki
  • Date: 2011-05-17 00:45:09 UTC
  • mfrom: (5875 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5891.
  • Revision ID: songofacandy@gmail.com-20110517004509-q58negjbdjh7t6u1
mergeĀ fromĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
        self._control_files.break_lock()
269
269
        self.branch.break_lock()
270
270
 
271
 
    def _get_check_refs(self):
272
 
        """Return the references needed to perform a check of this tree.
273
 
        
274
 
        The default implementation returns no refs, and is only suitable for
275
 
        trees that have no local caching and can commit on ghosts at any time.
276
 
 
277
 
        :seealso: bzrlib.check for details about check_refs.
278
 
        """
279
 
        return []
280
 
 
281
271
    def requires_rich_root(self):
282
272
        return self._format.requires_rich_root
283
273
 
572
562
    def id2abspath(self, file_id):
573
563
        return self.abspath(self.id2path(file_id))
574
564
 
 
565
    def _check_for_tree_references(self, iterator):
 
566
        """See if directories have become tree-references."""
 
567
        blocked_parent_ids = set()
 
568
        for path, ie in iterator:
 
569
            if ie.parent_id in blocked_parent_ids:
 
570
                # This entry was pruned because one of its parents became a
 
571
                # TreeReference. If this is a directory, mark it as blocked.
 
572
                if ie.kind == 'directory':
 
573
                    blocked_parent_ids.add(ie.file_id)
 
574
                continue
 
575
            if ie.kind == 'directory' and self._directory_is_tree_reference(path):
 
576
                # This InventoryDirectory needs to be a TreeReference
 
577
                ie = inventory.TreeReference(ie.file_id, ie.name, ie.parent_id)
 
578
                blocked_parent_ids.add(ie.file_id)
 
579
            yield path, ie
 
580
 
 
581
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
 
582
        """See Tree.iter_entries_by_dir()"""
 
583
        # The only trick here is that if we supports_tree_reference then we
 
584
        # need to detect if a directory becomes a tree-reference.
 
585
        iterator = super(WorkingTree, self).iter_entries_by_dir(
 
586
                specific_file_ids=specific_file_ids,
 
587
                yield_parents=yield_parents)
 
588
        if not self.supports_tree_reference():
 
589
            return iterator
 
590
        else:
 
591
            return self._check_for_tree_references(iterator)
 
592
 
575
593
    def get_file_size(self, file_id):
576
594
        """See Tree.get_file_size"""
577
595
        # XXX: this returns the on-disk size; it should probably return the
845
863
        self.add(path, file_id, 'directory')
846
864
        return file_id
847
865
 
848
 
    def get_symlink_target(self, file_id):
849
 
        abspath = self.id2abspath(file_id)
 
866
    def get_symlink_target(self, file_id, path=None):
 
867
        if path is not None:
 
868
            abspath = self.abspath(path)
 
869
        else:
 
870
            abspath = self.id2abspath(file_id)
850
871
        target = osutils.readlink(abspath)
851
872
        return target
852
873
 
1004
1025
            new_revision_info = self.branch.last_revision_info()
1005
1026
            if new_revision_info != old_revision_info:
1006
1027
                repository = self.branch.repository
 
1028
                if repository._format.fast_deltas:
 
1029
                    parent_ids = self.get_parent_ids()
 
1030
                    if parent_ids:
 
1031
                        basis_id = parent_ids[0]
 
1032
                        basis_tree = repository.revision_tree(basis_id)
1007
1033
                basis_tree.lock_read()
1008
1034
                try:
1009
1035
                    new_basis_tree = self.branch.basis_tree()
1228
1254
        if _mod_revision.is_null(new_revision):
1229
1255
            self.branch.set_last_revision_info(0, new_revision)
1230
1256
            return False
 
1257
        _mod_revision.check_not_reserved_id(new_revision)
1231
1258
        try:
1232
1259
            self.branch.generate_revision_history(new_revision)
1233
1260
        except errors.NoSuchRevision:
1751
1778
        self.set_conflicts(un_resolved)
1752
1779
        return un_resolved, resolved
1753
1780
 
1754
 
    @needs_read_lock
1755
 
    def _check(self, references):
1756
 
        """Check the tree for consistency.
1757
 
 
1758
 
        :param references: A dict with keys matching the items returned by
1759
 
            self._get_check_refs(), and values from looking those keys up in
1760
 
            the repository.
1761
 
        """
1762
 
        tree_basis = self.basis_tree()
1763
 
        tree_basis.lock_read()
1764
 
        try:
1765
 
            repo_basis = references[('trees', self.last_revision())]
1766
 
            if len(list(repo_basis.iter_changes(tree_basis))) > 0:
1767
 
                raise errors.BzrCheckError(
1768
 
                    "Mismatched basis inventory content.")
1769
 
            self._validate()
1770
 
        finally:
1771
 
            tree_basis.unlock()
1772
 
 
1773
1781
    def _validate(self):
1774
1782
        """Validate internal structures.
1775
1783
 
1781
1789
        """
1782
1790
        return
1783
1791
 
1784
 
    @needs_read_lock
1785
1792
    def check_state(self):
1786
1793
        """Check that the working state is/isn't valid."""
1787
 
        check_refs = self._get_check_refs()
1788
 
        refs = {}
1789
 
        for ref in check_refs:
1790
 
            kind, value = ref
1791
 
            if kind == 'trees':
1792
 
                refs[ref] = self.branch.repository.revision_tree(value)
1793
 
        self._check(refs)
 
1794
        raise NotImplementedError(self.check_state)
1794
1795
 
1795
1796
    def reset_state(self, revision_ids=None):
1796
1797
        """Reset the state of the working tree.
2087
2088
 
2088
2089
    __contains__ = has_id
2089
2090
 
2090
 
    # should be deprecated - this is slow and in any case treating them as a
2091
 
    # container is (we now know) bad style -- mbp 20070302
2092
 
    ## @deprecated_method(zero_fifteen)
 
2091
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2093
2092
    def __iter__(self):
2094
2093
        """Iterate through file_ids for this tree.
2095
2094
 
2107
2106
        if self._change_last_revision(new_revision):
2108
2107
            self._cache_basis_inventory(new_revision)
2109
2108
 
 
2109
    def _get_check_refs(self):
 
2110
        """Return the references needed to perform a check of this tree.
 
2111
        
 
2112
        The default implementation returns no refs, and is only suitable for
 
2113
        trees that have no local caching and can commit on ghosts at any time.
 
2114
 
 
2115
        :seealso: bzrlib.check for details about check_refs.
 
2116
        """
 
2117
        return []
 
2118
 
 
2119
    @needs_read_lock
 
2120
    def _check(self, references):
 
2121
        """Check the tree for consistency.
 
2122
 
 
2123
        :param references: A dict with keys matching the items returned by
 
2124
            self._get_check_refs(), and values from looking those keys up in
 
2125
            the repository.
 
2126
        """
 
2127
        tree_basis = self.basis_tree()
 
2128
        tree_basis.lock_read()
 
2129
        try:
 
2130
            repo_basis = references[('trees', self.last_revision())]
 
2131
            if len(list(repo_basis.iter_changes(tree_basis))) > 0:
 
2132
                raise errors.BzrCheckError(
 
2133
                    "Mismatched basis inventory content.")
 
2134
            self._validate()
 
2135
        finally:
 
2136
            tree_basis.unlock()
 
2137
 
 
2138
    @needs_read_lock
 
2139
    def check_state(self):
 
2140
        """Check that the working state is/isn't valid."""
 
2141
        check_refs = self._get_check_refs()
 
2142
        refs = {}
 
2143
        for ref in check_refs:
 
2144
            kind, value = ref
 
2145
            if kind == 'trees':
 
2146
                refs[ref] = self.branch.repository.revision_tree(value)
 
2147
        self._check(refs)
 
2148
 
2110
2149
    @needs_tree_write_lock
2111
2150
    def reset_state(self, revision_ids=None):
2112
2151
        """Reset the state of the working tree.