/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

Avoid the use of InventoryDirectory.children. This speeds up 
imports significantly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from dulwich.objects import (
18
18
    Commit,
19
19
    Tag,
 
20
    Tree,
20
21
    S_ISGITLINK,
21
22
    )
22
23
from dulwich.object_store import (
77
78
    )
78
79
 
79
80
 
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,
82
 
    executable, symlink):
 
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.
84
85
 
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
99
 
    if base_ie is None:
100
 
        base_sha = None
101
 
    else:
102
 
        try:
103
 
            base_sha = base_inv_shamap.lookup_blob(file_id, base_ie.revision)
104
 
        except KeyError:
105
 
            base_sha = None
106
 
        else:
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
110
 
                return [], []
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
 
103
        return [], []
 
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
173
166
    internal = False
174
167
 
175
168
 
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")),
180
173
        parent_id)
204
197
    return ret
205
198
 
206
199
 
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.
211
204
 
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))
228
221
    else:
229
 
        # See if this has changed at all
230
 
        try:
231
 
            base_sha = base_inv_shamap.lookup_tree(file_id)
232
 
        except (KeyError, NotImplementedError):
233
 
            pass
234
 
        else:
235
 
            if base_sha == hexsha:
236
 
                # If nothing has changed since the base revision, we're done
237
 
                return [], {}, []
 
222
        if base_hexsha == hexsha:
 
223
            # If nothing has changed since the base revision, we're done
 
224
            return [], {}, []
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:
 
231
        base_tree = None
 
232
    else:
 
233
        base_tree = lookup_object(base_hexsha)
 
234
 
242
235
    if base_ie is not None and base_ie.kind == "directory":
243
236
        base_children = base_ie.children
244
237
    else:
247
240
    existing_children = set()
248
241
    child_modes = {}
249
242
    shamap = {}
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:
 
248
            try:
 
249
                child_base_mode, child_base_hexsha = base_tree[name]
 
250
            except KeyError:
 
251
                child_base_hexsha = None
 
252
                child_base_mode = 0
 
253
        else:
 
254
            child_base_hexsha = None
 
255
            child_base_mode = 0
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)
267
269
        else:
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)
298
301
        base_ie = None
299
302
        base_inv_shamap = None # Should never be accessed
 
303
        base_tree = None
300
304
    else:
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))
308
313
    entries = []
309
314
    for (oldpath, newpath, fileid, new_ie) in inv_delta: