/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

Merge roundtrip support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    DEFAULT_FILE_MODE,
68
68
    mode_is_executable,
69
69
    mode_kind,
70
 
    squash_revision,
71
70
    warn_unusual_mode,
72
71
    )
73
72
from bzrlib.plugins.git.object_store import (
96
95
    :param blob: A git blob
97
96
    :return: Inventory delta for this file
98
97
    """
 
98
    if mapping.is_control_file(path):
 
99
        return []
99
100
    if base_hexsha == hexsha and base_mode == mode:
100
101
        # If nothing has changed since the base revision, we're done
101
102
        return []
132
133
            pie = pinv[file_id]
133
134
        except NoSuchId:
134
135
            continue
135
 
        if pie.text_sha1 == ie.text_sha1 and pie.executable == ie.executable and pie.symlink_target == ie.symlink_target:
 
136
        if (pie.text_sha1 == ie.text_sha1 and
 
137
            pie.executable == ie.executable and
 
138
            pie.symlink_target == ie.symlink_target):
136
139
            # found a revision in one of the parents to use
137
140
            ie.revision = pie.revision
138
141
            break
147
150
            chunks = []
148
151
        else: 
149
152
            chunks = blob.chunked
150
 
        texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), tuple(parent_keys), ie.text_sha1, chunks)])
 
153
        texts.insert_record_stream([
 
154
            ChunkedContentFactory((file_id, ie.revision),
 
155
                tuple(parent_keys), ie.text_sha1, chunks)])
151
156
    invdelta = []
152
157
    if base_hexsha is not None:
153
158
        old_path = path # Renames are not supported yet
180
185
    else:
181
186
        oldpath = path
182
187
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
183
 
    texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), (), None, [])])
 
188
    texts.insert_record_stream([
 
189
        ChunkedContentFactory((file_id, ie.revision), (), None, [])])
184
190
    invdelta = [(oldpath, path, file_id, ie)]
185
191
    return invdelta, {}
186
192
 
228
234
    if base_tree is None or type(base_tree) is not Tree:
229
235
        ie.revision = revision_id
230
236
        invdelta.append((old_path, path, ie.file_id, ie))
231
 
        texts.insert_record_stream([ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
 
237
        texts.insert_record_stream([
 
238
            ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
232
239
    # Remember for next time
233
240
    existing_children = set()
234
241
    child_modes = {}
245
252
            child_base_hexsha = None
246
253
            child_base_mode = 0
247
254
        if stat.S_ISDIR(child_mode):
248
 
            subinvdelta, grandchildmodes = import_git_tree(
249
 
                    texts, mapping, child_path, name,
250
 
                    (child_base_hexsha, child_hexsha),
251
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
252
 
                    (child_base_mode, child_mode), store_updater, 
253
 
                    lookup_file_id, allow_submodules=allow_submodules)
 
255
            subinvdelta, grandchildmodes = import_git_tree(texts, mapping,
 
256
                child_path, name, (child_base_hexsha, child_hexsha), base_inv,
 
257
                file_id, revision_id, parent_invs, lookup_object, 
 
258
                (child_base_mode, child_mode), store_updater, lookup_file_id,
 
259
                allow_submodules=allow_submodules)
254
260
        elif S_ISGITLINK(child_mode): # submodule
255
261
            if not allow_submodules:
256
262
                raise SubmodulesRequireSubtrees()
257
 
            subinvdelta, grandchildmodes = import_git_submodule(
258
 
                    texts, mapping, child_path, name,
259
 
                    (child_base_hexsha, child_hexsha),
260
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
261
 
                    (child_base_mode, child_mode), store_updater,
262
 
                    lookup_file_id)
 
263
            subinvdelta, grandchildmodes = import_git_submodule(texts, mapping,
 
264
                child_path, name, (child_base_hexsha, child_hexsha), base_inv,
 
265
                file_id, revision_id, parent_invs, lookup_object,
 
266
                (child_base_mode, child_mode), store_updater, lookup_file_id)
263
267
        else:
264
 
            subinvdelta = import_git_blob(texts, mapping,
265
 
                    child_path, name, (child_base_hexsha, child_hexsha),
266
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
267
 
                    (child_base_mode, child_mode), store_updater,
268
 
                    lookup_file_id)
 
268
            subinvdelta = import_git_blob(texts, mapping, child_path, name,
 
269
                (child_base_hexsha, child_hexsha), base_inv, file_id,
 
270
                revision_id, parent_invs, lookup_object,
 
271
                (child_base_mode, child_mode), store_updater, lookup_file_id)
269
272
            grandchildmodes = {}
270
273
        child_modes.update(grandchildmodes)
271
274
        invdelta.extend(subinvdelta)
294
297
    diff = []
295
298
    new_objs = {}
296
299
    for path, obj, ie in _tree_to_objects(ret_tree, parent_trees,
297
 
        target_git_object_retriever._cache.idmap, unusual_modes):
 
300
        target_git_object_retriever._cache.idmap, unusual_modes, mapping.BZR_DUMMY_FILE):
298
301
        old_obj_id = tree_lookup_path(lookup_object, o.tree, path)[1]
299
302
        new_objs[path] = obj
300
303
        if obj.id != old_obj_id:
305
308
               sorted(old_obj) == sorted(new_obj)):
306
309
            for name in old_obj:
307
310
                if old_obj[name][0] != new_obj[name][0]:
308
 
                    raise AssertionError("Modes for %s differ: %o != %o" % (path, old_obj[name][0], new_obj[name][0]))
 
311
                    raise AssertionError("Modes for %s differ: %o != %o" %
 
312
                        (path, old_obj[name][0], new_obj[name][0]))
309
313
                if old_obj[name][1] != new_obj[name][1]:
310
314
                    # Found a differing child, delve deeper
311
315
                    path = posixpath.join(path, name)
319
323
def import_git_commit(repo, mapping, head, lookup_object,
320
324
                      target_git_object_retriever, trees_cache):
321
325
    o = lookup_object(head)
322
 
    rev = mapping.import_commit(o)
 
326
    rev = mapping.import_commit(o,
 
327
            lambda x: target_git_object_retriever.lookup_git_sha(x)[1][0])
323
328
    # We have to do this here, since we have to walk the tree and
324
329
    # we need to make sure to import the blobs / trees with the right
325
330
    # path; this may involve adding them more than once.
334
339
        base_mode = stat.S_IFDIR
335
340
    store_updater = target_git_object_retriever._get_updater(rev)
336
341
    store_updater.add_object(o, None)
 
342
    lookup_file_id = mapping.get_fileid_map(lookup_object, o.tree).lookup_file_id
337
343
    inv_delta, unusual_modes = import_git_tree(repo.texts,
338
344
            mapping, "", u"", (base_tree, o.tree), base_inv, 
339
345
            None, rev.revision_id, [p.inventory for p in parent_trees],
340
346
            lookup_object, (base_mode, stat.S_IFDIR), store_updater,
341
 
            mapping.generate_file_id,
 
347
            lookup_file_id,
342
348
            allow_submodules=getattr(repo._format, "supports_tree_reference", False))
343
349
    store_updater.finish()
344
350
    if unusual_modes != {}:
391
397
        except KeyError:
392
398
            continue
393
399
        if isinstance(o, Commit):
394
 
            rev = mapping.import_commit(o)
 
400
            rev = mapping.import_commit(o, lambda x: None)
395
401
            if repo.has_revision(rev.revision_id):
396
402
                continue
397
 
            squash_revision(repo, rev)
398
403
            graph.append((o.id, o.parents))
399
404
            heads.extend([p for p in o.parents if p not in checked])
400
405
        elif isinstance(o, Tag):
423
428
                        pb.update("fetching revisions", offset+i,
424
429
                                  len(revision_ids))
425
430
                    import_git_commit(repo, mapping, head, lookup_object,
426
 
                                      target_git_object_retriever,
427
 
                                      trees_cache)
 
431
                        target_git_object_retriever, trees_cache)
428
432
                    last_imported = head
429
433
            except:
430
434
                repo.abort_write_group()
479
483
            if interesting_heads is None:
480
484
                ret = [sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")]
481
485
            else:
482
 
                ret = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in interesting_heads if revid not in (None, NULL_REVISION)]
483
 
            return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(rev))]
 
486
                ret = [self.source.lookup_bzr_revision_id(revid)[0] for revid in interesting_heads if revid not in (None, NULL_REVISION)]
 
487
            return [rev for rev in ret if not self.target.has_revision(self.source.lookup_foreign_revision_id(rev))]
484
488
        (pack_hint, _) = self.fetch_objects(determine_wants, mapping, pb)
485
489
        if pack_hint is not None and self.target._format.pack_compresses:
486
490
            self.target.pack(hint=pack_hint)
487
 
        if interesting_heads is not None:
488
 
            present_interesting_heads = self.target.has_revisions(interesting_heads)
489
 
            missing_interesting_heads = set(interesting_heads) - present_interesting_heads
490
 
            if missing_interesting_heads:
491
 
                raise AssertionError("Missing interesting heads: %r" % missing_interesting_heads)
492
491
        return self._refs
493
492
 
494
493
 
535
534
            if pb is None:
536
535
                create_pb = pb = ui.ui_factory.nested_progress_bar()
537
536
            try:
538
 
                objects_iter = self.source.fetch_objects(
539
 
                            record_determine_wants, graph_walker,
540
 
                            store.get_raw, progress)
 
537
                objects_iter = self.source.fetch_objects(record_determine_wants,
 
538
                    graph_walker, store.get_raw, progress)
541
539
                return import_git_objects(self.target, mapping,
542
540
                    objects_iter, store, recorded_wants, pb, limit)
543
541
            finally: