/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

More work on roundtrip push support.

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
81
80
from bzrlib.plugins.git.remote import (
82
81
    RemoteGitRepository,
83
82
    )
261
260
    # Remember for next time
262
261
    existing_children = set()
263
262
    child_modes = {}
264
 
    for name, child_mode, child_hexsha in tree.iteritems():
 
263
    for child_mode, name, child_hexsha in tree.entries():
265
264
        existing_children.add(name)
266
265
        child_path = posixpath.join(path, name)
267
266
        if type(base_tree) is Tree:
276
275
        if stat.S_ISDIR(child_mode):
277
276
            subinvdelta, grandchildmodes = import_git_tree(texts, mapping,
278
277
                child_path, name, (child_base_hexsha, child_hexsha), base_inv,
279
 
                file_id, revision_id, parent_invs, lookup_object,
 
278
                file_id, revision_id, parent_invs, lookup_object, 
280
279
                (child_base_mode, child_mode), store_updater, lookup_file_id,
281
280
                allow_submodules=allow_submodules)
282
281
        elif S_ISGITLINK(child_mode): # submodule
306
305
 
307
306
 
308
307
def verify_commit_reconstruction(target_git_object_retriever, lookup_object,
309
 
    o, rev, ret_tree, parent_trees, mapping, unusual_modes, verifiers):
 
308
    o, rev, ret_tree, parent_trees, mapping, unusual_modes):
310
309
    new_unusual_modes = mapping.export_unusual_file_modes(rev)
311
310
    if new_unusual_modes != unusual_modes:
312
311
        raise AssertionError("unusual modes don't match: %r != %r" % (
313
312
            unusual_modes, new_unusual_modes))
314
313
    # Verify that we can reconstruct the commit properly
315
 
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True,
316
 
        verifiers)
 
314
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True)
317
315
    if rec_o != o:
318
316
        raise AssertionError("Reconstructed commit differs: %r != %r" % (
319
317
            rec_o, o))
379
377
        base_inv = None
380
378
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
381
379
              inv_delta, rev.revision_id, rev.parent_ids, base_inv)
382
 
    # Check verifiers
 
380
    # FIXME: Check verifiers
383
381
    testament = StrictTestament3(rev, inv)
384
382
    calculated_verifiers = { "testament3-sha1": testament.as_sha1() }
385
383
    if roundtrip_revid is not None:
398
396
    if "verify" in debug.debug_flags:
399
397
        verify_commit_reconstruction(target_git_object_retriever, 
400
398
            lookup_object, o, rev, ret_tree, parent_trees, mapping,
401
 
            unusual_modes, verifiers)
 
399
            unusual_modes)
402
400
 
403
401
 
404
402
def import_git_objects(repo, mapping, object_iter,
484
482
 
485
483
    _matching_repo_format = GitRepositoryFormat()
486
484
 
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
 
 
503
485
    @staticmethod
504
486
    def _get_repo_format_to_test():
505
487
        return None
513
495
    """Base InterRepository that copies revisions from a Git into a non-Git
514
496
    repository."""
515
497
 
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
 
 
527
498
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
528
499
        """Fetch objects from a remote server.
529
500
 
542
513
        if revision_id is not None:
543
514
            interesting_heads = [revision_id]
544
515
        elif fetch_spec is not None:
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])
 
516
            interesting_heads = fetch_spec.heads
550
517
        else:
551
518
            interesting_heads = None
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)
 
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)
561
526
        if pack_hint is not None and self.target._format.pack_compresses:
562
527
            self.target.pack(hint=pack_hint)
563
528
        return remote_refs
618
583
                objects_iter = self.source.fetch_objects(
619
584
                    wants_recorder, graph_walker, store.get_raw,
620
585
                    progress)
621
 
                trace.mutter("Importing %d new revisions", len(wants_recorder.wants))
622
586
                (pack_hint, last_rev) = import_git_objects(self.target, mapping,
623
587
                    objects_iter, store, wants_recorder.wants, pb, limit)
624
588
                return (pack_hint, last_rev, wants_recorder.remote_refs)
700
664
        else:
701
665
            raise AssertionError
702
666
 
703
 
    def _target_has_shas(self, shas):
704
 
        return set([sha for sha in shas if self.target._git.object_store])
705
 
 
706
667
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
707
668
              mapping=None, fetch_spec=None, branches=None):
708
669
        if mapping is None:
711
672
        if revision_id is not None:
712
673
            args = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
713
674
        elif fetch_spec is not None:
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]
 
675
            args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in fetch_spec.heads]
720
676
        if branches is not None:
721
677
            determine_wants = lambda x: [x[y] for y in branches if not x[y] in r.object_store]
722
678
        elif fetch_spec is None and revision_id is None:
723
 
            determine_wants = self.determine_wants_all
 
679
            determine_wants = r.object_store.determine_wants_all
724
680
        else:
725
681
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
726
682
        self.fetch_objects(determine_wants, mapping)