146
146
# are not versioned.
147
147
pred = self.inventory.has_filename
148
148
return set((p for p in paths if not pred(p)))
151
class RevisionTree(Tree):
152
"""Tree viewing a previous revision.
154
File text can be retrieved from the text store.
156
TODO: Some kind of `__repr__` method, but a good one
157
probably means knowing the branch and revision number,
158
or at least passing a description to the constructor.
161
def __init__(self, branch, inv, revision_id):
162
# for compatability the 'branch' parameter has not been renamed to
163
# repository at this point. However, we should change RevisionTree's
164
# construction to always be via Repository and not via direct
165
# construction - this will mean that we can change the constructor
166
# with much less chance of breaking client code.
167
self._repository = branch
168
self._weave_store = branch.weave_store
169
self._inventory = inv
170
self._revision_id = revision_id
172
def get_parent_ids(self):
173
"""See Tree.get_parent_ids.
175
A RevisionTree's parents match the revision graph.
177
parent_ids = self._repository.get_revision(self._revision_id).parent_ids
180
def get_revision_id(self):
181
"""Return the revision id associated with this tree."""
182
return self._revision_id
184
def get_weave(self, file_id):
185
return self._weave_store.get_weave(file_id,
186
self._repository.get_transaction())
188
def get_file_lines(self, file_id):
189
ie = self._inventory[file_id]
190
weave = self.get_weave(file_id)
191
return weave.get_lines(ie.revision)
193
def get_file_text(self, file_id):
194
return ''.join(self.get_file_lines(file_id))
196
def get_file(self, file_id):
197
return StringIO(self.get_file_text(file_id))
199
def get_file_size(self, file_id):
200
return self._inventory[file_id].text_size
202
def get_file_sha1(self, file_id, path=None):
203
ie = self._inventory[file_id]
204
if ie.kind == "file":
208
def get_file_mtime(self, file_id, path=None):
209
ie = self._inventory[file_id]
210
revision = self._repository.get_revision(ie.revision)
211
return revision.timestamp
213
def is_executable(self, file_id, path=None):
214
ie = self._inventory[file_id]
215
if ie.kind != "file":
217
return self._inventory[file_id].executable
219
def has_filename(self, filename):
220
return bool(self.inventory.path2id(filename))
222
def list_files(self):
223
# The only files returned by this are those from the version
224
entries = self.inventory.iter_entries()
225
# skip the root for compatability with the current apis.
227
for path, entry in entries:
228
yield path, 'V', entry.kind, entry.file_id, entry
230
def get_symlink_target(self, file_id):
231
ie = self._inventory[file_id]
232
return ie.symlink_target;
234
def kind(self, file_id):
235
return self._inventory[file_id].kind
238
self._repository.lock_read()
241
self._repository.unlock()
152
from bzrlib.revisiontree import RevisionTree
244
155
class EmptyTree(Tree):