~jelmer/brz-hg/trunk

« back to all changes in this revision

Viewing changes to branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 18:14:17 UTC
  • Revision ID: jelmer@samba.org-20110921181417-bof2ikbx7chdi30m
Add ToHgRepository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
399
399
    def _get_branch_formats_to_test():
400
400
        return [(HgBranchFormat(), HgBranchFormat())]
401
401
 
402
 
    @staticmethod
403
 
    def is_compatible(source, target):
 
402
    @classmethod
 
403
    def is_compatible(cls, source, target):
404
404
        """See InterBranch.is_compatible()."""
405
405
        return (isinstance(source, HgBranch) and isinstance(target, HgBranch))
406
406
 
565
565
        return self._lookup_revno(self.new_revid)
566
566
 
567
567
 
 
568
class InterHgBranch(InterBranch):
 
569
 
 
570
    @staticmethod
 
571
    def _get_branch_formats_to_test():
 
572
        return [(HgBranchFormat(), HgBranchFormat())]
 
573
 
 
574
    @classmethod
 
575
    def is_compatible(self, source, target):
 
576
        return (isinstance(source, HgBranch) and
 
577
                isinstance(target, HgBranch))
 
578
 
 
579
 
568
580
class InterToHgBranch(InterBranch):
569
581
    """InterBranch implementation that pushes into Hg."""
570
582
 
580
592
 
581
593
    def _push_helper(self, stop_revision=None, overwrite=False,
582
594
            lossy=False):
583
 
        graph = self.source.repository.get_graph()
 
595
        interrepo = InterRepository(self.source.repository, self.target.repository)
584
596
        if stop_revision is None:
585
597
            stop_revision = self.source.last_revision()
586
 
        revs = graph.find_difference(self.target.last_revision(),
587
 
                                     stop_revision)[1]
588
 
        cg, revidmap = dchangegroup(self.source.repository,
589
 
                                    self.target.mapping, revs, lossy=lossy)
 
598
        cg, revidmap = interrepo._generate_changegroup(stop_revision, self.target.mapping, lossy=lossy)
590
599
        heads = [revidmap[stop_revision]]
591
600
        remote = self.target.repository._hgrepo
592
601
        if remote.capable('unbundle'):
593
602
            remote.unbundle(cg, heads, None)
594
603
        else:
 
604
            # TODO: Set heads
595
605
            remote.addchangegroup(cg, 'push', self.source.base)
596
 
            # TODO: Set heads
597
 
        if lossy:
598
 
            return dict((k, self.target.mapping.revision_id_foreign_to_bzr(v)) for (k, v) in revidmap.iteritems())
 
606
        return dict((k, self.target.mapping.revision_id_foreign_to_bzr(v)) for (k, v) in revidmap.iteritems())
599
607
 
600
608
    @needs_read_lock
601
609
    def push(self, overwrite=True, stop_revision=None,
630
638
 
631
639
InterBranch.register_optimiser(InterFromHgBranch)
632
640
InterBranch.register_optimiser(InterToHgBranch)
 
641
InterBranch.register_optimiser(InterHgBranch)