/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

Fix fetching between git repositories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
from bzrlib import (
37
37
    debug,
 
38
    errors,
38
39
    osutils,
39
40
    trace,
40
41
    ui,
764
765
class InterGitGitRepository(InterFromGitRepository):
765
766
    """InterRepository that copies between Git repositories."""
766
767
 
767
 
    def fetch_objects(self, determine_wants, mapping, pb=None):
 
768
    def fetch_refs(self, update_refs, lossy=False):
 
769
        if lossy:
 
770
            raise errors.LossyPushToSameVCS(self.source, self.target)
 
771
        old_refs = self.target._git.get_refs()
 
772
        ref_changes = {}
 
773
        def determine_wants(heads):
 
774
            old_refs = dict([(k, (v, None)) for (k, v) in heads.iteritems()])
 
775
            new_refs = update_refs(old_refs)
 
776
            ref_changes.update(new_refs)
 
777
            return [sha1 for (sha1, bzr_revid) in new_refs.itervalues()]
 
778
        self.fetch_objects(determine_wants)
 
779
        for k, (git_sha, bzr_revid) in ref_changes.iteritems():
 
780
            self.target._git.refs[k] = git_sha
 
781
        new_refs = self.target._git.get_refs()
 
782
        return None, old_refs, new_refs
 
783
 
 
784
    def fetch_objects(self, determine_wants, mapping=None, pb=None):
768
785
        def progress(text):
769
786
            trace.note("git: %s", text)
770
787
        graphwalker = self.target._git.get_graph_walker()
778
795
            raise NotImplementedError
779
796
        elif (isinstance(self.source, RemoteGitRepository) and
780
797
              isinstance(self.target, LocalGitRepository)):
781
 
            f, commit = self.target._git.object_store.add_thin_pack()
 
798
            f, commit = self.target._git.object_store.add_pack()
782
799
            try:
783
 
                refs = self.source.bzrdir.root_transport.fetch_pack(
 
800
                refs = self.source.bzrdir.fetch_pack(
784
801
                    determine_wants, graphwalker, f.write, progress)
785
802
                commit()
786
803
                return (None, None, refs)
788
805
                f.close()
789
806
                raise
790
807
        else:
791
 
            raise AssertionError
 
808
            raise AssertionError("fetching between %r and %r not supported" %
 
809
                    (self.source, self.target))
792
810
 
793
811
    def _target_has_shas(self, shas):
794
812
        return set([sha for sha in shas if self.target._git.object_store])