/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

Default to using global user id rather than making one up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from dulwich.objects import (
22
22
    Commit,
23
23
    Tag,
24
 
    S_ISGITLINK,
25
24
    )
26
25
from dulwich.object_store import (
27
26
    tree_lookup_path,
66
65
    DEFAULT_FILE_MODE,
67
66
    inventory_to_tree_and_blobs,
68
67
    mode_is_executable,
69
 
    squash_revision,
70
68
    text_to_blob,
71
69
    warn_unusual_mode,
72
70
    )
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
 
101
    ie.text_id = hexsha
103
102
    # See if this has changed at all
104
103
    try:
105
104
        base_ie = base_inv[file_id]
107
106
        base_ie = None
108
107
        base_sha = None
109
108
    else:
 
109
        base_sha = base_ie.text_id
110
110
        try:
111
 
            base_sha = shagitmap.lookup_blob(file_id, base_ie.revision)
 
111
            if base_sha is None:
 
112
                base_sha = shagitmap.lookup_blob(file_id, base_ie.revision)
112
113
        except KeyError:
113
114
            base_sha = None
114
115
        else:
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
125
 
        else:
126
 
            blob = lookup_object(hexsha)
 
124
        ie.revision = base_ie.revision
127
125
    else:
128
126
        blob = lookup_object(hexsha)
129
127
        if ie.kind == "symlink":
130
 
            ie.revision = None
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]
147
144
            except NoSuchId:
148
145
                continue
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
152
149
            break
164
161
        old_path = base_inv.id2path(file_id)
165
162
    else:
166
163
        old_path = None
167
 
    invdelta = [(old_path, path, file_id, ie)]
168
 
    invdelta.extend(remove_disappeared_children(base_inv, base_ie, []))
169
 
    return (invdelta, shamap)
170
 
 
171
 
 
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)
175
 
 
176
 
 
177
 
def remove_disappeared_children(base_inv, base_ie, existing_children):
178
 
    if base_ie is None or base_ie.kind != 'directory':
179
 
        return []
180
 
    ret = []
181
 
    deletable = [v for k,v in base_ie.children.iteritems() if k not in existing_children]
182
 
    while deletable:
183
 
        ie = deletable.pop()
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())
187
 
    return ret
 
164
    return ([(old_path, path, file_id, ie)], shamap)
188
165
 
189
166
 
190
167
def import_git_tree(texts, mapping, path, hexsha, base_inv, parent_id, 
202
179
    # We just have to hope this is indeed utf-8:
203
180
    ie = InventoryDirectory(file_id, urlutils.basename(path.decode("utf-8")), 
204
181
        parent_id)
 
182
    ie.text_id = hexsha
205
183
    try:
206
184
        base_ie = base_inv[file_id]
207
185
    except NoSuchId:
211
189
        texts.add_lines((file_id, ie.revision), (), [])
212
190
        invdelta.append((None, path, file_id, ie))
213
191
    else:
 
192
        base_sha = base_ie.text_id
214
193
        # See if this has changed at all
215
194
        try:
216
 
            base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
 
195
            if base_sha is None:
 
196
                base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
217
197
        except KeyError:
218
198
            pass
219
199
        else:
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()
229
205
    child_modes = {}
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]
 
232
        while deletable:
 
233
            ie = deletable.pop()
 
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
264
239
 
297
272
            rev = mapping.import_commit(o)
298
273
            if repo.has_revision(rev.revision_id):
299
274
                continue
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)
341
314
        try:
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)
357
 
                if oldobj != newobj:
358
 
                    raise AssertionError("%r != %r in %s" % (oldobj, newobj, path))
 
327
                assert oldobj == newobj, "%r != %r in %s" % (oldobj, newobj, path)
359
328
 
360
329
    target_git_object_retriever._idmap.commit()
361
330