/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

Import ZERO_SHA from dulwich.objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    LRUTreeCache,
78
78
    _tree_to_objects,
79
79
    )
 
80
from bzrlib.plugins.git.refs import extract_tags
80
81
from bzrlib.plugins.git.remote import (
81
82
    RemoteGitRepository,
82
83
    )
260
261
    # Remember for next time
261
262
    existing_children = set()
262
263
    child_modes = {}
263
 
    for child_mode, name, child_hexsha in tree.entries():
 
264
    for name, child_mode, child_hexsha in tree.iteritems():
264
265
        existing_children.add(name)
265
266
        child_path = posixpath.join(path, name)
266
267
        if type(base_tree) is Tree:
275
276
        if stat.S_ISDIR(child_mode):
276
277
            subinvdelta, grandchildmodes = import_git_tree(texts, mapping,
277
278
                child_path, name, (child_base_hexsha, child_hexsha), base_inv,
278
 
                file_id, revision_id, parent_invs, lookup_object, 
 
279
                file_id, revision_id, parent_invs, lookup_object,
279
280
                (child_base_mode, child_mode), store_updater, lookup_file_id,
280
281
                allow_submodules=allow_submodules)
281
282
        elif S_ISGITLINK(child_mode): # submodule
305
306
 
306
307
 
307
308
def verify_commit_reconstruction(target_git_object_retriever, lookup_object,
308
 
    o, rev, ret_tree, parent_trees, mapping, unusual_modes):
 
309
    o, rev, ret_tree, parent_trees, mapping, unusual_modes, verifiers):
309
310
    new_unusual_modes = mapping.export_unusual_file_modes(rev)
310
311
    if new_unusual_modes != unusual_modes:
311
312
        raise AssertionError("unusual modes don't match: %r != %r" % (
312
313
            unusual_modes, new_unusual_modes))
313
314
    # Verify that we can reconstruct the commit properly
314
 
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True)
 
315
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True,
 
316
        verifiers)
315
317
    if rec_o != o:
316
318
        raise AssertionError("Reconstructed commit differs: %r != %r" % (
317
319
            rec_o, o))
377
379
        base_inv = None
378
380
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
379
381
              inv_delta, rev.revision_id, rev.parent_ids, base_inv)
380
 
    # FIXME: Check verifiers
 
382
    # Check verifiers
381
383
    testament = StrictTestament3(rev, inv)
382
384
    calculated_verifiers = { "testament3-sha1": testament.as_sha1() }
383
385
    if roundtrip_revid is not None:
396
398
    if "verify" in debug.debug_flags:
397
399
        verify_commit_reconstruction(target_git_object_retriever, 
398
400
            lookup_object, o, rev, ret_tree, parent_trees, mapping,
399
 
            unusual_modes)
 
401
            unusual_modes, verifiers)
400
402
 
401
403
 
402
404
def import_git_objects(repo, mapping, object_iter,
495
497
    """Base InterRepository that copies revisions from a Git into a non-Git
496
498
    repository."""
497
499
 
 
500
    def _target_has_shas(self, shas):
 
501
        revids = [self.source.lookup_foreign_revision_id(sha) for sha in shas]
 
502
        return self.target.has_revisions(revids)
 
503
 
 
504
    def get_determine_wants_heads(self, wants, include_tags=False):
 
505
        wants = set(wants)
 
506
        def determine_wants(refs):
 
507
            potential = set(wants)
 
508
            if include_tags:
 
509
                potential.update([v[0] for v in extract_tags(refs).itervalues()])
 
510
            return list(potential - self._target_has_shas(potential))
 
511
        return determine_wants
 
512
 
 
513
    def get_determine_wants_revids(self, revids, include_tags=False):
 
514
        wants = set()
 
515
        for revid in set(revids):
 
516
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
 
517
            wants.add(git_sha)
 
518
        return self.get_determine_wants_heads(wants, include_tags=include_tags)
 
519
 
 
520
    def determine_wants_all(self, refs):
 
521
        potential = set([sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")])
 
522
        return list(potential - self._target_has_shas(potential))
 
523
 
498
524
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
499
525
        """Fetch objects from a remote server.
500
526
 
513
539
        if revision_id is not None:
514
540
            interesting_heads = [revision_id]
515
541
        elif fetch_spec is not None:
516
 
            interesting_heads = fetch_spec.heads
 
542
            recipe = fetch_spec.get_recipe()
 
543
            if recipe[0] in ("search", "proxy-search"):
 
544
                interesting_heads = recipe[1]
 
545
            else:
 
546
                raise AssertionError("Unsupported search result type %s" % recipe[0])
517
547
        else:
518
548
            interesting_heads = None
519
 
        def determine_wants(refs):
520
 
            if interesting_heads is None:
521
 
                ret = [sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")]
522
 
            else:
523
 
                ret = [self.source.lookup_bzr_revision_id(revid)[0] for revid in interesting_heads if revid not in (None, NULL_REVISION)]
524
 
            return [rev for rev in ret if not self.target.has_revision(self.source.lookup_foreign_revision_id(rev))]
525
 
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants, mapping, pb)
 
549
 
 
550
        if interesting_heads is not None:
 
551
            determine_wants = self.get_determine_wants_revids(interesting_heads,
 
552
                include_tags=False)
 
553
        else:
 
554
            determine_wants = self.determine_wants_all
 
555
 
 
556
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
 
557
            mapping, pb)
526
558
        if pack_hint is not None and self.target._format.pack_compresses:
527
559
            self.target.pack(hint=pack_hint)
528
560
        return remote_refs
583
615
                objects_iter = self.source.fetch_objects(
584
616
                    wants_recorder, graph_walker, store.get_raw,
585
617
                    progress)
 
618
                trace.mutter("Importing %d new revisions", len(wants_recorder.wants))
586
619
                (pack_hint, last_rev) = import_git_objects(self.target, mapping,
587
620
                    objects_iter, store, wants_recorder.wants, pb, limit)
588
621
                return (pack_hint, last_rev, wants_recorder.remote_refs)
672
705
        if revision_id is not None:
673
706
            args = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
674
707
        elif fetch_spec is not None:
675
 
            args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in fetch_spec.heads]
 
708
            recipe = fetch_spec.get_recipe()
 
709
            if recipe[0] in ("search", "proxy-search"):
 
710
                heads = recipe[1]
 
711
            else:
 
712
                raise AssertionError("Unsupported search result type %s" % recipe[0])
 
713
            args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in heads]
676
714
        if branches is not None:
677
715
            determine_wants = lambda x: [x[y] for y in branches if not x[y] in r.object_store]
678
716
        elif fetch_spec is None and revision_id is None: