/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006-2010 Canonical Ltd
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
16
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
17
"""RevisionTree - a Tree implementation backed by repository data for a revision."""
18
6379.6.3 by Jelmer Vernooij
Use absolute_import.
19
from __future__ import absolute_import
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from . import (
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
22
    errors,
6754.8.3 by Jelmer Vernooij
Use context manager in decorators.
23
    lock,
2255.2.83 by John Arbash Meinel
[merge] bzr.dev 2294
24
    revision,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
25
    tree,
2249.5.13 by John Arbash Meinel
Finish auditing Repository, and fix generate_ids to always generate utf8 ids.
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from .sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
28
    BytesIO,
29
    )
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
30
31
5793.2.2 by Jelmer Vernooij
Split inventory-specific code out of RevisionTree into InventoryRevisionTree.
32
class RevisionTree(tree.Tree):
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
33
    """Tree viewing a previous revision.
34
35
    File text can be retrieved from the text store.
36
    """
3008.1.13 by Michael Hudson
merge bzr.dev
37
5793.2.2 by Jelmer Vernooij
Split inventory-specific code out of RevisionTree into InventoryRevisionTree.
38
    def __init__(self, repository, revision_id):
39
        self._repository = repository
2858.2.1 by Martin Pool
Remove most calls to safe_file_id and safe_revision_id.
40
        self._revision_id = revision_id
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
41
        self._rules_searcher = None
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
42
6110.6.1 by Jelmer Vernooij
Add Tree.has_versioned_directories.
43
    def has_versioned_directories(self):
44
        """See `Tree.has_versioned_directories`."""
45
        return self._repository._format.supports_versioned_directories
46
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
47
    def supports_tree_reference(self):
4370.3.2 by Ian Clatworthy
apply jam's review feedback
48
        return getattr(self._repository._format, "supports_tree_reference",
49
            False)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
50
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
51
    def get_parent_ids(self):
52
        """See Tree.get_parent_ids.
53
54
        A RevisionTree's parents match the revision graph.
55
        """
1908.11.3 by Robert Collins
Merge bzr.dev
56
        if self._revision_id in (None, revision.NULL_REVISION):
57
            parent_ids = []
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
58
        else:
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
59
            parent_ids = self._repository.get_revision(
60
                self._revision_id).parent_ids
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
61
        return parent_ids
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
62
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
63
    def get_revision_id(self):
64
        """Return the revision id associated with this tree."""
65
        return self._revision_id
66
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
67
    def get_file_revision(self, path, file_id=None):
5793.2.3 by Jelmer Vernooij
Add a RevisionTree.get_file_revision() method.
68
        """Return the revision id in which a file was last changed."""
69
        raise NotImplementedError(self.get_file_revision)
70
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
71
    def get_file_text(self, path, file_id=None):
72
        if file_id is None:
73
            file_id = self.path2id(path)
6280.10.14 by Jelmer Vernooij
cope with slightly different behaviour.
74
        for (identifier, content) in self.iter_files_bytes([(file_id, None)]):
75
            ret = "".join(content)
76
        return ret
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
77
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
78
    def get_file(self, path, file_id=None):
79
        return BytesIO(self.get_file_text(path, file_id))
1852.7.1 by Robert Collins
Move RevisionTree out of tree.py.
80
5793.2.2 by Jelmer Vernooij
Split inventory-specific code out of RevisionTree into InventoryRevisionTree.
81
    def is_locked(self):
82
        return self._repository.is_locked()
83
84
    def lock_read(self):
85
        self._repository.lock_read()
6754.8.3 by Jelmer Vernooij
Use context manager in decorators.
86
        return lock.LogicalLockResult(self.unlock)
5793.2.2 by Jelmer Vernooij
Split inventory-specific code out of RevisionTree into InventoryRevisionTree.
87
88
    def __repr__(self):
89
        return '<%s instance at %x, rev_id=%r>' % (
90
            self.__class__.__name__, id(self), self._revision_id)
91
92
    def unlock(self):
93
        self._repository.unlock()
94
95
    def _get_rules_searcher(self, default_searcher):
96
        """See Tree._get_rules_searcher."""
97
        if self._rules_searcher is None:
98
            self._rules_searcher = super(RevisionTree,
99
                self)._get_rules_searcher(default_searcher)
100
        return self._rules_searcher