39
40
# construction - this will mean that we can change the constructor
40
41
# with much less chance of breaking client code.
41
42
self._repository = branch
42
self._weave_store = branch.weave_store
43
43
self._inventory = inv
44
44
self._revision_id = revision_id
45
self._rules_searcher = None
46
47
def supports_tree_reference(self):
62
63
"""Return the revision id associated with this tree."""
63
64
return self._revision_id
65
def _get_weave(self, file_id):
66
return self._weave_store.get_weave(file_id,
67
self._repository.get_transaction())
69
def get_file_lines(self, file_id):
70
ie = self._inventory[file_id]
71
weave = self._get_weave(file_id)
72
return weave.get_lines(ie.revision)
74
def get_file_text(self, file_id):
75
return ''.join(self.get_file_lines(file_id))
66
def get_file_text(self, file_id, path=None):
67
return list(self.iter_files_bytes([(file_id, None)]))[0][1]
77
69
def get_file(self, file_id, path=None):
78
70
return StringIO(self.get_file_text(file_id))
80
72
def iter_files_bytes(self, desired_files):
81
"""See Tree.extract_files_bytes.
73
"""See Tree.iter_files_bytes.
83
75
This version is implemented on top of Repository.extract_files_bytes"""
84
76
repo_desired_files = [(f, self.inventory[f].revision, i)
85
77
for f, i in desired_files]
86
return self._repository.iter_files_bytes(repo_desired_files)
79
for result in self._repository.iter_files_bytes(repo_desired_files):
81
except errors.RevisionNotPresent, e:
82
raise errors.NoSuchFile(e.revision_id)
88
84
def annotate_iter(self, file_id,
89
85
default_revision=revision.CURRENT_REVISION):
90
86
"""See Tree.annotate_iter"""
91
w = self._get_weave(file_id)
92
return w.annotate(self.inventory[file_id].revision)
87
text_key = (file_id, self.inventory[file_id].revision)
88
annotations = self._repository.texts.annotate(text_key)
89
return [(key[-1], line) for key, line in annotations]
94
91
def get_file_size(self, file_id):
95
92
"""See Tree.get_file_size"""
203
200
for dir in reversed(dirblock):
204
201
if dir[2] == _directory:
205
202
pending.append(dir)
204
def _get_rules_searcher(self, default_searcher):
205
"""See Tree._get_rules_searcher."""
206
if self._rules_searcher is None:
207
self._rules_searcher = super(RevisionTree,
208
self)._get_rules_searcher(default_searcher)
209
return self._rules_searcher