/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/repository.py

  • Committer: Andrew Bennetts
  • Date: 2007-10-12 08:18:54 UTC
  • mfrom: (2905 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2906.
  • Revision ID: andrew.bennetts@canonical.com-20071012081854-6wjgjhjjdy55s84i
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
621
621
        self.weave_store = text_store
622
622
        # for tests
623
623
        self._reconcile_does_inventory_gc = True
 
624
        self._reconcile_fixes_text_parents = False
624
625
        # not right yet - should be more semantically clear ? 
625
626
        # 
626
627
        self.control_store = control_store
1471
1472
                [parents_provider, other_repository._make_parents_provider()])
1472
1473
        return graph.Graph(parents_provider)
1473
1474
 
 
1475
    def get_versioned_file_checker(self, revisions, revision_versions_cache):
 
1476
        return VersionedFileChecker(revisions, revision_versions_cache, self)
 
1477
 
1474
1478
    @needs_write_lock
1475
1479
    def set_make_working_trees(self, new_value):
1476
1480
        """Set the policy flag for making working trees when creating branches.
1505
1509
                                                       self.get_transaction())
1506
1510
 
1507
1511
    @needs_read_lock
1508
 
    def check(self, revision_ids):
 
1512
    def check(self, revision_ids=None):
1509
1513
        """Check consistency of all history of given revision_ids.
1510
1514
 
1511
1515
        Different repository implementations should override _check().
1513
1517
        :param revision_ids: A non-empty list of revision_ids whose ancestry
1514
1518
             will be checked.  Typically the last revision_id of a branch.
1515
1519
        """
1516
 
        if not revision_ids:
1517
 
            raise ValueError("revision_ids must be non-empty in %s.check" 
1518
 
                    % (self,))
1519
1520
        return self._check(revision_ids)
1520
1521
 
1521
1522
    def _check(self, revision_ids):
1549
1550
                    revision_id.decode('ascii')
1550
1551
                except UnicodeDecodeError:
1551
1552
                    raise errors.NonAsciiRevisionId(method, self)
1552
 
 
1553
 
 
1554
 
 
 
1553
    
 
1554
    def revision_graph_can_have_wrong_parents(self):
 
1555
        """Is it possible for this repository to have a revision graph with
 
1556
        incorrect parents?
 
1557
 
 
1558
        If True, then this repository must also implement
 
1559
        _find_inconsistent_revision_parents so that check and reconcile can
 
1560
        check for inconsistencies before proceeding with other checks that may
 
1561
        depend on the revision index being consistent.
 
1562
        """
 
1563
        raise NotImplementedError(self.revision_graph_can_have_wrong_parents)
 
1564
        
1555
1565
# remove these delegates a while after bzr 0.15
1556
1566
def __make_delegated(name, from_module):
1557
1567
    def _deprecated_repository_forwarder():
2471
2481
    if _unescape_re is None:
2472
2482
        _unescape_re = re.compile('\&([^;]*);')
2473
2483
    return _unescape_re.sub(_unescaper, data)
 
2484
 
 
2485
 
 
2486
class _RevisionTextVersionCache(object):
 
2487
    """A cache of the versionedfile versions for revision and file-id."""
 
2488
 
 
2489
    def __init__(self, repository):
 
2490
        self.repository = repository
 
2491
        self.revision_versions = {}
 
2492
 
 
2493
    def add_revision_text_versions(self, tree):
 
2494
        """Cache text version data from the supplied revision tree"""
 
2495
        inv_revisions = {}
 
2496
        for path, entry in tree.iter_entries_by_dir():
 
2497
            inv_revisions[entry.file_id] = entry.revision
 
2498
        self.revision_versions[tree.get_revision_id()] = inv_revisions
 
2499
        return inv_revisions
 
2500
 
 
2501
    def get_text_version(self, file_id, revision_id):
 
2502
        """Determine the text version for a given file-id and revision-id"""
 
2503
        try:
 
2504
            inv_revisions = self.revision_versions[revision_id]
 
2505
        except KeyError:
 
2506
            tree = self.repository.revision_tree(revision_id)
 
2507
            inv_revisions = self.add_revision_text_versions(tree)
 
2508
        return inv_revisions.get(file_id)
 
2509
 
 
2510
 
 
2511
class VersionedFileChecker(object):
 
2512
 
 
2513
    def __init__(self, planned_revisions, revision_versions, repository):
 
2514
        self.planned_revisions = planned_revisions
 
2515
        self.revision_versions = revision_versions
 
2516
        self.repository = repository
 
2517
    
 
2518
    def calculate_file_version_parents(self, revision_id, file_id):
 
2519
        text_revision = self.revision_versions.get_text_version(
 
2520
            file_id, revision_id)
 
2521
        if text_revision is None:
 
2522
            return None
 
2523
        parents_of_text_revision = self.repository.get_parents(
 
2524
            [text_revision])[0]
 
2525
        parents_from_inventories = []
 
2526
        for parent in parents_of_text_revision:
 
2527
            if parent == _mod_revision.NULL_REVISION:
 
2528
                continue
 
2529
            try:
 
2530
                inventory = self.repository.get_inventory(parent)
 
2531
            except errors.RevisionNotPresent:
 
2532
                pass
 
2533
            else:
 
2534
                try:
 
2535
                    introduced_in = inventory[file_id].revision
 
2536
                except errors.NoSuchId:
 
2537
                    pass
 
2538
                else:
 
2539
                    parents_from_inventories.append(introduced_in)
 
2540
        graph = self.repository.get_graph()
 
2541
        heads = set(graph.heads(parents_from_inventories))
 
2542
        new_parents = []
 
2543
        for parent in parents_from_inventories:
 
2544
            if parent in heads and parent not in new_parents:
 
2545
                new_parents.append(parent)
 
2546
        return new_parents
 
2547
 
 
2548
    def check_file_version_parents(self, weave, file_id):
 
2549
        result = {}
 
2550
        for num, revision_id in enumerate(self.planned_revisions):
 
2551
            correct_parents = self.calculate_file_version_parents(
 
2552
                revision_id, file_id)
 
2553
            if correct_parents is None:
 
2554
                continue
 
2555
            text_revision = self.revision_versions.get_text_version(
 
2556
                file_id, revision_id)
 
2557
            knit_parents = weave.get_parents(text_revision)
 
2558
            if correct_parents != knit_parents:
 
2559
                result[revision_id] = (knit_parents, correct_parents)
 
2560
        return result