~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-02 04:50:05 UTC
  • mto: (4476.3.44 inventory-delta)
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090702045005-fqlbhlnvi7fsgue6
Refactor out duplicated get parent keys logic from Inter1and2Helper and InterDifferingSerializer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3521
3521
        deltas.sort()
3522
3522
        return deltas[0][1:]
3523
3523
 
3524
 
    def _get_parent_keys(self, root_key, parent_map):
3525
 
        """Get the parent keys for a given root id."""
3526
 
        root_id, rev_id = root_key
3527
 
        # Include direct parents of the revision, but only if they used
3528
 
        # the same root_id and are heads.
3529
 
        parent_keys = []
3530
 
        for parent_id in parent_map[rev_id]:
3531
 
            if parent_id == _mod_revision.NULL_REVISION:
3532
 
                continue
3533
 
            if parent_id not in self._revision_id_to_root_id:
3534
 
                # We probably didn't read this revision, go spend the
3535
 
                # extra effort to actually check
3536
 
                try:
3537
 
                    tree = self.source.revision_tree(parent_id)
3538
 
                except errors.NoSuchRevision:
3539
 
                    # Ghost, fill out _revision_id_to_root_id in case we
3540
 
                    # encounter this again.
3541
 
                    # But set parent_root_id to None since we don't really know
3542
 
                    parent_root_id = None
3543
 
                else:
3544
 
                    parent_root_id = tree.get_root_id()
3545
 
                self._revision_id_to_root_id[parent_id] = None
3546
 
            else:
3547
 
                parent_root_id = self._revision_id_to_root_id[parent_id]
3548
 
            if root_id == parent_root_id:
3549
 
                # With stacking we _might_ want to refer to a non-local
3550
 
                # revision, but this code path only applies when we have the
3551
 
                # full content available, so ghosts really are ghosts, not just
3552
 
                # the edge of local data.
3553
 
                parent_keys.append((parent_id,))
3554
 
            else:
3555
 
                # root_id may be in the parent anyway.
3556
 
                try:
3557
 
                    tree = self.source.revision_tree(parent_id)
3558
 
                except errors.NoSuchRevision:
3559
 
                    # ghost, can't refer to it.
3560
 
                    pass
3561
 
                else:
3562
 
                    try:
3563
 
                        parent_keys.append((tree.inventory[root_id].revision,))
3564
 
                    except errors.NoSuchId:
3565
 
                        # not in the tree
3566
 
                        pass
 
3524
    def _new_root_data_stream(self, root_keys_to_create, parent_map):
 
3525
        from bzrlib.fetch import _parent_keys_for_root_version
3567
3526
        g = graph.Graph(self.source.revisions)
3568
 
        heads = g.heads(parent_keys)
3569
 
        selected_keys = []
3570
 
        for key in parent_keys:
3571
 
            if key in heads and key not in selected_keys:
3572
 
                selected_keys.append(key)
3573
 
        return tuple([(root_id,)+ key for key in selected_keys])
3574
 
 
3575
 
    def _new_root_data_stream(self, root_keys_to_create, parent_map):
3576
3527
        for root_key in root_keys_to_create:
3577
 
            parent_keys = self._get_parent_keys(root_key, parent_map)
 
3528
            root_id, rev_id = root_key
 
3529
            parent_keys = _parent_keys_for_root_version(
 
3530
                root_id, rev_id, self._revision_id_to_root_id, parent_map, g,
 
3531
                self.source)
3578
3532
            yield versionedfile.FulltextContentFactory(root_key,
3579
3533
                parent_keys, None, '')
3580
3534