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