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