132
class GitInventoryTreeReference(GitInventoryEntry):
136
def __init__(self, inv, parent_id, hexsha, path, basename, executable):
137
super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
138
self.text_sha1 = None
139
self.text_size = None
140
self.symlink_target = None
141
self.kind = 'tree-reference'
142
self._children = None
144
def kind_character(self):
145
"""See InventoryEntry.kind_character."""
131
149
class GitInventoryDirectory(GitInventoryEntry):
133
151
_git_class = Tree
155
173
for mode, name, hexsha in self.object.entries():
156
174
basename = name.decode("utf-8")
157
175
child_path = osutils.pathjoin(self.path, basename)
158
entry_kind = (mode & 0700000) / 0100000
159
fs_mode = mode & 0777
160
executable = bool(fs_mode & 0111)
162
kind_class = GitInventoryDirectory
163
elif entry_kind == 1:
164
file_kind = (mode & 070000) / 010000
166
kind_class = GitInventoryFile
168
kind_class = GitInventoryLink
170
raise AssertionError(
171
"Unknown file kind, perms=%o." % (mode,))
173
raise AssertionError(
174
"Unknown blob kind, perms=%r." % (mode,))
176
executable = mode_is_executable(mode)
177
kind_class = {'directory': GitInventoryDirectory,
178
'file': GitInventoryFile,
179
'symlink': GitInventoryLink,
180
'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
175
181
self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
239
247
class GitIndexInventory(inventory.Inventory):
240
248
"""Inventory that retrieves its contents from an index file."""
242
def __init__(self, basis_inventory, mapping, index):
250
def __init__(self, basis_inventory, mapping, index, store):
243
251
super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
244
252
self.basis_inv = basis_inventory
245
253
self.mapping = mapping
246
254
self.index = index
255
self._contents_read = False
256
self.root = self.add_path("", 'directory',
257
self.mapping.generate_file_id(""), None)
259
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
260
self._read_contents()
261
return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
263
def has_id(self, file_id):
265
self.id2path(file_id)
267
except errors.NoSuchId:
270
def has_filename(self, path):
271
if path in self.index:
273
self._read_contents()
274
return super(GitIndexInventory, self).has_filename(path)
276
def id2path(self, file_id):
277
path = self.mapping.parse_file_id(file_id)
278
if path in self.index:
280
self._read_contents()
281
return super(GitIndexInventory, self).id2path(file_id)
283
def path2id(self, path):
284
if path in self.index:
285
return self.mapping.generate_file_id(path)
286
self._read_contents()
287
return super(GitIndexInventory, self).path2id(path)
289
def __getitem__(self, file_id):
290
self._read_contents()
291
return super(GitIndexInventory, self).__getitem__(file_id)
293
def _read_contents(self):
294
if self._contents_read:
296
self._contents_read = True
248
297
pb = ui.ui_factory.nested_progress_bar()
250
299
for i, (path, value) in enumerate(self.index.iteritems()):
252
301
i, len(self.index))
253
302
assert isinstance(path, str)
254
303
assert isinstance(value, tuple) and len(value) == 10
255
(ctime, mtime, ino, dev, mode, uid, gid, size, sha, flags) = value
304
(ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
257
306
old_ie = self.basis_inv._get_ie(path)
261
310
file_id = self.mapping.generate_file_id(path)
263
312
file_id = old_ie.file_id
264
if stat.S_ISLNK(mode):
267
assert stat.S_ISREG(mode)
313
kind = mode_kind(mode)
269
314
if old_ie is not None and old_ie.hexsha == sha:
270
315
# Hasn't changed since basis inv
271
316
self.add_parents(path)
274
319
ie = self.add_path(path, kind, file_id, self.add_parents(path))
320
data = store[sha].data
321
if kind == "symlink":
322
ie.symlink_target = data
324
ie.text_sha1 = osutils.sha_string(data)
325
ie.text_size = len(data)
275
326
ie.revision = None
279
330
def add_parents(self, path):
280
331
dirname, _ = osutils.split(path)
281
file_id = self.path2id(dirname)
332
file_id = super(GitIndexInventory, self).path2id(dirname)
282
333
if file_id is None:
283
334
if dirname == "":
284
335
parent_fid = None