~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
    def _open_hook(self):
102
102
        """Called by init to allow simpler extension of the base class."""
103
103
 
104
 
    def _activate_fallback_location(self, url, lock_style):
 
104
    def _activate_fallback_location(self, url):
105
105
        """Activate the branch/repository from url as a fallback repository."""
106
106
        repo = self._get_fallback_repository(url)
107
 
        if lock_style == 'write':
108
 
            repo.lock_write()
109
 
        elif lock_style == 'read':
110
 
            repo.lock_read()
111
107
        self.repository.add_fallback_repository(repo)
112
108
 
113
109
    def break_lock(self):
656
652
                self.repository.fetch(source_repository, revision_id,
657
653
                    find_ghosts=True)
658
654
        else:
659
 
            self._activate_fallback_location(url, 'write')
 
655
            self._activate_fallback_location(url)
660
656
        # write this out after the repository is stacked to avoid setting a
661
657
        # stacked config that doesn't work.
662
658
        self._set_config_location('stacked_on_location', url)
867
863
        return InterBranch.get(self, target).push(overwrite, stop_revision,
868
864
            *args, **kwargs)
869
865
 
 
866
    def lossy_push(self, target, stop_revision=None):
 
867
        """Push deltas into another branch.
 
868
 
 
869
        :note: This does not, like push, retain the revision ids from 
 
870
            the source branch and will, rather than adding bzr-specific 
 
871
            metadata, push only those semantics of the revision that can be 
 
872
            natively represented by this branch' VCS.
 
873
 
 
874
        :param target: Target branch
 
875
        :param stop_revision: Revision to push, defaults to last revision.
 
876
        :return: BranchPushResult with an extra member revidmap: 
 
877
            A dictionary mapping revision ids from the target branch 
 
878
            to new revision ids in the target branch, for each 
 
879
            revision that was pushed.
 
880
        """
 
881
        inter = InterBranch.get(self, target)
 
882
        lossy_push = getattr(inter, "lossy_push", None)
 
883
        if lossy_push is None:
 
884
            raise errors.LossyPushToSameVCS(self, target)
 
885
        return lossy_push(stop_revision)
 
886
 
870
887
    def basis_tree(self):
871
888
        """Return `Tree` object for last revision."""
872
889
        return self.repository.revision_tree(self.last_revision())
911
928
            location = None
912
929
        return location
913
930
 
 
931
    def get_child_submit_format(self):
 
932
        """Return the preferred format of submissions to this branch."""
 
933
        return self.get_config().get_user_option("child_submit_format")
 
934
 
914
935
    def get_submit_branch(self):
915
936
        """Return the submit location of the branch.
916
937
 
1064
1085
        source_revno, source_revision_id = self.last_revision_info()
1065
1086
        if revision_id is None:
1066
1087
            revno, revision_id = source_revno, source_revision_id
1067
 
        elif source_revision_id == revision_id:
1068
 
            # we know the revno without needing to walk all of history
1069
 
            revno = source_revno
1070
1088
        else:
1071
 
            # To figure out the revno for a random revision, we need to build
1072
 
            # the revision history, and count its length.
1073
 
            # We don't care about the order, just how long it is.
1074
 
            # Alternatively, we could start at the current location, and count
1075
 
            # backwards. But there is no guarantee that we will find it since
1076
 
            # it may be a merged revision.
1077
 
            revno = len(list(self.repository.iter_reverse_revision_history(
1078
 
                                                                revision_id)))
 
1089
            graph = self.repository.get_graph()
 
1090
            try:
 
1091
                revno = graph.find_distance_to_null(revision_id, 
 
1092
                    [(source_revision_id, source_revno)])
 
1093
            except errors.GhostRevisionsHaveNoRevno:
 
1094
                # Default to 1, if we can't find anything else
 
1095
                revno = 1
1079
1096
        destination.set_last_revision_info(revno, revision_id)
1080
1097
 
1081
1098
    @needs_read_lock
1126
1143
 
1127
1144
        :return: A BranchCheckResult.
1128
1145
        """
 
1146
        ret = BranchCheckResult(self)
1129
1147
        mainline_parent_id = None
1130
1148
        last_revno, last_revision_id = self.last_revision_info()
1131
 
        real_rev_history = list(self.repository.iter_reverse_revision_history(
1132
 
                                last_revision_id))
 
1149
        real_rev_history = []
 
1150
        try:
 
1151
            for revid in self.repository.iter_reverse_revision_history(
 
1152
                last_revision_id):
 
1153
                real_rev_history.append(revid)
 
1154
        except errors.RevisionNotPresent:
 
1155
            ret.ghosts_in_mainline = True
 
1156
        else:
 
1157
            ret.ghosts_in_mainline = False
1133
1158
        real_rev_history.reverse()
1134
1159
        if len(real_rev_history) != last_revno:
1135
1160
            raise errors.BzrCheckError('revno does not match len(mainline)'
1151
1176
                                        "parents of {%s}"
1152
1177
                                        % (mainline_parent_id, revision_id))
1153
1178
            mainline_parent_id = revision_id
1154
 
        return BranchCheckResult(self)
 
1179
        return ret
1155
1180
 
1156
1181
    def _get_checkout_format(self):
1157
1182
        """Return the most suitable metadir for a checkout of this branch.
2345
2370
                    raise AssertionError(
2346
2371
                        "'transform_fallback_location' hook %s returned "
2347
2372
                        "None, not a URL." % hook_name)
2348
 
            self._activate_fallback_location(url, None)
 
2373
            self._activate_fallback_location(url)
2349
2374
 
2350
2375
    def __init__(self, *args, **kwargs):
2351
2376
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2759
2784
 
2760
2785
    def __init__(self, branch):
2761
2786
        self.branch = branch
 
2787
        self.ghosts_in_mainline = False
2762
2788
 
2763
2789
    def report_results(self, verbose):
2764
2790
        """Report the check results via trace.note.
2769
2795
        note('checked branch %s format %s',
2770
2796
             self.branch.base,
2771
2797
             self.branch._format)
 
2798
        if self.ghosts_in_mainline:
 
2799
            note('branch contains ghosts in mainline')
2772
2800
 
2773
2801
 
2774
2802
class Converter5to6(object):