1
# Copyright (C) 2006-2010 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""RevisionTree - a Tree implementation backed by repository data for a revision."""
19
from __future__ import absolute_import
32
class RevisionTree(tree.Tree):
33
"""Tree viewing a previous revision.
35
File text can be retrieved from the text store.
38
def __init__(self, repository, revision_id):
39
self._repository = repository
40
self._revision_id = revision_id
41
self._rules_searcher = None
43
def has_versioned_directories(self):
44
"""See `Tree.has_versioned_directories`."""
45
return self._repository._format.supports_versioned_directories
47
def supports_tree_reference(self):
48
return getattr(self._repository._format, "supports_tree_reference",
51
def get_parent_ids(self):
52
"""See Tree.get_parent_ids.
54
A RevisionTree's parents match the revision graph.
56
if self._revision_id in (None, revision.NULL_REVISION):
59
parent_ids = self._repository.get_revision(
60
self._revision_id).parent_ids
63
def get_revision_id(self):
64
"""Return the revision id associated with this tree."""
65
return self._revision_id
67
def get_file_revision(self, path, file_id=None):
68
"""Return the revision id in which a file was last changed."""
69
raise NotImplementedError(self.get_file_revision)
71
def get_file_text(self, path, file_id=None):
72
for (identifier, content) in self.iter_files_bytes([(path, None)]):
73
ret = "".join(content)
76
def get_file(self, path, file_id=None):
77
return BytesIO(self.get_file_text(path, file_id))
80
return self._repository.is_locked()
83
self._repository.lock_read()
84
return lock.LogicalLockResult(self.unlock)
87
return '<%s instance at %x, rev_id=%r>' % (
88
self.__class__.__name__, id(self), self._revision_id)
91
self._repository.unlock()
93
def _get_rules_searcher(self, default_searcher):
94
"""See Tree._get_rules_searcher."""
95
if self._rules_searcher is None:
96
self._rules_searcher = super(RevisionTree,
97
self)._get_rules_searcher(default_searcher)
98
return self._rules_searcher