/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

Add some basic documentation in 'bzr help git'.

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
117
            self.branch.mapping.revision_id_bzr_to_foreign(revid)
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
 
257
260
 
259
262
    """A local Git branch."""
260
263
 
261
264
    def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
262
 
        super(LocalGitBranch, self).__init__(bzrdir, repository, name, 
 
265
        super(LocalGitBranch, self).__init__(bzrdir, repository, name,
263
266
              lockfiles, tagsdict)
264
267
        refs = repository._git.get_refs()
265
268
        if not (name in refs.keys() or "HEAD" in refs.keys()):
279
282
            return tree
280
283
        else:
281
284
            return self._create_heavyweight_checkout(to_location, revision_id,
282
 
            hardlink)
 
285
                hardlink)
283
286
 
284
287
    def _create_heavyweight_checkout(self, to_location, revision_id=None,
285
288
                                     hardlink=False):
342
345
 
343
346
    def supports_tags(self):
344
347
        return True
345
 
    
 
348
 
346
349
 
347
350
class GitBranchPullResult(branch.PullResult):
348
351
 
389
392
 
390
393
    def _set_new_revno(self, revno):
391
394
        self._new_revno = revno
392
 
    
 
395
 
393
396
    new_revno = property(_get_new_revno, _set_new_revno)
394
397
 
395
398
 
416
419
class InterFromGitBranch(branch.GenericInterBranch):
417
420
    """InterBranch implementation that pulls from Git into bzr."""
418
421
 
 
422
    @staticmethod
 
423
    def _get_branch_formats_to_test():
 
424
        return []
 
425
 
419
426
    @classmethod
420
427
    def _get_interrepo(self, source, target):
