51
51
self.revision = self._inventory.revision_id
52
52
self.executable = executable
53
self.file_id = self._inventory.fileid_map.lookup_file_id(
53
self.file_id = self._inventory.mapping.generate_file_id(path.encode('utf-8'))
179
178
for mode, name, hexsha in self.object.entries():
180
179
basename = name.decode("utf-8")
181
180
child_path = osutils.pathjoin(self.path, basename)
182
if self._inventory.mapping.is_control_file(child_path):
184
181
executable = mode_is_executable(mode)
185
182
kind_class = {'directory': GitInventoryDirectory,
186
183
'file': GitInventoryFile,
187
184
'symlink': GitInventoryLink,
188
185
'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
189
self._children[basename] = kind_class(self._inventory,
190
self.file_id, hexsha, child_path, basename, executable)
186
self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
193
189
other = inventory.InventoryDirectory(self.file_id, self.name,
201
197
class GitInventory(inventory.Inventory):
204
return "<%s for %r in %r>" % (self.__class__.__name__,
205
self.root.hexsha, self.store)
207
def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
199
def __init__(self, tree_id, mapping, store, revision_id):
208
200
super(GitInventory, self).__init__(revision_id=revision_id)
209
201
self.store = store
210
self.fileid_map = fileid_map
211
202
self.mapping = mapping
212
203
self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
214
205
def _get_ie(self, path):
215
if path == "" or path == []:
217
if isinstance(path, basestring):
218
parts = path.split("/")
208
parts = path.split("/")
222
210
for name in parts:
223
211
ie = ie.children[name]
254
242
def __getitem__(self, file_id):
255
243
if file_id == inventory.ROOT_ID:
257
path = self.fileid_map.lookup_path(file_id)
245
path = self.mapping.parse_file_id(file_id)
259
247
return self._get_ie(path)
264
252
class GitIndexInventory(inventory.Inventory):
265
253
"""Inventory that retrieves its contents from an index file."""
268
return "<%s for %r>" % (self.__class__.__name__, self.index)
270
def __init__(self, basis_inventory, fileid_map, index, store):
271
if basis_inventory is None:
274
root_id = basis_inventory.root.file_id
275
super(GitIndexInventory, self).__init__(revision_id=None, root_id=root_id)
255
def __init__(self, basis_inventory, mapping, index, store):
256
super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
276
257
self.basis_inv = basis_inventory
277
self.fileid_map = fileid_map
258
self.mapping = mapping
278
259
self.index = index
279
260
self._contents_read = False
281
261
self.root = self.add_path("", 'directory',
282
self.fileid_map.lookup_file_id(""), None)
262
self.mapping.generate_file_id(""), None)
284
264
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
285
265
self._read_contents()
286
return super(GitIndexInventory, self).iter_entries_by_dir(
287
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
266
return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
289
268
def has_id(self, file_id):
290
if type(file_id) != str:
293
270
self.id2path(file_id)
302
279
return super(GitIndexInventory, self).has_filename(path)
304
281
def id2path(self, file_id):
305
if type(file_id) != str:
307
path = self.fileid_map.lookup_path(file_id)
282
path = self.mapping.parse_file_id(file_id)
308
283
if path in self.index:
310
285
self._read_contents()
311
286
return super(GitIndexInventory, self).id2path(file_id)
313
288
def path2id(self, path):
314
if type(path) in (list, tuple):
315
path = "/".join(path)
316
289
if path in self.index:
317
file_id = self.fileid_map.lookup_file_id(path)
319
self._read_contents()
320
file_id = super(GitIndexInventory, self).path2id(path)
321
if file_id is not None and type(file_id) is not str:
290
return self.mapping.generate_file_id(path)
291
self._read_contents()
292
return super(GitIndexInventory, self).path2id(path)
325
294
def __getitem__(self, file_id):
326
295
self._read_contents()
338
307
assert isinstance(path, str)
339
308
assert isinstance(value, tuple) and len(value) == 10
340
309
(ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
341
if self.basis_inv is not None:
343
old_ie = self.basis_inv._get_ie(path)
311
old_ie = self.basis_inv._get_ie(path)
348
314
if old_ie is None:
349
file_id = self.fileid_map.lookup_file_id(path)
315
file_id = self.mapping.generate_file_id(path)
351
317
file_id = old_ie.file_id
352
if type(file_id) != str:
354
318
kind = mode_kind(mode)
355
319
if old_ie is not None and old_ie.hexsha == sha:
356
320
# Hasn't changed since basis inv
379
343
parent_fid = self.add_parents(dirname)
380
344
ie = self.add_path(dirname, 'directory',
381
self.fileid_map.lookup_file_id(dirname), parent_fid)
382
if self.basis_inv is not None and ie.file_id in self.basis_inv:
345
self.mapping.generate_file_id(dirname), parent_fid)
346
if ie.file_id in self.basis_inv:
383
347
ie.revision = self.basis_inv[ie.file_id].revision
384
348
file_id = ie.file_id
385
if type(file_id) != str: