~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2007-10-05 00:44:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2905.
  • Revision ID: andrew.bennetts@canonical.com-20071005004453-01gpk6nnh4zelciv
Move check_parents out of VersionedFile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1452
1452
                [parents_provider, other_repository._make_parents_provider()])
1453
1453
        return graph.Graph(parents_provider)
1454
1454
 
 
1455
    def get_versioned_file_checker(self, revisions, revision_versions_cache):
 
1456
        return WeaveChecker(revisions, revision_versions_cache, self)
 
1457
 
1455
1458
    def find_bad_ancestors(self, revision_ids, file_id, versionedfile,
1456
1459
                           revision_versions):
1457
1460
        """Search the versionedfile for ancestors that are not referenced.
2524
2527
                self._memoized[revision_id] = parents
2525
2528
            parents_list.append(parents)
2526
2529
        return parents_list
 
2530
 
 
2531
 
 
2532
class WeaveChecker(object):
 
2533
 
 
2534
    def __init__(self, planned_revisions, revision_versions, repository):
 
2535
        self.planned_revisions = planned_revisions
 
2536
        self.revision_versions = revision_versions
 
2537
        self.repository = repository
 
2538
        
 
2539
    def calculate_file_version_parents(self, revision_id, file_id,
 
2540
                                       parents_provider):
 
2541
        text_revision = self.revision_versions.get_text_version(
 
2542
            file_id, revision_id)
 
2543
        if text_revision is None:
 
2544
            return None
 
2545
        parents_of_text_revision = parents_provider.get_parents(
 
2546
            [text_revision])[0]
 
2547
        parents_from_inventories = []
 
2548
        for parent in parents_of_text_revision:
 
2549
            if parent == _mod_revision.NULL_REVISION:
 
2550
                continue
 
2551
            try:
 
2552
                inventory = self.repository.get_inventory(parent)
 
2553
            except errors.RevisionNotPresent:
 
2554
                pass
 
2555
            else:
 
2556
                introduced_in = inventory[file_id].revision
 
2557
                parents_from_inventories.append(introduced_in)
 
2558
        mutter('%r:%r introduced in: %r',
 
2559
               file_id, revision_id, parents_from_inventories)
 
2560
        graph = self.repository.get_graph()
 
2561
        heads = set(graph.heads(parents_from_inventories))
 
2562
        mutter('    heads: %r', heads)
 
2563
        new_parents = []
 
2564
        for parent in parents_from_inventories:
 
2565
            if parent in heads and parent not in new_parents:
 
2566
                new_parents.append(parent)
 
2567
        return new_parents
 
2568
 
 
2569
    def check_file_version_parents(self, weave, file_id, parents_provider):
 
2570
        result = {}
 
2571
        for num, revision_id in enumerate(self.planned_revisions):
 
2572
            correct_parents = self.calculate_file_version_parents(
 
2573
                revision_id, file_id, parents_provider)
 
2574
            if correct_parents is None:
 
2575
                continue
 
2576
            text_revision = self.revision_versions.get_text_version(
 
2577
                file_id, revision_id)
 
2578
            knit_parents = weave.get_parents(text_revision)
 
2579
            if correct_parents != knit_parents:
 
2580
                result[revision_id] = (knit_parents, correct_parents)
 
2581
        return result