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'))
70
69
def __init__(self, inv, parent_id, hexsha, path, basename, executable):
71
super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path,
70
super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path, basename, executable)
74
72
self.text_id = None
75
73
self.symlink_target = None
78
76
def text_sha1(self):
79
return osutils.sha_strings(self.object.chunked)
77
return osutils.sha_string(self.object.data)
82
80
def text_size(self):
100
other = inventory.InventoryFile(self.file_id, self.name,
98
other = inventory.InventoryFile(self.file_id, self.name, self.parent_id)
102
99
other.executable = self.executable
103
100
other.text_id = self.text_id
104
101
other.text_sha1 = self.text_sha1
129
126
other = inventory.InventoryLink(self.file_id, self.name, self.parent_id)
130
other.executable = self.executable
131
127
other.symlink_target = self.symlink_target
132
128
other.revision = self.revision
140
136
def __init__(self, inv, parent_id, hexsha, path, basename, executable):
141
137
super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
143
self.reference_revision = inv.mapping.revision_id_foreign_to_bzr(hexsha)
144
138
self.text_sha1 = None
145
139
self.text_size = None
146
140
self.symlink_target = None
179
173
for mode, name, hexsha in self.object.entries():
180
174
basename = name.decode("utf-8")
181
175
child_path = osutils.pathjoin(self.path, basename)
182
if self._inventory.mapping.is_control_file(child_path):
184
176
executable = mode_is_executable(mode)
185
177
kind_class = {'directory': GitInventoryDirectory,
186
178
'file': GitInventoryFile,
187
179
'symlink': GitInventoryLink,
188
180
'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
189
self._children[basename] = kind_class(self._inventory,
190
self.file_id, hexsha, child_path, basename, executable)
181
self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
193
other = inventory.InventoryDirectory(self.file_id, self.name,
184
other = inventory.InventoryDirectory(self.file_id, self.name,
195
186
other.revision = self.revision
196
187
# note that children are *not* copied; they're pulled across when
201
192
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):
194
def __init__(self, tree_id, mapping, store, revision_id):
208
195
super(GitInventory, self).__init__(revision_id=revision_id)
209
196
self.store = store
210
self.fileid_map = fileid_map
211
197
self.mapping = mapping
212
198
self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
214
200
def _get_ie(self, path):
215
if path == "" or path == []:
217
if isinstance(path, basestring):
218
parts = path.split("/")
203
parts = path.split("/")
222
205
for name in parts:
223
ie = ie.children[name]
206
ie = ie.children[name]
226
209
def has_filename(self, path):
254
237
def __getitem__(self, file_id):
255
238
if file_id == inventory.ROOT_ID:
257
path = self.fileid_map.lookup_path(file_id)
240
path = self.mapping.parse_file_id(file_id)
259
242
return self._get_ie(path)
264
247
class GitIndexInventory(inventory.Inventory):
265
248
"""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)
250
def __init__(self, basis_inventory, mapping, index, store):
251
super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
276
252
self.basis_inv = basis_inventory
277
self.fileid_map = fileid_map
253
self.mapping = mapping
278
254
self.index = index
279
255
self._contents_read = False
281
self.root = self.add_path("", 'directory',
282
self.fileid_map.lookup_file_id(""), None)
256
self.root = self.add_path("", 'directory',
257
self.mapping.generate_file_id(""), None)
284
259
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
285
260
self._read_contents()
286
return super(GitIndexInventory, self).iter_entries_by_dir(
287
specific_file_ids=specific_file_ids, yield_parents=yield_parents)
261
return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
289
263
def has_id(self, file_id):
290
if type(file_id) != str:
293
265
self.id2path(file_id)
302
274
return super(GitIndexInventory, self).has_filename(path)
304
276
def id2path(self, file_id):
305
if type(file_id) != str:
307
path = self.fileid_map.lookup_path(file_id)
277
path = self.mapping.parse_file_id(file_id)
308
278
if path in self.index:
310
280
self._read_contents()
311
281
return super(GitIndexInventory, self).id2path(file_id)
313
283
def path2id(self, path):
314
if type(path) in (list, tuple):
315
path = "/".join(path)
316
284
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:
285
return self.mapping.generate_file_id(path)
286
self._read_contents()
287
return super(GitIndexInventory, self).path2id(path)
325
289
def __getitem__(self, file_id):
326
290
self._read_contents()
333
297
pb = ui.ui_factory.nested_progress_bar()
335
299
for i, (path, value) in enumerate(self.index.iteritems()):
336
pb.update("creating working inventory from index",
300
pb.update("creating working inventory from index",
337
301
i, len(self.index))
338
302
assert isinstance(path, str)
339
303
assert isinstance(value, tuple) and len(value) == 10
340
304
(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)
306
old_ie = self.basis_inv._get_ie(path)
348
309
if old_ie is None:
349
file_id = self.fileid_map.lookup_file_id(path)
310
file_id = self.mapping.generate_file_id(path)
351
312
file_id = old_ie.file_id
352
if type(file_id) != str:
354
313
kind = mode_kind(mode)
355
314
if old_ie is not None and old_ie.hexsha == sha:
356
315
# Hasn't changed since basis inv
357
316
self.add_parents(path)
360
ie = self.add_path(path, kind, file_id,
361
self.add_parents(path))
362
data = self.store[sha].data
319
ie = self.add_path(path, kind, file_id, self.add_parents(path))
320
data = store[sha].data
363
321
if kind == "symlink":
364
322
ie.symlink_target = data
377
335
parent_fid = None
379
337
parent_fid = self.add_parents(dirname)
380
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:
338
ie = self.add_path(dirname, 'directory',
339
self.mapping.generate_file_id(dirname), parent_fid)
340
if ie.file_id in self.basis_inv:
383
341
ie.revision = self.basis_inv[ie.file_id].revision
384
342
file_id = ie.file_id
385
if type(file_id) != str: