74
70
def __init__(self, inv, parent_id, hexsha, path, basename, executable):
75
super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path, basename, executable)
71
super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path,
77
74
self.text_id = None
78
75
self.symlink_target = None
81
78
def text_sha1(self):
82
return osutils.sha_string(self.object.data)
79
return osutils.sha_strings(self.object.chunked)
85
82
def text_size(self):
103
other = inventory.InventoryFile(self.file_id, self.name, self.parent_id)
100
other = inventory.InventoryFile(self.file_id, self.name,
104
102
other.executable = self.executable
105
103
other.text_id = self.text_id
106
104
other.text_sha1 = self.text_sha1
141
140
def __init__(self, inv, parent_id, hexsha, path, basename, executable):
142
141
super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
143
self.reference_revision = inv.mapping.revision_id_foreign_to_bzr(hexsha)
143
144
self.text_sha1 = None
144
145
self.text_size = None
145
146
self.symlink_target = None
178
179
for mode, name, hexsha in self.object.entries():
179
180
basename = name.decode("utf-8")
180
181
child_path = osutils.pathjoin(self.path, basename)
182
if self._inventory.mapping.is_control_file(child_path):
181
184
executable = mode_is_executable(mode)
182
185
kind_class = {'directory': GitInventoryDirectory,
183
186
'file': GitInventoryFile,
184
187
'symlink': GitInventoryLink,
185
188
'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
186
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)
189
other = inventory.InventoryDirectory(self.file_id, self.name,
193
other = inventory.InventoryDirectory(self.file_id, self.name,
191
195
other.revision = self.revision
192
196
# note that children are *not* copied; they're pulled across when
197
201
class GitInventory(inventory.Inventory):
199
def __init__(self, tree_id, mapping, store, revision_id):
203
def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
200
204
super(GitInventory, self).__init__(revision_id=revision_id)
201
205
self.store = store
206
self.fileid_map = fileid_map
202
207
self.mapping = mapping
203
208
self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
252
257
class GitIndexInventory(inventory.Inventory):
253
258
"""Inventory that retrieves its contents from an index file."""
255
def __init__(self, basis_inventory, mapping, index, store):
260
def __init__(self, basis_inventory, fileid_map, index, store):
256
261
super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
257
262
self.basis_inv = basis_inventory
258
self.mapping = mapping
263
self.fileid_map = fileid_map
259
264
self.index = index
265
self._contents_read = False
267
self.root = self.add_path("", 'directory',
268
self.fileid_map.lookup_file_id(""), None)
270
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
271
self._read_contents()
272
return super(GitIndexInventory, self).iter_entries_by_dir(
273
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
275
def has_id(self, file_id):
276
if type(file_id) != str:
279
self.id2path(file_id)
281
except errors.NoSuchId:
284
def has_filename(self, path):
285
if path in self.index:
287
self._read_contents()
288
return super(GitIndexInventory, self).has_filename(path)
290
def id2path(self, file_id):
291
if type(file_id) != str:
293
path = self.fileid_map.lookup_path(file_id)
294
if path in self.index:
296
self._read_contents()
297
return super(GitIndexInventory, self).id2path(file_id)
299
def path2id(self, path):
300
if path in self.index:
301
file_id = self.fileid_map.lookup_file_id(path)
303
self._read_contents()
304
file_id = super(GitIndexInventory, self).path2id(path)
305
if type(file_id) is not str:
309
def __getitem__(self, file_id):
310
self._read_contents()
311
return super(GitIndexInventory, self).__getitem__(file_id)
313
def _read_contents(self):
314
if self._contents_read:
316
self._contents_read = True
261
317
pb = ui.ui_factory.nested_progress_bar()
263
319
for i, (path, value) in enumerate(self.index.iteritems()):
264
pb.update("creating working inventory from index",
320
pb.update("creating working inventory from index",
265
321
i, len(self.index))
266
322
assert isinstance(path, str)
267
323
assert isinstance(value, tuple) and len(value) == 10
273
329
if old_ie is None:
274
file_id = self.mapping.generate_file_id(path)
330
file_id = self.fileid_map.lookup_file_id(path)
276
332
file_id = old_ie.file_id
333
if type(file_id) != str:
277
335
kind = mode_kind(mode)
278
336
if old_ie is not None and old_ie.hexsha == sha:
279
337
# Hasn't changed since basis inv
280
338
self.add_parents(path)
283
ie = self.add_path(path, kind, file_id, self.add_parents(path))
284
data = store[sha].data
341
ie = self.add_path(path, kind, file_id,
342
self.add_parents(path))
343
data = self.store[sha].data
285
344
if kind == "symlink":
286
345
ie.symlink_target = data
294
353
def add_parents(self, path):
295
354
dirname, _ = osutils.split(path)
296
file_id = self.path2id(dirname)
355
file_id = super(GitIndexInventory, self).path2id(dirname)
297
356
if file_id is None:
298
357
if dirname == "":
299
358
parent_fid = None
301
360
parent_fid = self.add_parents(dirname)
302
ie = self.add_path(dirname, 'directory',
303
self.mapping.generate_file_id(dirname), parent_fid)
361
ie = self.add_path(dirname, 'directory',
362
self.fileid_map.lookup_file_id(dirname), parent_fid)
304
363
if ie.file_id in self.basis_inv:
305
364
ie.revision = self.basis_inv[ie.file_id].revision
306
365
file_id = ie.file_id
366
if type(file_id) != str: