/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

Require dulwich 0.7.1.

Show diffs side-by-side

added added

removed removed

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