67
65
raise NotImplementedError(self.get_file_revision)
69
67
def get_file_text(self, file_id, path=None):
70
for (identifier, content) in self.iter_files_bytes([(file_id, None)]):
71
ret = "".join(content)
68
_, content = list(self.iter_files_bytes([(file_id, None)]))[0]
69
return ''.join(content)
74
71
def get_file(self, file_id, path=None):
75
72
return StringIO(self.get_file_text(file_id))
103
100
self._inventory = inv
105
102
def get_file_mtime(self, file_id, path=None):
106
inv, inv_file_id = self._unpack_file_id(file_id)
107
ie = inv[inv_file_id]
103
ie = self._inventory[file_id]
109
105
revision = self._repository.get_revision(ie.revision)
110
106
except errors.NoSuchRevision:
112
108
return revision.timestamp
114
110
def get_file_size(self, file_id):
115
inv, inv_file_id = self._unpack_file_id(file_id)
116
return inv[inv_file_id].text_size
111
return self._inventory[file_id].text_size
118
113
def get_file_sha1(self, file_id, path=None, stat_value=None):
119
inv, inv_file_id = self._unpack_file_id(file_id)
120
ie = inv[inv_file_id]
114
ie = self._inventory[file_id]
121
115
if ie.kind == "file":
122
116
return ie.text_sha1
125
119
def get_file_revision(self, file_id, path=None):
126
inv, inv_file_id = self._unpack_file_id(file_id)
127
ie = inv[inv_file_id]
120
ie = self._inventory[file_id]
128
121
return ie.revision
130
123
def is_executable(self, file_id, path=None):
131
inv, inv_file_id = self._unpack_file_id(file_id)
132
ie = inv[inv_file_id]
124
ie = self._inventory[file_id]
133
125
if ie.kind != "file":
135
127
return ie.executable
137
129
def has_filename(self, filename):
138
return bool(self.path2id(filename))
130
return bool(self.inventory.path2id(filename))
140
132
def list_files(self, include_root=False, from_dir=None, recursive=True):
141
133
# The only files returned by this are those from the version
142
135
if from_dir is None:
143
136
from_dir_id = None
144
inv = self.root_inventory
146
inv, from_dir_id = self._path2inv_file_id(from_dir)
138
from_dir_id = inv.path2id(from_dir)
147
139
if from_dir_id is None:
148
140
# Directory not versioned
155
147
yield path, 'V', entry.kind, entry.file_id, entry
157
149
def get_symlink_target(self, file_id, path=None):
158
inv, inv_file_id = self._unpack_file_id(file_id)
159
ie = inv[inv_file_id]
150
ie = self._inventory[file_id]
160
151
# Inventories store symlink targets in unicode
161
152
return ie.symlink_target
163
154
def get_reference_revision(self, file_id, path=None):
164
inv, inv_file_id = self._unpack_file_id(file_id)
165
return inv[inv_file_id].reference_revision
155
return self.inventory[file_id].reference_revision
167
157
def get_root_id(self):
168
if self.root_inventory.root:
169
return self.root_inventory.root.file_id
158
if self.inventory.root:
159
return self.inventory.root.file_id
171
161
def kind(self, file_id):
172
inv, inv_file_id = self._unpack_file_id(file_id)
173
return inv[inv_file_id].kind
162
return self._inventory[file_id].kind
175
164
def path_content_summary(self, path):
176
165
"""See Tree.path_content_summary."""
177
inv, file_id = self._path2inv_file_id(path)
166
id = self.inventory.path2id(path)
179
168
return ('missing', None, None, None)
169
entry = self._inventory[id]
181
170
kind = entry.kind
182
171
if kind == 'file':
183
172
return (kind, entry.text_size, entry.executable, entry.text_sha1)
225
215
def iter_files_bytes(self, desired_files):
226
216
"""See Tree.iter_files_bytes.
228
This version is implemented on top of Repository.iter_files_bytes"""
218
This version is implemented on top of Repository.extract_files_bytes"""
229
219
repo_desired_files = [(f, self.get_file_revision(f), i)
230
220
for f, i in desired_files]
232
222
for result in self._repository.iter_files_bytes(repo_desired_files):
234
224
except errors.RevisionNotPresent, e:
235
raise errors.NoSuchFile(e.file_id)
225
raise errors.NoSuchFile(e.revision_id)
237
227
def annotate_iter(self, file_id,
238
228
default_revision=revision.CURRENT_REVISION):
242
232
annotations = annotator.annotate_flat(text_key)
243
233
return [(key[-1], line) for key, line in annotations]
245
def __eq__(self, other):
248
if isinstance(other, InventoryRevisionTree):
249
return (self.root_inventory == other.root_inventory)
252
def __ne__(self, other):
253
return not (self == other)
256
raise ValueError('not hashable')
259
236
class InterCHKRevisionTree(tree.InterTree):
260
237
"""Fast path optimiser for RevisionTrees with CHK inventories."""
265
242
and isinstance(target, RevisionTree)):
267
244
# Only CHK inventories have id_to_entry attribute
268
source.root_inventory.id_to_entry
269
target.root_inventory.id_to_entry
245
source.inventory.id_to_entry
246
target.inventory.id_to_entry
271
248
except AttributeError:
290
267
# to CHKInventory.iter_changes and do a better job there -- vila
292
269
changed_file_ids = set()
293
# FIXME: nested tree support
294
for result in self.target.root_inventory.iter_changes(
295
self.source.root_inventory):
270
for result in self.target.inventory.iter_changes(self.source.inventory):
296
271
if specific_file_ids is not None:
297
272
file_id = result[0]
298
273
if file_id not in specific_file_ids:
315
290
# Now walk the whole inventory, excluding the already yielded
317
# FIXME: Support nested trees
318
292
changed_file_ids = set(changed_file_ids)
319
for relpath, entry in self.target.root_inventory.iter_entries():
293
for relpath, entry in self.target.inventory.iter_entries():
320
294
if (specific_file_ids is not None
321
295
and not entry.file_id in specific_file_ids):