100
98
# We just have to hope this is indeed utf-8:
101
99
ie = cls(file_id, urlutils.basename(path).decode("utf-8"), parent_id)
102
100
ie.executable = executable
103
102
# See if this has changed at all
105
104
base_ie = base_inv[file_id]
120
121
ie.text_size = base_ie.text_size
121
122
ie.text_sha1 = base_ie.text_sha1
122
123
ie.symlink_target = base_ie.symlink_target
123
if ie.executable == base_ie.executable:
124
ie.revision = base_ie.revision
126
blob = lookup_object(hexsha)
124
ie.revision = base_ie.revision
128
126
blob = lookup_object(hexsha)
129
127
if ie.kind == "symlink":
131
128
ie.symlink_target = blob.data
132
129
ie.text_size = None
133
130
ie.text_sha1 = None
146
143
pie = pinv[file_id]
149
if pie.text_sha1 == ie.text_sha1 and pie.executable == ie.executable and pie.symlink_target == ie.symlink_target:
146
if pie.text_sha1 == ie.text_sha1:
150
147
# found a revision in one of the parents to use
151
148
ie.revision = pie.revision
164
161
old_path = base_inv.id2path(file_id)
167
invdelta = [(old_path, path, file_id, ie)]
168
invdelta.extend(remove_disappeared_children(base_inv, base_ie, []))
169
return (invdelta, shamap)
172
def import_git_submodule(texts, mapping, path, hexsha, base_inv, parent_id,
173
revision_id, parent_invs, shagitmap, lookup_object):
174
raise NotImplementedError(import_git_submodule)
177
def remove_disappeared_children(base_inv, base_ie, existing_children):
178
if base_ie is None or base_ie.kind != 'directory':
181
deletable = [v for k,v in base_ie.children.iteritems() if k not in existing_children]
184
ret.append((base_inv.id2path(ie.file_id), None, ie.file_id, None))
185
if ie.kind == "directory":
186
deletable.extend(ie.children.values())
164
return ([(old_path, path, file_id, ie)], shamap)
190
167
def import_git_tree(texts, mapping, path, hexsha, base_inv, parent_id,
211
189
texts.add_lines((file_id, ie.revision), (), [])
212
190
invdelta.append((None, path, file_id, ie))
192
base_sha = base_ie.text_id
214
193
# See if this has changed at all
216
base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
196
base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
220
200
if base_sha == hexsha:
221
201
# If nothing has changed since the base revision, we're done
222
202
return [], {}, []
223
if base_ie.kind != "directory":
224
ie.revision = revision_id
225
texts.add_lines((ie.file_id, ie.revision), (), [])
226
invdelta.append((base_inv.id2path(ie.file_id), path, ie.file_id, ie))
227
203
# Remember for next time
228
204
existing_children = set()
234
210
existing_children.add(basename)
235
211
child_path = osutils.pathjoin(path, name)
236
212
if stat.S_ISDIR(mode):
237
subinvdelta, grandchildmodes, subshamap = import_git_tree(
238
texts, mapping, child_path, child_hexsha, base_inv,
239
file_id, revision_id, parent_invs, shagitmap, lookup_object)
240
invdelta.extend(subinvdelta)
241
child_modes.update(grandchildmodes)
242
shamap.extend(subshamap)
243
elif S_ISGITLINK(mode): # submodule
244
subinvdelta, grandchildmodes, subshamap = import_git_submodule(
245
texts, mapping, child_path, child_hexsha, base_inv,
246
file_id, revision_id, parent_invs, shagitmap, lookup_object)
213
subinvdelta, grandchildmodes, subshamap = import_git_tree(texts,
214
mapping, child_path, child_hexsha, base_inv, file_id,
215
revision_id, parent_invs, shagitmap, lookup_object)
247
216
invdelta.extend(subinvdelta)
248
217
child_modes.update(grandchildmodes)
249
218
shamap.extend(subshamap)
258
227
stat.S_IFLNK, DEFAULT_FILE_MODE|0111):
259
228
child_modes[child_path] = mode
260
229
# Remove any children that have disappeared
261
invdelta.extend(remove_disappeared_children(base_inv, base_ie, existing_children))
230
if base_ie is not None and base_ie.kind == 'directory':
231
deletable = [v for k,v in base_ie.children.iteritems() if k not in existing_children]
234
invdelta.append((base_inv.id2path(ie.file_id), None, ie.file_id, None))
235
if ie.kind == "directory":
236
deletable.extend(ie.children.values())
262
237
shamap.append((hexsha, "tree", (file_id, revision_id)))
263
238
return invdelta, child_modes, shamap
297
272
rev = mapping.import_commit(o)
298
273
if repo.has_revision(rev.revision_id):
300
squash_revision(repo, rev)
301
275
root_trees[rev.revision_id] = o.tree
302
276
revisions[rev.revision_id] = rev
303
277
graph.append((rev.revision_id, rev.parent_ids))
337
311
if unusual_modes != {}:
338
312
for path, mode in unusual_modes.iteritems():
339
313
warn_unusual_mode(rev.foreign_revid, path, mode)
340
mapping.import_unusual_file_modes(rev, unusual_modes)
342
315
basis_id = rev.parent_ids[0]
343
316
except IndexError:
347
320
parent_invs_cache[rev.revision_id] = inv
348
321
repo.add_revision(rev.revision_id, rev)
349
322
if "verify" in debug.debug_flags:
350
new_unusual_modes = mapping.export_unusual_file_modes(rev)
351
if new_unusual_modes != unusual_modes:
352
raise AssertionError("unusual modes don't match: %r != %r" % (unusual_modes, new_unusual_modes))
353
objs = inventory_to_tree_and_blobs(inv, repo.texts, mapping, unusual_modes)
323
objs = inventory_to_tree_and_blobs(inv, repo.texts, mapping)
354
324
for sha1, newobj, path in objs:
355
325
assert path is not None
356
326
oldobj = tree_lookup_path(lookup_object, root_trees[revid], path)
358
raise AssertionError("%r != %r in %s" % (oldobj, newobj, path))
327
assert oldobj == newobj, "%r != %r in %s" % (oldobj, newobj, path)
360
329
target_git_object_retriever._idmap.commit()