/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

Add check-all target.

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,
482
484
 
483
485
    _matching_repo_format = GitRepositoryFormat()
484
486
 
 
487
    def _target_has_shas(self, shas):
 
488
        raise NotImplementedError(self._target_has_shas)
 
489
 
 
490
    def get_determine_wants_heads(self, wants, include_tags=False):
 
491
        wants = set(wants)
 
492
        def determine_wants(refs):
 
493
            potential = set(wants)
 
494
            if include_tags:
 
495
                potential.update([v[1] or v[0] for v in extract_tags(refs).itervalues()])
 
496
            return list(potential - self._target_has_shas(potential))
 
497
        return determine_wants
 
498
 
 
499
    def determine_wants_all(self, refs):
 
500
        potential = set([sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")])
 
501
        return list(potential - self._target_has_shas(potential))
 
502
 
485
503
    @staticmethod
486
504
    def _get_repo_format_to_test():
487
505
        return None
495
513
    """Base InterRepository that copies revisions from a Git into a non-Git
496
514
    repository."""
497
515
 
 
516
    def _target_has_shas(self, shas):
 
517
        revids = [self.source.lookup_foreign_revision_id(sha) for sha in shas]
 
518
        return self.target.has_revisions(revids)
 
519
 
 
520
    def get_determine_wants_revids(self, revids, include_tags=False):
 
521
        wants = set()
 
522
        for revid in set(revids):
 
523
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
 
524
            wants.add(git_sha)
 
525
        return self.get_determine_wants_heads(wants, include_tags=include_tags)
 
526
 
498
527
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
499
528
        """Fetch objects from a remote server.
500
529
 
513
542
        if revision_id is not None:
514
543
            interesting_heads = [revision_id]
515
544
        elif fetch_spec is not None:
516
 
            interesting_heads = fetch_spec.heads
 
545
            recipe = fetch_spec.get_recipe()
 
546
            if recipe[0] in ("search", "proxy-search"):
 
547
                interesting_heads = recipe[1]
 
548
            else:
 
549
                raise AssertionError("Unsupported search result type %s" % recipe[0])
517
550
        else:
518
551
            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)
 
552
 
 
553
        if interesting_heads is not None:
 
554
            determine_wants = self.get_determine_wants_revids(interesting_heads,
 
555
                include_tags=False)
 
556
        else:
 
557
            determine_wants = self.determine_wants_all
 
558
 
 
559
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
 
560
            mapping, pb)
526
561
        if pack_hint is not None and self.target._format.pack_compresses:
527
562
            self.target.pack(hint=pack_hint)
528
563
        return remote_refs
583
618
                objects_iter = self.source.fetch_objects(
584
619
                    wants_recorder, graph_walker, store.get_raw,
585
620
                    progress)
 
621
                trace.mutter("Importing %d new revisions", len(wants_recorder.wants))
586
622
                (pack_hint, last_rev) = import_git_objects(self.target, mapping,
587
623
                    objects_iter, store, wants_recorder.wants, pb, limit)
588
624
                return (pack_hint, last_rev, wants_recorder.remote_refs)
664
700
        else:
665
701
            raise AssertionError
666
702
 
 
703
    def _target_has_shas(self, shas):
 
704
        return set([sha for sha in shas if self.target._git.object_store])
 
705
 
667
706
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
668
707
              mapping=None, fetch_spec=None, branches=None):
669
708
        if mapping is None:
672
711
        if revision_id is not None:
673
712
            args = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
674
713
        elif fetch_spec is not None:
675
 
            args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in fetch_spec.heads]
 
714
            recipe = fetch_spec.get_recipe()
 
715
            if recipe[0] in ("search", "proxy-search"):
 
716
                heads = recipe[1]
 
717
            else:
 
718
                raise AssertionError("Unsupported search result type %s" % recipe[0])
 
719
            args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in heads]
676
720
        if branches is not None:
677
721
            determine_wants = lambda x: [x[y] for y in branches if not x[y] in r.object_store]
678
722
        elif fetch_spec is None and revision_id is None:
679
 
            determine_wants = r.object_store.determine_wants_all
 
723
            determine_wants = self.determine_wants_all
680
724
        else:
681
725
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
682
726
        self.fetch_objects(determine_wants, mapping)