~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Andrew Bennetts
  • Date: 2009-06-09 03:14:05 UTC
  • mfrom: (4416 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4420.
  • Revision ID: andrew.bennetts@canonical.com-20090609031405-wak9yogzzpx9o172
Merge bzr.dev, resolving NEWS conflict.

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)
932
928
            location = None
933
929
        return location
934
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
 
935
935
    def get_submit_branch(self):
936
936
        """Return the submit location of the branch.
937
937
 
1085
1085
        source_revno, source_revision_id = self.last_revision_info()
1086
1086
        if revision_id is None:
1087
1087
            revno, revision_id = source_revno, source_revision_id
1088
 
        elif source_revision_id == revision_id:
1089
 
            # we know the revno without needing to walk all of history
1090
 
            revno = source_revno
1091
1088
        else:
1092
 
            # To figure out the revno for a random revision, we need to build
1093
 
            # the revision history, and count its length.
1094
 
            # We don't care about the order, just how long it is.
1095
 
            # Alternatively, we could start at the current location, and count
1096
 
            # backwards. But there is no guarantee that we will find it since
1097
 
            # it may be a merged revision.
1098
 
            revno = len(list(self.repository.iter_reverse_revision_history(
1099
 
                                                                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
1100
1096
        destination.set_last_revision_info(revno, revision_id)
1101
1097
 
1102
1098
    @needs_read_lock
1147
1143
 
1148
1144
        :return: A BranchCheckResult.
1149
1145
        """
 
1146
        ret = BranchCheckResult(self)
1150
1147
        mainline_parent_id = None
1151
1148
        last_revno, last_revision_id = self.last_revision_info()
1152
 
        real_rev_history = list(self.repository.iter_reverse_revision_history(
1153
 
                                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
1154
1158
        real_rev_history.reverse()
1155
1159
        if len(real_rev_history) != last_revno:
1156
1160
            raise errors.BzrCheckError('revno does not match len(mainline)'
1172
1176
                                        "parents of {%s}"
1173
1177
                                        % (mainline_parent_id, revision_id))
1174
1178
            mainline_parent_id = revision_id
1175
 
        return BranchCheckResult(self)
 
1179
        return ret
1176
1180
 
1177
1181
    def _get_checkout_format(self):
1178
1182
        """Return the most suitable metadir for a checkout of this branch.
2366
2370
                    raise AssertionError(
2367
2371
                        "'transform_fallback_location' hook %s returned "
2368
2372
                        "None, not a URL." % hook_name)
2369
 
            self._activate_fallback_location(url, None)
 
2373
            self._activate_fallback_location(url)
2370
2374
 
2371
2375
    def __init__(self, *args, **kwargs):
2372
2376
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2780
2784
 
2781
2785
    def __init__(self, branch):
2782
2786
        self.branch = branch
 
2787
        self.ghosts_in_mainline = False
2783
2788
 
2784
2789
    def report_results(self, verbose):
2785
2790
        """Report the check results via trace.note.
2790
2795
        note('checked branch %s format %s',
2791
2796
             self.branch.base,
2792
2797
             self.branch._format)
 
2798
        if self.ghosts_in_mainline:
 
2799
            note('branch contains ghosts in mainline')
2793
2800
 
2794
2801
 
2795
2802
class Converter5to6(object):