/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 branch.py

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.decorators import (
36
36
    needs_read_lock,
37
37
    )
 
38
from bzrlib.revision import (
 
39
    NULL_REVISION,
 
40
    )
38
41
from bzrlib.trace import (
39
42
    is_quiet,
40
43
    mutter,
48
51
    NoSuchRef,
49
52
    )
50
53
from bzrlib.plugins.git.refs import (
51
 
    branch_name_to_ref,
52
54
    ref_to_branch_name,
53
55
    extract_tags,
54
56
    tag_name_to_ref,
58
60
 
59
61
 
60
62
class GitPullResult(branch.PullResult):
 
63
    """Result of a pull from a Git branch."""
61
64
 
62
65
    def _lookup_revno(self, revid):
63
66
        assert isinstance(revid, str), "was %r" % revid
108
111
        for name in extra:
109
112
            if name.startswith("refs/tags/"):
110
113
                del self.repository._git[name]
111
 
        
 
114
 
112
115
    def set_tag(self, name, revid):
113
116
        self.repository._git.refs[tag_name_to_ref(name)], _ = \
114
 
            self.branch.mapping.revision_id_bzr_to_foreign(revid)
 
117
            self.branch.lookup_bzr_revision_id(revid)
115
118
 
116
119
 
117
120
class DictTagDict(LocalGitTagDict):
251
254
            overwrite, stop_revision)
252
255
 
253
256
    def lookup_foreign_revision_id(self, foreign_revid):
254
 
        return self.repository.lookup_foreign_revision_id(foreign_revid, 
 
257
        return self.repository.lookup_foreign_revision_id(foreign_revid,
255
258
            self.mapping)
256
259
 
 
260
    def lookup_bzr_revision_id(self, revid):
 
261
        return self.repository.lookup_bzr_revision_id(
 
262
            revid, mapping=self.mapping)
 
263
 
257
264
 
258
265
class LocalGitBranch(GitBranch):
259
266
    """A local Git branch."""
260
267
 
261
268
    def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
262
 
        super(LocalGitBranch, self).__init__(bzrdir, repository, name, 
 
269
        super(LocalGitBranch, self).__init__(bzrdir, repository, name,
263
270
              lockfiles, tagsdict)
264
271
        refs = repository._git.get_refs()
265
272
        if not (name in refs.keys() or "HEAD" in refs.keys()):
279
286
            return tree
280
287
        else:
281
288
            return self._create_heavyweight_checkout(to_location, revision_id,
282
 
            hardlink)
 
289
                hardlink)
283
290
 
284
291
    def _create_heavyweight_checkout(self, to_location, revision_id=None,
285
292
                                     hardlink=False):
342
349
 
343
350
    def supports_tags(self):
344
351
        return True
345
 
    
 
352
 
346
353
 
347
354
class GitBranchPullResult(branch.PullResult):
348
355
 
389
396
 
390
397
    def _set_new_revno(self, revno):
391
398
        self._new_revno = revno
392
 
    
 
399
 
393
400
    new_revno = property(_get_new_revno, _set_new_revno)
394
401
 
395
402
 
416
423
class InterFromGitBranch(branch.GenericInterBranch):
417
424
    """InterBranch implementation that pulls from Git into bzr."""
418
425
 
 
426
    @staticmethod
 
427
    def _get_branch_formats_to_test():
 
428
        return []
 
429
 
419
430
    @classmethod
420
431
    def _get_interrepo(self, source, target):
421
432
        return repository.InterRepository.get(source.repository,
452
463
            if self.target.repository.has_revision(self._last_revid):
453
464
                return []
454
465
            return [head]
455
 
        pack_hint, head = interrepo.fetch_objects(
 
466
        pack_hint, head, refs = interrepo.fetch_objects(
456
467
            determine_wants, self.source.mapping, limit=limit)
457
468
        if (pack_hint is not None and
458
469
            self.target.repository._format.pack_compresses):
543
554
class InterGitLocalRemoteBranch(InterGitBranch):
544
555
    """InterBranch that copies from a local to a remote git branch."""
545
556
 
 
557
    @staticmethod
 
558
    def _get_branch_formats_to_test():
 
559
        return []
 
560
 
546
561
    @classmethod
547
562
    def is_compatible(self, source, target):
548
563
        from bzrlib.plugins.git.remote import RemoteGitBranch
572
587
class InterGitRemoteLocalBranch(InterGitBranch):
573
588
    """InterBranch that copies from a remote to a local git branch."""
574
589
 
 
590
    @staticmethod
 
591
    def _get_branch_formats_to_test():
 
592
        return []
 
593
 
575
594
    @classmethod
576
595
    def is_compatible(self, source, target):
577
596
        from bzrlib.plugins.git.remote import RemoteGitBranch
620
639
        return result
621
640
 
622
641
 
623
 
class InterToGitBranch(branch.InterBranch):
 
642
class InterToGitBranch(branch.GenericInterBranch):
624
643
    """InterBranch implementation that pulls from Git into bzr."""
625
644
 
626
645
    def __init__(self, source, target):
630
649
 
631
650
    @staticmethod
632
651
    def _get_branch_formats_to_test():
633
 
        return None, None
 
652
        return []
634
653
 
635
654
    @classmethod
636
655
    def is_compatible(self, source, target):
643
662
    def _get_new_refs(self, stop_revision=None):
644
663
        if stop_revision is None:
645
664
            stop_revision = self.source.last_revision()
 
665
        assert type(stop_revision) is str
646
666
        main_ref = self.target.ref or "refs/heads/master"
647
 
        refs = { main_ref: stop_revision }
 
667
        refs = { main_ref: (None, stop_revision) }
648
668
        for name, revid in self.source.tags.get_tag_dict().iteritems():
649
669
            if self.source.repository.has_revision(revid):
650
 
                refs[tag_name_to_ref(name)] = revid
 
670
                refs[tag_name_to_ref(name)] = (None, revid)
651
671
        return refs, main_ref
652
672
 
653
673
    def pull(self, overwrite=False, stop_revision=None, local=False,
681
701
            refs.update(new_refs)
682
702
            return refs
683
703
        old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
684
 
        result.old_revid = self.target.lookup_foreign_revision_id(
685
 
            old_refs.get(main_ref, ZERO_SHA))
 
704
        (result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
 
705
        if result.old_revid is None:
 
706
            result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
686
707
        result.new_revid = new_refs[main_ref]
687
708
        return result
688
709
 
689
710
    def lossy_push(self, stop_revision=None):
690
 
        from dulwich.protocol import ZERO_SHA
691
711
        result = GitBranchPushResult()
692
712
        result.source_branch = self.source
693
713
        result.target_branch = self.target
699
719
            return refs
700
720
        result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
701
721
            update_refs)
702
 
        result.old_revid = self.target.lookup_foreign_revision_id(
703
 
            old_refs.get(self.target.ref, ZERO_SHA))
704
 
        result.new_revid = self.target.lookup_foreign_revision_id(
705
 
            new_refs[main_ref])
 
722
        result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
 
723
        result.new_revid = new_refs[main_ref][1]
706
724
        return result
707
725
 
708
726