~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-06 02:23:37 UTC
  • mfrom: (4332.3.36 check)
  • Revision ID: pqm@pqm.ubuntu.com-20090806022337-7c2oni07fsjq6gun
(robertc) Partial overhaul of check to do less duplicate work.
        (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
        if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
150
150
            self._partial_revision_history_cache.pop()
151
151
 
 
152
    def _get_check_refs(self):
 
153
        """Get the references needed for check().
 
154
 
 
155
        See bzrlib.check.
 
156
        """
 
157
        revid = self.last_revision()
 
158
        return [('revision-existence', revid), ('lefthand-distance', revid)]
 
159
 
152
160
    @staticmethod
153
161
    def open(base, _unsupported=False, possible_transports=None):
154
162
        """Open the branch rooted at base.
1212
1220
        target._set_all_reference_info(target_reference_dict)
1213
1221
 
1214
1222
    @needs_read_lock
1215
 
    def check(self):
 
1223
    def check(self, refs):
1216
1224
        """Check consistency of the branch.
1217
1225
 
1218
1226
        In particular this checks that revisions given in the revision-history
1221
1229
 
1222
1230
        Callers will typically also want to check the repository.
1223
1231
 
 
1232
        :param refs: Calculated refs for this branch as specified by
 
1233
            branch._get_check_refs()
1224
1234
        :return: A BranchCheckResult.
1225
1235
        """
1226
 
        ret = BranchCheckResult(self)
1227
 
        mainline_parent_id = None
 
1236
        result = BranchCheckResult(self)
1228
1237
        last_revno, last_revision_id = self.last_revision_info()
1229
 
        real_rev_history = []
1230
 
        try:
1231
 
            for revid in self.repository.iter_reverse_revision_history(
1232
 
                last_revision_id):
1233
 
                real_rev_history.append(revid)
1234
 
        except errors.RevisionNotPresent:
1235
 
            ret.ghosts_in_mainline = True
1236
 
        else:
1237
 
            ret.ghosts_in_mainline = False
1238
 
        real_rev_history.reverse()
1239
 
        if len(real_rev_history) != last_revno:
1240
 
            raise errors.BzrCheckError('revno does not match len(mainline)'
1241
 
                ' %s != %s' % (last_revno, len(real_rev_history)))
1242
 
        # TODO: We should probably also check that real_rev_history actually
1243
 
        #       matches self.revision_history()
1244
 
        for revision_id in real_rev_history:
1245
 
            try:
1246
 
                revision = self.repository.get_revision(revision_id)
1247
 
            except errors.NoSuchRevision, e:
1248
 
                raise errors.BzrCheckError("mainline revision {%s} not in repository"
1249
 
                            % revision_id)
1250
 
            # In general the first entry on the revision history has no parents.
1251
 
            # But it's not illegal for it to have parents listed; this can happen
1252
 
            # in imports from Arch when the parents weren't reachable.
1253
 
            if mainline_parent_id is not None:
1254
 
                if mainline_parent_id not in revision.parent_ids:
1255
 
                    raise errors.BzrCheckError("previous revision {%s} not listed among "
1256
 
                                        "parents of {%s}"
1257
 
                                        % (mainline_parent_id, revision_id))
1258
 
            mainline_parent_id = revision_id
1259
 
        return ret
 
1238
        actual_revno = refs[('lefthand-distance', last_revision_id)]
 
1239
        if actual_revno != last_revno:
 
1240
            result.errors.append(errors.BzrCheckError(
 
1241
                'revno does not match len(mainline) %s != %s' % (
 
1242
                last_revno, actual_revno)))
 
1243
        # TODO: We should probably also check that self.revision_history
 
1244
        # matches the repository for older branch formats.
 
1245
        # If looking for the code that cross-checks repository parents against
 
1246
        # the iter_reverse_revision_history output, that is now a repository
 
1247
        # specific check.
 
1248
        return result
1260
1249
 
1261
1250
    def _get_checkout_format(self):
1262
1251
        """Return the most suitable metadir for a checkout of this branch.
2839
2828
 
2840
2829
    def __init__(self, branch):
2841
2830
        self.branch = branch
2842
 
        self.ghosts_in_mainline = False
 
2831
        self.errors = []
2843
2832
 
2844
2833
    def report_results(self, verbose):
2845
2834
        """Report the check results via trace.note.
2847
2836
        :param verbose: Requests more detailed display of what was checked,
2848
2837
            if any.
2849
2838
        """
2850
 
        note('checked branch %s format %s',
2851
 
             self.branch.base,
2852
 
             self.branch._format)
2853
 
        if self.ghosts_in_mainline:
2854
 
            note('branch contains ghosts in mainline')
 
2839
        note('checked branch %s format %s', self.branch.base,
 
2840
            self.branch._format)
 
2841
        for error in self.errors:
 
2842
            note('found error:%s', error)
2855
2843
 
2856
2844
 
2857
2845
class Converter5to6(object):