421
428
        return repository.InterRepository.get(source.repository,
452
459
            if self.target.repository.has_revision(self._last_revid):
453
460
                return []
454
461
            return [head]
455
 
        pack_hint, head = interrepo.fetch_objects(
 
462
        pack_hint, head, refs = interrepo.fetch_objects(
456
463
            determine_wants, self.source.mapping, limit=limit)
457
464
        if (pack_hint is not None and
458
465
            self.target.repository._format.pack_compresses):
543
550
class InterGitLocalRemoteBranch(InterGitBranch):
544
551
    """InterBranch that copies from a local to a remote git branch."""
545
552
 
 
553
    @staticmethod
 
554
    def _get_branch_formats_to_test():
 
555
        return []
 
556
 
546
557
    @classmethod
547
558
    def is_compatible(self, source, target):
548
559
        from bzrlib.plugins.git.remote import RemoteGitBranch
572
583
class InterGitRemoteLocalBranch(InterGitBranch):
573
584
    """InterBranch that copies from a remote to a local git branch."""
574
585
 
 
586
    @staticmethod
 
587
    def _get_branch_formats_to_test():
 
588
        return []
 
589
 
575
590
    @classmethod
576
591
    def is_compatible(self, source, target):
577
592
        from bzrlib.plugins.git.remote import RemoteGitBranch
598
613
        interrepo = repository.InterRepository.get(self.source.repository,
599
614
            self.target.repository)
600
615
        if stop_revision is None:
601
 
            refs = interrepo.fetch_refs(branches=["HEAD"])
 
616
            refs = interrepo.fetch(branches=["HEAD"])
602
617
            stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
603
618
        else:
604
 
            refs = interrepo.fetch_refs(revision_id=stop_revision)
 
619
            refs = interrepo.fetch(revision_id=stop_revision)
605
620
        return refs, stop_revision
606
621
 
607
622
    def pull(self, stop_revision=None, overwrite=False,
620
635
        return result
621
636
 
622
637
 
623
 
class InterToGitBranch(branch.InterBranch):
 
638
class InterToGitBranch(branch.GenericInterBranch):
624
639
    """InterBranch implementation that pulls from Git into bzr."""
625
640
 
626
641
    def __init__(self, source, target):
630
645
 
631
646
    @staticmethod
632
647
    def _get_branch_formats_to_test():
633
 
        return None, None
 
648
        return []
634
649
 
635
650
    @classmethod
636
651
    def is_compatible(self, source, target):
643
658
    def _get_new_refs(self, stop_revision=None):
644
659
        if stop_revision is None:
645
660
            stop_revision = self.source.last_revision()
 
661
        assert type(stop_revision) is str
646
662
        main_ref = self.target.ref or "refs/heads/master"
647
 
        refs = { main_ref: stop_revision }
 
663
        refs = { main_ref: (None, stop_revision) }
648
664
        for name, revid in self.source.tags.get_tag_dict().iteritems():
649
665
            if self.source.repository.has_revision(revid):
650
 
                refs[tag_name_to_ref(name)] = revid
 
666
                refs[tag_name_to_ref(name)] = (None, revid)
651
667
        return refs, main_ref
652
668
 
653
669
    def pull(self, overwrite=False, stop_revision=None, local=False,
656
672
        result = GitBranchPullResult()
657
673
        result.source_branch = self.source
658
674
        result.target_branch = self.target
659
 
        # FIXME: Check for diverged branches
660
 
        old_refs = self.target.repository._git.get_refs()
661
 
        refs = dict(old_refs)
662
675
        new_refs, main_ref = self._get_new_refs(stop_revision)
663
 
        refs.update(new_refs)
664
 
        self.interrepo.fetch_refs(refs)
 
676
        def update_refs(old_refs):
 
677
            refs = dict(old_refs)
 
678
            # FIXME: Check for diverged branches
 
679
            refs.update(new_refs)
 
680
            return refs
 
681
        old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
665
682
        result.old_revid = self.target.lookup_foreign_revision_id(
666
683
            old_refs.get(main_ref, ZERO_SHA))
667
 
        result.new_revid = refs[main_ref]
 
684
        result.new_revid = new_refs[main_ref]
668
685
        return result
669
686
 
670
687
    def push(self, overwrite=False, stop_revision=None,
673
690
        result = GitBranchPushResult()
674
691
        result.source_branch = self.source
675
692
        result.target_branch = self.target
676
 
        # FIXME: Check for diverged branches
677
 
        old_refs = self.target.repository._git.get_refs()
678
 
        refs = dict(old_refs)
679
693
        new_refs, main_ref = self._get_new_refs(stop_revision)
680
 
        refs.update(new_refs)
681
 
        self.interrepo.fetch_refs(refs)
 
694
        def update_refs(old_refs):
 
695
            refs = dict(old_refs)
 
696
            # FIXME: Check for diverged branches
 
697
            refs.update(new_refs)
 
698
            return refs
 
699
        old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
682
700
        result.old_revid = self.target.lookup_foreign_revision_id(
683
701
            old_refs.get(main_ref, ZERO_SHA))
684
 
        result.new_revid = refs[main_ref]
 
702
        result.new_revid = new_refs[main_ref]
685
703
        return result
686
704
 
687
705
    def lossy_push(self, stop_revision=None):
688
 
        from dulwich.protocol import ZERO_SHA
689
706
        result = GitBranchPushResult()
690
707
        result.source_branch = self.source
691
708
        result.target_branch = self.target
692
 
        # FIXME: Check for diverged branches
693
 
        refs, main_ref = self._get_new_refs(stop_revision)
694
 
        result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(refs)
695
 
        result.old_revid = self.target.lookup_foreign_revision_id(
696
 
            old_refs.get(self.target.ref, ZERO_SHA))
697
 
        result.new_revid = self.target.lookup_foreign_revision_id(
698
 
            new_refs[main_ref])
 
709
        new_refs, main_ref = self._get_new_refs(stop_revision)
 
710
        def update_refs(old_refs):
 
711
            refs = dict(old_refs)
 
712
            # FIXME: Check for diverged branches
 
713
            refs.update(new_refs)
 
714
            return refs
 
715
        result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
 
716
            update_refs)
 
717
        result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
 
718
        result.new_revid = new_refs[main_ref][1]
699
719
        return result
700
720
 
701
721