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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-26 21:59:10 UTC
  • mfrom: (2041.1.5 commit-perf)
  • Revision ID: pqm@pqm.ubuntu.com-20060926215910-c87762786b24e444
(jam) fix commit performance regression

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
            leftmost_parent_id = None
 
727
            leftmost_parent_tree = None
 
728
        else:
 
729
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
 
730
 
 
731
        if self._change_last_revision(leftmost_parent_id):
 
732
            if leftmost_parent_tree is None:
 
733
                # If we don't have a tree, fall back to reading the
 
734
                # parent tree from the repository.
 
735
                self._cache_basis_inventory(leftmost_parent_id)
 
736
            else:
 
737
                # It seems Repository.deserialise_inventory is doing this
 
738
                # because apparently commit builder, *doesn't*. It
 
739
                # seems like the in-memory Inventory should always have
 
740
                # the root.revision set without having to serialize out
 
741
                # to disk first.
 
742
                inv = leftmost_parent_tree.inventory
 
743
                if not self.branch.repository._format.rich_root_data:
 
744
                    inv.root.revision = leftmost_parent_id
 
745
                xml = self._create_basis_xml_from_inventory(
 
746
                                        leftmost_parent_id, inv)
 
747
                self._write_basis_inventory(xml)
 
748
        self._set_merges_from_parent_ids(parent_ids)
 
749
 
710
750
    @needs_tree_write_lock
711
751
    def set_pending_merges(self, rev_list):
712
752
        parents = self.get_parent_ids()
1383
1423
            self.branch.set_revision_history([new_revision])
1384
1424
        return True
1385
1425
 
 
1426
    def _write_basis_inventory(self, xml):
 
1427
        """Write the basis inventory XML to the basis-inventory file"""
 
1428
        assert isinstance(xml, str), 'serialised xml must be bytestring.'
 
1429
        path = self._basis_inventory_name()
 
1430
        sio = StringIO(xml)
 
1431
        self._control_files.put(path, sio)
 
1432
 
 
1433
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
 
1434
        """Create the text that will be saved in basis-inventory"""
 
1435
        inventory.revision_id = revision_id
 
1436
        return bzrlib.xml6.serializer_v6.write_inventory_to_string(inventory)
 
1437
 
1386
1438
    def _cache_basis_inventory(self, new_revision):
1387
1439
        """Cache new_revision as the basis inventory."""
1388
1440
        # TODO: this should allow the ready-to-use inventory to be passed in,
1405
1457
                'format="6"' not in firstline):
1406
1458
                inv = self.branch.repository.deserialise_inventory(
1407
1459
                    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)
 
1460
                xml = self._create_basis_xml_from_inventory(new_revision, inv)
 
1461
            self._write_basis_inventory(xml)
1414
1462
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
1415
1463
            pass
1416
1464