167
167
def import_git_submodule(texts, mapping, path, (base_hexsha, hexsha),
168
base_inv, base_ie, parent_id, revision_id, parent_invs, lookup_object):
168
base_inv, parent_id, revision_id, parent_invs, lookup_object,
170
if base_hexsha == hexsha and base_mode == mode:
169
172
file_id = mapping.generate_file_id(path)
170
173
ie = TreeReference(file_id, urlutils.basename(path.decode("utf-8")),
172
175
ie.revision = revision_id
176
if base_hexsha is None:
177
if (base_ie.kind == ie.kind and
178
base_ie.reference_revision == ie.reference_revision):
179
ie.revision = base_ie.revision
180
180
ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
181
181
texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), (), None, [])])
182
182
invdelta = [(oldpath, path, file_id, ie)]
198
198
def import_git_tree(texts, mapping, path, (base_hexsha, hexsha), base_inv,
199
199
base_inv_shamap, base_ie, parent_id, revision_id, parent_invs,
200
lookup_object, allow_submodules=False):
200
lookup_object, (base_mode, mode), allow_submodules=False):
201
201
"""Import a git tree object into a bzr repository.
203
203
:param texts: VersionedFiles object to add to
206
206
:param base_inv: Base inventory against which to return inventory delta
207
207
:return: Inventory delta for this subtree
209
if base_hexsha == hexsha and base_mode == mode:
210
# If nothing has changed since the base revision, we're done
210
213
file_id = mapping.generate_file_id(path)
211
214
# We just have to hope this is indeed utf-8:
212
215
ie = InventoryDirectory(file_id, urlutils.basename(path.decode("utf-8")),
217
tree = lookup_object(hexsha)
218
if base_hexsha is None:
221
base_tree = lookup_object(base_hexsha)
222
if base_tree is None:
215
223
# Newly appeared here
216
224
ie.revision = revision_id
217
225
texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), (), None, [])])
218
226
invdelta.append((None, path, file_id, ie))
220
if base_hexsha == hexsha:
221
# If nothing has changed since the base revision, we're done
223
if base_ie.kind != "directory":
224
ie.revision = revision_id
225
texts.insert_record_stream([ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
226
invdelta.append((base_inv.id2path(ie.file_id), path, ie.file_id, ie))
227
tree = lookup_object(hexsha)
228
if base_hexsha is None:
231
base_tree = lookup_object(base_hexsha)
227
elif type(base_tree) is not Tree:
228
ie.revision = revision_id
229
texts.insert_record_stream([ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
230
invdelta.append((base_inv.id2path(ie.file_id), path, ie.file_id, ie))
233
231
if base_ie is not None and base_ie.kind == "directory":
234
232
base_children = base_ie.children
257
255
(child_base_hexsha, child_hexsha),
258
256
base_inv, base_inv_shamap, base_children.get(basename),
259
257
file_id, revision_id, parent_invs, lookup_object,
258
(child_base_mode, child_mode),
260
259
allow_submodules=allow_submodules)
261
260
elif S_ISGITLINK(child_mode): # submodule
262
261
if not allow_submodules:
264
263
subinvdelta, grandchildmodes, subshamap = import_git_submodule(
265
264
texts, mapping, child_path,
266
265
(child_base_hexsha, child_hexsha),
267
base_inv, base_children.get(basename),
268
file_id, revision_id, parent_invs, lookup_object)
266
base_inv, file_id, revision_id, parent_invs, lookup_object,
267
(child_base_mode, child_mode))
270
269
subinvdelta, subshamap = import_git_blob(texts, mapping,
271
270
child_path, (child_base_hexsha, child_hexsha),
281
280
stat.S_IFLNK, DEFAULT_FILE_MODE|0111):
282
281
child_modes[child_path] = child_mode
283
282
# Remove any children that have disappeared
284
if base_ie is not None and base_ie.kind == "directory":
283
if base_tree is not None and type(base_tree) is Tree:
285
284
invdelta.extend(remove_disappeared_children(base_inv.id2path(file_id),
286
285
base_children, existing_children))
287
286
shamap[file_id] = hexsha
302
301
base_inv_shamap = None # Should never be accessed
305
305
base_inv = parent_invs[0]
306
306
base_ie = base_inv.root
307
307
base_inv_shamap = target_git_object_retriever._idmap.get_inventory_sha_map(base_inv.revision_id)
308
308
base_tree = lookup_object(o.parents[0]).tree
309
base_mode = stat.S_IFDIR
309
310
inv_delta, unusual_modes, shamap = import_git_tree(repo.texts,
310
311
mapping, "", (base_tree, o.tree), base_inv, base_inv_shamap,
311
312
base_ie, None, rev.revision_id, parent_invs, lookup_object,
313
(base_mode, stat.S_IFDIR),
312
314
allow_submodules=getattr(repo._format, "supports_tree_reference", False))
314
316
for (oldpath, newpath, fileid, new_ie) in inv_delta: