103
101
self._inventory = inv
105
103
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]
104
ie = self._inventory[file_id]
109
106
revision = self._repository.get_revision(ie.revision)
110
107
except errors.NoSuchRevision:
112
109
return revision.timestamp
114
111
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
112
return self._inventory[file_id].text_size
118
114
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]
115
ie = self._inventory[file_id]
121
116
if ie.kind == "file":
122
117
return ie.text_sha1
125
120
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]
121
ie = self._inventory[file_id]
128
122
return ie.revision
130
124
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]
125
ie = self._inventory[file_id]
133
126
if ie.kind != "file":
135
128
return ie.executable
137
130
def has_filename(self, filename):
138
return bool(self.path2id(filename))
131
return bool(self.inventory.path2id(filename))
140
133
def list_files(self, include_root=False, from_dir=None, recursive=True):
141
134
# The only files returned by this are those from the version
142
136
if from_dir is None:
143
137
from_dir_id = None
144
inv = self.root_inventory
146
inv, from_dir_id = self._path2inv_file_id(from_dir)
139
from_dir_id = inv.path2id(from_dir)
147
140
if from_dir_id is None:
148
141
# Directory not versioned
155
148
yield path, 'V', entry.kind, entry.file_id, entry
157
150
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]
151
ie = self._inventory[file_id]
160
152
# Inventories store symlink targets in unicode
161
153
return ie.symlink_target
163
155
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
156
return self.inventory[file_id].reference_revision
167
158
def get_root_id(self):
168
if self.root_inventory.root:
169
return self.root_inventory.root.file_id
159
if self.inventory.root:
160
return self.inventory.root.file_id
171
162
def kind(self, file_id):
172
inv, inv_file_id = self._unpack_file_id(file_id)
173
return inv[inv_file_id].kind
163
return self._inventory[file_id].kind
175
165
def path_content_summary(self, path):
176
166
"""See Tree.path_content_summary."""
177
inv, file_id = self._path2inv_file_id(path)
167
id = self.inventory.path2id(path)
179
169
return ('missing', None, None, None)
170
entry = self._inventory[id]
181
171
kind = entry.kind
182
172
if kind == 'file':
183
173
return (kind, entry.text_size, entry.executable, entry.text_sha1)
242
233
annotations = annotator.annotate_flat(text_key)
243
234
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
237
class InterCHKRevisionTree(tree.InterTree):
260
238
"""Fast path optimiser for RevisionTrees with CHK inventories."""
265
243
and isinstance(target, RevisionTree)):
267
245
# Only CHK inventories have id_to_entry attribute
268
source.root_inventory.id_to_entry
269
target.root_inventory.id_to_entry
246
source.inventory.id_to_entry
247
target.inventory.id_to_entry
271
249
except AttributeError:
290
268
# to CHKInventory.iter_changes and do a better job there -- vila
292
270
changed_file_ids = set()
293
# FIXME: nested tree support
294
for result in self.target.root_inventory.iter_changes(
295
self.source.root_inventory):
271
for result in self.target.inventory.iter_changes(self.source.inventory):
296
272
if specific_file_ids is not None:
297
273
file_id = result[0]
298
274
if file_id not in specific_file_ids:
315
291
# Now walk the whole inventory, excluding the already yielded
317
# FIXME: Support nested trees
318
293
changed_file_ids = set(changed_file_ids)
319
for relpath, entry in self.target.root_inventory.iter_entries():
294
for relpath, entry in self.target.inventory.iter_entries():
320
295
if (specific_file_ids is not None
321
296
and not entry.file_id in specific_file_ids):