/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to fetch.py

Deal with all modes locally.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
            ie.text_sha1 = osutils.sha_string(blob.data)
120
120
    # Check what revision we should store
121
121
    parent_keys = []
122
 
    for pinv in parent_invs:
 
122
    for pinv in parent_invs[1:]:
123
123
        if pinv.revision_id == base_inv.revision_id:
124
124
            pie = base_ie
125
125
            if pie is None:
165
165
 
166
166
 
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,
 
169
    (base_mode, mode)):
 
170
    if base_hexsha == hexsha and base_mode == mode:
 
171
        return [], {}, {}
169
172
    file_id = mapping.generate_file_id(path)
170
173
    ie = TreeReference(file_id, urlutils.basename(path.decode("utf-8")),
171
174
        parent_id)
172
175
    ie.revision = revision_id
173
 
    if base_ie is None:
 
176
    if base_hexsha is None:
174
177
        oldpath = None
175
178
    else:
176
179
        oldpath = path
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)]
197
197
 
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.
202
202
 
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
208
208
    """
 
209
    if base_hexsha == hexsha and base_mode == mode:
 
210
        # If nothing has changed since the base revision, we're done
 
211
        return [], {}, []
209
212
    invdelta = []
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")),
213
216
        parent_id)
214
 
    if base_ie is None:
 
217
    tree = lookup_object(hexsha)
 
218
    if base_hexsha is None:
 
219
        base_tree = None
 
220
    else:
 
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))
219
 
    else:
220
 
        if base_hexsha == hexsha:
221
 
            # If nothing has changed since the base revision, we're done
222
 
            return [], {}, []
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:
229
 
        base_tree = None
230
 
    else:
231
 
        base_tree = lookup_object(base_hexsha)
232
 
 
 
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
235
233
    else:
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))
269
268
        else:
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
301
300
        base_ie = None
302
301
        base_inv_shamap = None # Should never be accessed
303
302
        base_tree = None
 
303
        base_mode = None
304
304
    else:
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))
313
315
    entries = []
314
316
    for (oldpath, newpath, fileid, new_ie) in inv_delta: