/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2009-09-14 01:48:28 UTC
  • mfrom: (4685 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090914014828-ydr9rlkdfq2sv57z
Merge news

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.
438
446
        # start_revision_id.
439
447
        if self._merge_sorted_revisions_cache is None:
440
448
            last_revision = self.last_revision()
441
 
            graph = self.repository.get_graph()
442
 
            parent_map = dict(((key, value) for key, value in
443
 
                     graph.iter_ancestry([last_revision]) if value is not None))
444
 
            revision_graph = repository._strip_NULL_ghosts(parent_map)
445
 
            revs = tsort.merge_sort(revision_graph, last_revision, None,
446
 
                generate_revno=True)
447
 
            # Drop the sequence # before caching
448
 
            self._merge_sorted_revisions_cache = [r[1:] for r in revs]
449
 
 
 
449
            last_key = (last_revision,)
 
450
            known_graph = self.repository.revisions.get_known_graph_ancestry(
 
451
                [last_key])
 
452
            self._merge_sorted_revisions_cache = known_graph.merge_sort(
 
453
                last_key)
450
454
        filtered = self._filter_merge_sorted_revisions(
451
455
            self._merge_sorted_revisions_cache, start_revision_id,
452
456
            stop_revision_id, stop_rule)
462
466
        """Iterate over an inclusive range of sorted revisions."""
463
467
        rev_iter = iter(merge_sorted_revisions)
464
468
        if start_revision_id is not None:
465
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
469
            for node in rev_iter:
 
470
                rev_id = node.key[-1]
466
471
                if rev_id != start_revision_id:
467
472
                    continue
468
473
                else:
469
474
                    # The decision to include the start or not
470
475
                    # depends on the stop_rule if a stop is provided
471
 
                    rev_iter = chain(
472
 
                        iter([(rev_id, depth, revno, end_of_merge)]),
473
 
                        rev_iter)
 
476
                    # so pop this node back into the iterator
 
477
                    rev_iter = chain(iter([node]), rev_iter)
474
478
                    break
475
479
        if stop_revision_id is None:
476
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
477
 
                yield rev_id, depth, revno, end_of_merge
 
480
            # Yield everything
 
481
            for node in rev_iter:
 
482
                rev_id = node.key[-1]
 
483
                yield (rev_id, node.merge_depth, node.revno,
 
484
                       node.end_of_merge)
478
485
        elif stop_rule == 'exclude':
479
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
486
            for node in rev_iter:
 
487
                rev_id = node.key[-1]
480
488
                if rev_id == stop_revision_id:
481
489
                    return
482
 
                yield rev_id, depth, revno, end_of_merge
 
490
                yield (rev_id, node.merge_depth, node.revno,
 
491
                       node.end_of_merge)
483
492
        elif stop_rule == 'include':
484
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
485
 
                yield rev_id, depth, revno, end_of_merge
 
493
            for node in rev_iter:
 
494
                rev_id = node.key[-1]
 
495
                yield (rev_id, node.merge_depth, node.revno,
 
496
                       node.end_of_merge)
486
497
                if rev_id == stop_revision_id:
487
498
                    return
488
499
        elif stop_rule == 'with-merges':
491
502
                left_parent = stop_rev.parent_ids[0]
492
503
            else:
493
504
                left_parent = _mod_revision.NULL_REVISION
494
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
505
            for node in rev_iter:
 
506
                rev_id = node.key[-1]
495
507
                if rev_id == left_parent:
496
508
                    return
497
 
                yield rev_id, depth, revno, end_of_merge
 
509
                yield (rev_id, node.merge_depth, node.revno,
 
510
                       node.end_of_merge)
498
511
        else:
499
512
            raise ValueError('invalid stop_rule %r' % stop_rule)
500
513
 
1139
1152
        revision_id: if not None, the revision history in the new branch will
1140
1153
                     be truncated to end with revision_id.
1141
1154
        """
 
1155
        if (repository_policy is not None and
 
1156
            repository_policy.requires_stacking()):
 
1157
            to_bzrdir._format.require_stacking(_skip_repo=True)
1142
1158
        result = to_bzrdir.create_branch()
1143
1159
        result.lock_write()
1144
1160
        try:
1212
1228
        target._set_all_reference_info(target_reference_dict)
1213
1229
 
1214
1230
    @needs_read_lock
1215
 
    def check(self):
 
1231
    def check(self, refs):
1216
1232
        """Check consistency of the branch.
1217
1233
 
1218
1234
        In particular this checks that revisions given in the revision-history
1221
1237
 
1222
1238
        Callers will typically also want to check the repository.
1223
1239
 
 
1240
        :param refs: Calculated refs for this branch as specified by
 
1241
            branch._get_check_refs()
1224
1242
        :return: A BranchCheckResult.
1225
1243
        """
1226
 
        ret = BranchCheckResult(self)
1227
 
        mainline_parent_id = None
 
1244
        result = BranchCheckResult(self)
1228
1245
        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
 
1246
        actual_revno = refs[('lefthand-distance', last_revision_id)]
 
1247
        if actual_revno != last_revno:
 
1248
            result.errors.append(errors.BzrCheckError(
 
1249
                'revno does not match len(mainline) %s != %s' % (
 
1250
                last_revno, actual_revno)))
 
1251
        # TODO: We should probably also check that self.revision_history
 
1252
        # matches the repository for older branch formats.
 
1253
        # If looking for the code that cross-checks repository parents against
 
1254
        # the iter_reverse_revision_history output, that is now a repository
 
1255
        # specific check.
 
1256
        return result
1260
1257
 
1261
1258
    def _get_checkout_format(self):
1262
1259
        """Return the most suitable metadir for a checkout of this branch.
2075
2072
BranchFormat.register_format(__format6)
2076
2073
BranchFormat.register_format(__format7)
2077
2074
BranchFormat.register_format(__format8)
2078
 
BranchFormat.set_default_format(__format6)
 
2075
BranchFormat.set_default_format(__format7)
2079
2076
_legacy_formats = [BzrBranchFormat4(),
2080
2077
    ]
2081
2078
network_format_registry.register(
2839
2836
 
2840
2837
    def __init__(self, branch):
2841
2838
        self.branch = branch
2842
 
        self.ghosts_in_mainline = False
 
2839
        self.errors = []
2843
2840
 
2844
2841
    def report_results(self, verbose):
2845
2842
        """Report the check results via trace.note.
2847
2844
        :param verbose: Requests more detailed display of what was checked,
2848
2845
            if any.
2849
2846
        """
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')
 
2847
        note('checked branch %s format %s', self.branch.base,
 
2848
            self.branch._format)
 
2849
        for error in self.errors:
 
2850
            note('found error:%s', error)
2855
2851
 
2856
2852
 
2857
2853
class Converter5to6(object):