80
def import_git_blob(texts, mapping, path, hexsha, base_inv, base_inv_shamap,
81
base_ie, parent_id, revision_id, parent_invs, lookup_object,
81
def import_git_blob(texts, mapping, path, hexsha, base_hexsha,
82
base_inv, base_inv_shamap, base_ie, parent_id, revision_id,
83
parent_invs, lookup_object, executable, symlink):
83
84
"""Import a git blob object into a bzr repository.
85
86
:param texts: VersionedFiles to add to
96
97
ie = cls(file_id, urlutils.basename(path).decode("utf-8"), parent_id)
97
98
ie.executable = executable
98
99
# See if this has changed at all
103
base_sha = base_inv_shamap.lookup_blob(file_id, base_ie.revision)
107
if (base_sha == hexsha and base_ie.executable == ie.executable
108
and base_ie.kind == ie.kind):
109
# If nothing has changed since the base revision, we're done
111
if base_sha == hexsha and base_ie.kind == ie.kind:
100
if (base_hexsha == hexsha and base_ie.executable == ie.executable
101
and base_ie.kind == ie.kind):
102
# If nothing has changed since the base revision, we're done
104
if base_hexsha == hexsha and base_ie.kind == ie.kind:
112
105
ie.text_size = base_ie.text_size
113
106
ie.text_sha1 = base_ie.text_sha1
114
107
ie.symlink_target = base_ie.symlink_target
176
def import_git_submodule(texts, mapping, path, hexsha, base_inv, base_ie,
177
parent_id, revision_id, parent_invs, lookup_object):
169
def import_git_submodule(texts, mapping, path, hexsha, base_hexsha,
170
base_inv, base_ie, parent_id, revision_id, parent_invs, lookup_object):
178
171
file_id = mapping.generate_file_id(path)
179
172
ie = TreeReference(file_id, urlutils.basename(path.decode("utf-8")),
207
def import_git_tree(texts, mapping, path, hexsha, base_inv, base_inv_shamap,
208
base_ie, parent_id, revision_id, parent_invs, lookup_object,
209
allow_submodules=False):
200
def import_git_tree(texts, mapping, path, hexsha, base_hexsha, base_inv,
201
base_inv_shamap, base_ie, parent_id, revision_id, parent_invs,
202
lookup_object, allow_submodules=False):
210
203
"""Import a git tree object into a bzr repository.
212
205
:param texts: VersionedFiles object to add to
226
219
texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), (), None, [])])
227
220
invdelta.append((None, path, file_id, ie))
229
# See if this has changed at all
231
base_sha = base_inv_shamap.lookup_tree(file_id)
232
except (KeyError, NotImplementedError):
235
if base_sha == hexsha:
236
# If nothing has changed since the base revision, we're done
222
if base_hexsha == hexsha:
223
# If nothing has changed since the base revision, we're done
238
225
if base_ie.kind != "directory":
239
226
ie.revision = revision_id
240
227
texts.insert_record_stream([ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
241
228
invdelta.append((base_inv.id2path(ie.file_id), path, ie.file_id, ie))
229
tree = lookup_object(hexsha)
230
if base_hexsha is None:
233
base_tree = lookup_object(base_hexsha)
242
235
if base_ie is not None and base_ie.kind == "directory":
243
236
base_children = base_ie.children
247
240
existing_children = set()
250
tree = lookup_object(hexsha)
251
243
for mode, name, child_hexsha in tree.entries():
252
244
basename = name.decode("utf-8")
253
245
existing_children.add(basename)
254
246
child_path = osutils.pathjoin(path, name)
247
if type(base_tree) is Tree:
249
child_base_mode, child_base_hexsha = base_tree[name]
251
child_base_hexsha = None
254
child_base_hexsha = None
255
256
if stat.S_ISDIR(mode):
256
257
subinvdelta, grandchildmodes, subshamap = import_git_tree(
257
texts, mapping, child_path, child_hexsha, base_inv,
258
base_inv_shamap, base_children.get(basename), file_id,
259
revision_id, parent_invs, lookup_object,
258
texts, mapping, child_path, child_hexsha, child_base_hexsha,
259
base_inv, base_inv_shamap, base_children.get(basename),
260
file_id, revision_id, parent_invs, lookup_object,
260
261
allow_submodules=allow_submodules)
261
262
elif S_ISGITLINK(mode): # submodule
262
263
if not allow_submodules:
263
264
raise SubmodulesRequireSubtrees()
264
265
subinvdelta, grandchildmodes, subshamap = import_git_submodule(
265
texts, mapping, child_path, child_hexsha, base_inv, base_children.get(basename),
266
texts, mapping, child_path, child_hexsha, child_base_hexsha,
267
base_inv, base_children.get(basename),
266
268
file_id, revision_id, parent_invs, lookup_object)
268
270
subinvdelta, subshamap = import_git_blob(texts, mapping,
269
child_path, child_hexsha, base_inv, base_inv_shamap,
271
child_path, child_hexsha, child_base_hexsha,
272
base_inv, base_inv_shamap,
270
273
base_children.get(basename), file_id,
271
274
revision_id, parent_invs, lookup_object,
272
275
mode_is_executable(mode), stat.S_ISLNK(mode))
297
300
base_inv = Inventory(root_id=None)
299
302
base_inv_shamap = None # Should never be accessed
301
305
base_inv = parent_invs[0]
302
306
base_ie = base_inv.root
303
307
base_inv_shamap = target_git_object_retriever._idmap.get_inventory_sha_map(base_inv.revision_id)
308
base_tree = lookup_object(o.parents[0]).tree
304
309
inv_delta, unusual_modes, shamap = import_git_tree(repo.texts,
305
mapping, "", o.tree, base_inv, base_inv_shamap, base_ie, None,
306
rev.revision_id, parent_invs, lookup_object,
310
mapping, "", o.tree, base_tree, base_inv, base_inv_shamap,
311
base_ie, None, rev.revision_id, parent_invs, lookup_object,
307
312
allow_submodules=getattr(repo._format, "supports_tree_reference", False))
309
314
for (oldpath, newpath, fileid, new_ie) in inv_delta: