~bzr/ubuntu/maverick/bzr-git/bzr-ppa

« back to all changes in this revision

Viewing changes to branch.py

  • Committer: Jelmer Vernooij
  • Date: 2010-11-06 22:47:45 UTC
  • mfrom: (17.25.368 upstream)
  • Revision ID: jelmer@debian.org-20101106224745-ephery62e224bjup
* New upstream snapshot.
* Run testsuite as part of build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
        return True
352
352
 
353
353
 
 
354
def _quick_lookup_revno(local_branch, remote_branch, revid):
 
355
    assert isinstance(revid, str), "was %r" % revid
 
356
    # Try in source branch first, it'll be faster
 
357
    try:
 
358
        return local_branch.revision_id_to_revno(revid)
 
359
    except errors.NoSuchRevision:
 
360
        graph = local_branch.repository.get_graph()
 
361
        try:
 
362
            return graph.find_distance_to_null(revid)
 
363
        except errors.GhostRevisionsHaveNoRevno:
 
364
            # FIXME: Check using graph.find_distance_to_null() ?
 
365
            return remote_branch.revision_id_to_revno(revid)
 
366
 
 
367
 
354
368
class GitBranchPullResult(branch.PullResult):
355
369
 
356
370
    def __init__(self):
371
385
        self._show_tag_conficts(to_file)
372
386
 
373
387
    def _lookup_revno(self, revid):
374
 
        assert isinstance(revid, str), "was %r" % revid
375
 
        # Try in source branch first, it'll be faster
376
 
        try:
377
 
            return self.source_branch.revision_id_to_revno(revid)
378
 
        except errors.NoSuchRevision:
379
 
            # FIXME: Check using graph.find_distance_to_null() ?
380
 
            return self.target_branch.revision_id_to_revno(revid)
 
388
        return _quick_lookup_revno(self.target_branch, self.source_branch, revid)
381
389
 
382
390
    def _get_old_revno(self):
383
391
        if self._old_revno is not None:
403
411
class GitBranchPushResult(branch.BranchPushResult):
404
412
 
405
413
    def _lookup_revno(self, revid):
406
 
        assert isinstance(revid, str), "was %r" % revid
407
 
        # Try in source branch first, it'll be faster
408
 
        try:
409
 
            return self.source_branch.revision_id_to_revno(revid)
410
 
        except errors.NoSuchRevision:
411
 
            # FIXME: Check using graph.find_distance_to_null() ?
412
 
            return self.target_branch.revision_id_to_revno(revid)
 
414
        return _quick_lookup_revno(self.source_branch, self.target_branch, revid)
413
415
 
414
416
    @property
415
417
    def old_revno(self):
417
419
 
418
420
    @property
419
421
    def new_revno(self):
 
422
        new_original_revno = getattr(self, "new_original_revno", None)
 
423
        if new_original_revno:
 
424
            return new_original_revno
 
425
        if getattr(self, "new_original_revid", None) is not None:
 
426
            return self._lookup_revno(self.new_original_revid)
420
427
        return self._lookup_revno(self.new_revid)
421
428
 
422
429
 
661
668
 
662
669
    def _get_new_refs(self, stop_revision=None):
663
670
        if stop_revision is None:
664
 
            stop_revision = self.source.last_revision()
 
671
            (stop_revno, stop_revision) = self.source.last_revision_info()
665
672
        assert type(stop_revision) is str
666
673
        main_ref = self.target.ref or "refs/heads/master"
667
674
        refs = { main_ref: (None, stop_revision) }
668
675
        for name, revid in self.source.tags.get_tag_dict().iteritems():
669
676
            if self.source.repository.has_revision(revid):
670
677
                refs[tag_name_to_ref(name)] = (None, revid)
671
 
        return refs, main_ref
 
678
        return refs, main_ref, (stop_revno, stop_revision)
672
679
 
673
680
    def pull(self, overwrite=False, stop_revision=None, local=False,
674
681
             possible_transports=None):
676
683
        result = GitBranchPullResult()
677
684
        result.source_branch = self.source
678
685
        result.target_branch = self.target
679
 
        new_refs, main_ref = self._get_new_refs(stop_revision)
 
686
        new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
680
687
        def update_refs(old_refs):
681
688
            refs = dict(old_refs)
682
689
            # FIXME: Check for diverged branches
695
702
        result = GitBranchPushResult()
696
703
        result.source_branch = self.source
697
704
        result.target_branch = self.target
698
 
        new_refs, main_ref = self._get_new_refs(stop_revision)
 
705
        new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
699
706
        def update_refs(old_refs):
700
707
            refs = dict(old_refs)
701
708
            # FIXME: Check for diverged branches
712
719
        result = GitBranchPushResult()
713
720
        result.source_branch = self.source
714
721
        result.target_branch = self.target
715
 
        new_refs, main_ref = self._get_new_refs(stop_revision)
 
722
        new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
716
723
        def update_refs(old_refs):
717
724
            refs = dict(old_refs)
718
725
            # FIXME: Check for diverged branches
722
729
            update_refs)
723
730
        result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
724
731
        result.new_revid = new_refs[main_ref][1]
 
732
        (result.new_original_revno, result.new_original_revid) = stop_revinfo
725
733
        return result
726
734
 
727
735