~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-26 00:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 2044.
  • Revision ID: john@arbash-meinel.com-20060926002612-31b451c3f8a41992
Update WorkingTree.set_parent_trees() to directly cache inv.
Rather than go through set_parent_ids() which calls set_last_revision(),
which has to read the inventory back out of the repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
675
675
        """
676
676
        return self.get_parent_ids()[1:]
677
677
 
 
678
    def _check_parents_for_ghosts(self, revision_ids, allow_leftmost_as_ghost):
 
679
        """Common ghost checking functionality from set_parent_*.
 
680
 
 
681
        This checks that the left hand-parent exists if there are any
 
682
        revisions present.
 
683
        """
 
684
        if len(revision_ids) > 0:
 
685
            leftmost_id = revision_ids[0]
 
686
            if (not allow_leftmost_as_ghost and not
 
687
                self.branch.repository.has_revision(leftmost_id)):
 
688
                raise errors.GhostRevisionUnusableHere(leftmost_id)
 
689
 
 
690
    def _set_merges_from_parent_ids(self, parent_ids):
 
691
        merges = parent_ids[1:]
 
692
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
 
693
 
678
694
    @needs_tree_write_lock
679
695
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
680
696
        """Set the parent ids to revision_ids.
688
704
        :param revision_ids: The revision_ids to set as the parent ids of this
689
705
            working tree. Any of these may be ghosts.
690
706
        """
 
707
        self._check_parents_for_ghosts(revision_ids,
 
708
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
709
 
691
710
        if len(revision_ids) > 0:
692
 
            leftmost_id = revision_ids[0]
693
 
            if (not allow_leftmost_as_ghost and not
694
 
                self.branch.repository.has_revision(leftmost_id)):
695
 
                raise errors.GhostRevisionUnusableHere(leftmost_id)
696
 
            self.set_last_revision(leftmost_id)
 
711
            self.set_last_revision(revision_ids[0])
697
712
        else:
698
713
            self.set_last_revision(None)
699
 
        merges = revision_ids[1:]
700
 
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
 
714
 
 
715
        self._set_merges_from_parent_ids(revision_ids)
701
716
 
702
717
    @needs_tree_write_lock
703
718
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
704
719
        """See MutableTree.set_parent_trees."""
705
 
        # parent trees are not used in current format trees, delegate to
706
 
        # set_parent_ids
707
 
        self.set_parent_ids([rev for (rev, tree) in parents_list],
 
720
        parent_ids = [rev for (rev, tree) in parents_list]
 
721
 
 
722
        self._check_parents_for_ghosts(parent_ids,
708
723
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
709
724
 
 
725
        if len(parent_ids) == 0:
 
726
            self.set_last_revision(None)
 
727
        else:
 
728
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
 
729
 
 
730
            if leftmost_parent_id is None or leftmost_parent_tree is None:
 
731
                self.set_last_revision(leftmost_parent_id)
 
732
            elif self._change_last_revision(leftmost_parent_id):
 
733
                # It seems Repository.deserialise_inventory is doing this
 
734
                # because apparently commit, and such *don't*. But that
 
735
                # seems really bogus.
 
736
                inv = leftmost_parent_tree.inventory
 
737
                if not self.branch.repository._format.rich_root_data:
 
738
                    inv.root.revision = leftmost_parent_id
 
739
                xml = self._create_basis_xml_from_inventory(
 
740
                                        leftmost_parent_id, inv)
 
741
                self._write_basis_inventory(xml)
 
742
        self._set_merges_from_parent_ids(parent_ids)
 
743
 
710
744
    @needs_tree_write_lock
711
745
    def set_pending_merges(self, rev_list):
712
746
        parents = self.get_parent_ids()
1383
1417
            self.branch.set_revision_history([new_revision])
1384
1418
        return True
1385
1419
 
 
1420
    def _write_basis_inventory(self, xml):
 
1421
        """Write the basis inventory XML to the basis-inventory file"""
 
1422
        assert isinstance(xml, str), 'serialised xml must be bytestring.'
 
1423
        path = self._basis_inventory_name()
 
1424
        sio = StringIO(xml)
 
1425
        self._control_files.put(path, sio)
 
1426
 
 
1427
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
 
1428
        """Create the text that will be saved in basis-inventory"""
 
1429
        inventory.revision_id = revision_id
 
1430
        return bzrlib.xml6.serializer_v6.write_inventory_to_string(inventory)
 
1431
 
1386
1432
    def _cache_basis_inventory(self, new_revision):
1387
1433
        """Cache new_revision as the basis inventory."""
1388
1434
        # TODO: this should allow the ready-to-use inventory to be passed in,
1405
1451
                'format="6"' not in firstline):
1406
1452
                inv = self.branch.repository.deserialise_inventory(
1407
1453
                    new_revision, xml)
1408
 
                inv.revision_id = new_revision
1409
 
                xml = bzrlib.xml6.serializer_v6.write_inventory_to_string(inv)
1410
 
            assert isinstance(xml, str), 'serialised xml must be bytestring.'
1411
 
            path = self._basis_inventory_name()
1412
 
            sio = StringIO(xml)
1413
 
            self._control_files.put(path, sio)
 
1454
                xml = self._create_basis_xml_from_inventory(new_revision, inv)
 
1455
            self._write_basis_inventory(xml)
1414
1456
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
1415
1457
            pass
1416
1458