116
119
ie.text_size = len(blob.data)
117
120
ie.text_sha1 = osutils.sha_string(blob.data)
118
121
ie.executable = executable
119
# See if this is the same revision as one of the parents unchanged
122
# If there were no changes compared to the base inventory, there's no need
124
if (file_id in base_inv and
125
base_inv[file_id].parent_id == ie.parent_id and
126
base_inv[file_id].text_sha1 == ie.text_sha1 and
127
base_inv[file_id].executable == ie.executable):
129
# Check what revision we should store
121
131
for pinv in parent_invs:
122
132
if not file_id in pinv:
124
134
if pinv[file_id].text_sha1 == ie.text_sha1:
135
# found a revision in one of the parents to use
125
136
ie.revision = pinv[file_id].revision
127
138
parent_keys.append((file_id, pinv[file_id].revision))
128
ie.revision = revision_id
129
assert file_id is not None
130
assert ie.revision is not None
131
texts.add_lines((file_id, ie.revision), parent_keys,
132
osutils.split_lines(blob.data))
133
shagitmap.add_entry(blob.sha().hexdigest(), "blob",
134
(ie.file_id, ie.revision))
139
if ie.revision is None:
140
# Need to store a new revision
141
ie.revision = revision_id
142
assert file_id is not None
143
assert ie.revision is not None
144
texts.add_lines((file_id, ie.revision), parent_keys,
145
osutils.split_lines(blob.data))
146
shagitmap.add_entry(blob.sha().hexdigest(), "blob",
147
(ie.file_id, ie.revision))
148
if file_id in base_inv:
149
old_path = base_inv.id2path(file_id)
152
return [(old_path, path, file_id, ie)]
138
155
def import_git_tree(texts, mapping, path, tree, base_inv, parent_id,
145
162
:param base_inv: Base inventory against which to return inventory delta
146
163
:return: Inventory delta for this subtree
148
166
file_id = mapping.generate_file_id(path)
149
167
# We just have to hope this is indeed utf-8:
150
ie = InventoryDirectory(file_id,
151
urlutils.basename(path.decode("utf-8")), parent_id)
154
for pinv in parent_invs:
155
if not file_id in pinv:
168
ie = InventoryDirectory(file_id, urlutils.basename(path.decode("utf-8")),
170
if not file_id in base_inv:
171
# Newly appeared here
172
ie.revision = revision_id
173
texts.add_lines((file_id, ie.revision), [], [])
174
ret.append((None, path, file_id, ie))
176
# See if this has changed at all
158
tree_sha = shagitmap.lookup_tree(path, pinv[file_id].revision)
178
base_sha = shagitmap.lookup_tree(path, base_inv.revision_id)
162
182
if tree_sha == tree.id:
163
ie.revision = pinv[file_id].revision
165
parent_keys.append((file_id, pinv[file_id].revision))
166
if ie.revision is None:
167
ie.revision = revision_id
168
texts.add_lines((file_id, ie.revision), parent_keys, [])
169
shagitmap.add_entry(tree.id, "tree", (file_id, ie.revision))
183
# If nothing has changed since the base revision, we're done
185
# Remember for next time
186
shagitmap.add_entry(tree.id, "tree", (file_id, revision_id))
187
existing_children = set()
170
188
for mode, name, hexsha in tree.entries():
171
189
entry_kind = (mode & 0700000) / 0100000
172
190
basename = name.decode("utf-8")
191
existing_children.add(basename)
174
193
child_path = name
176
195
child_path = urlutils.join(path, name)
177
196
obj = lookup_object(hexsha)
178
197
if entry_kind == 0:
179
import_git_tree(texts, mapping, child_path, obj, base_inv,
180
parent_id, revision_id, parent_invs, shagitmap, lookup_object)
198
ret.extend(import_git_tree(texts, mapping, child_path, obj, base_inv,
199
file_id, revision_id, parent_invs, shagitmap, lookup_object))
181
200
elif entry_kind == 1:
182
201
fs_mode = mode & 0777
183
import_git_blob(texts, mapping, child_path, obj, base_inv,
184
parent_id, revision_id, parent_invs, shagitmap,
185
bool(fs_mode & 0111))
202
ret.extend(import_git_blob(texts, mapping, child_path, obj, base_inv,
203
file_id, revision_id, parent_invs, shagitmap,
204
bool(fs_mode & 0111)))
187
206
raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
207
# Remove any children that have disappeared
208
if file_id in base_inv:
209
for x in set(base_inv[file_id].children).difference(existing_children):
210
# TODO: Remove recursively if child is a directory
211
child_file_id = base_inv[file_id].children[x].file_id
212
ret.append((base_inv.id2path(child_file_id), None, child_file_id,
190
217
def import_git_objects(repo, mapping, object_iter, target_git_object_retriever,