/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

Remove explicit use of rich root formats.

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