~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-06 10:41:03 UTC
  • mfrom: (1638.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060406104103-849a925941c89106
Change the basis-inventory file to not have the revision-id in the file name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
350
350
        revision_id = self.last_revision()
351
351
        if revision_id is not None:
352
352
            try:
353
 
                xml = self.read_basis_inventory(revision_id)
 
353
                xml = self.read_basis_inventory()
354
354
                inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
 
355
            except NoSuchFile:
 
356
                inv = None
 
357
            if inv is not None and inv.revision_id == revision_id:
355
358
                return bzrlib.tree.RevisionTree(self.branch.repository, inv,
356
359
                                                revision_id)
357
 
            except NoSuchFile:
358
 
                pass
 
360
        # FIXME? RBC 20060403 should we cache the inventory here ?
359
361
        return self.branch.repository.revision_tree(revision_id)
360
362
 
361
363
    @staticmethod
1024
1026
            self.branch.unlock()
1025
1027
            raise
1026
1028
 
1027
 
    def _basis_inventory_name(self, revision_id):
1028
 
        return 'basis-inventory.%s' % revision_id
 
1029
    def _basis_inventory_name(self):
 
1030
        return 'basis-inventory'
1029
1031
 
1030
1032
    @needs_write_lock
1031
 
    def set_last_revision(self, new_revision, old_revision=None):
 
1033
    def set_last_revision(self, new_revision):
1032
1034
        """Change the last revision in the working tree."""
1033
 
        self._remove_old_basis(old_revision)
1034
1035
        if self._change_last_revision(new_revision):
1035
1036
            self._cache_basis_inventory(new_revision)
1036
1037
 
1037
1038
    def _change_last_revision(self, new_revision):
1038
 
        """Template method part of set_last_revision to perform the change."""
 
1039
        """Template method part of set_last_revision to perform the change.
 
1040
        
 
1041
        This is used to allow WorkingTree3 instances to not affect branch
 
1042
        when their last revision is set.
 
1043
        """
1039
1044
        if new_revision is None:
1040
1045
            self.branch.set_revision_history([])
1041
1046
            return False
1051
1056
    def _cache_basis_inventory(self, new_revision):
1052
1057
        """Cache new_revision as the basis inventory."""
1053
1058
        try:
1054
 
            xml = self.branch.repository.get_inventory_xml(new_revision)
1055
 
            path = self._basis_inventory_name(new_revision)
 
1059
            # this double handles the inventory - unpack and repack - 
 
1060
            # but is easier to understand. We can/should put a conditional
 
1061
            # in here based on whether the inventory is in the latest format
 
1062
            # - perhaps we should repack all inventories on a repository
 
1063
            # upgrade ?
 
1064
            inv = self.branch.repository.get_inventory(new_revision)
 
1065
            inv.revision_id = new_revision
 
1066
            xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
 
1067
 
 
1068
            path = self._basis_inventory_name()
1056
1069
            self._control_files.put_utf8(path, xml)
1057
1070
        except WeaveRevisionNotPresent:
1058
1071
            pass
1059
1072
 
1060
 
    def _remove_old_basis(self, old_revision):
1061
 
        """Remove the old basis inventory 'old_revision'."""
1062
 
        if old_revision is not None:
1063
 
            try:
1064
 
                path = self._basis_inventory_name(old_revision)
1065
 
                path = self._control_files._escape(path)
1066
 
                self._control_files._transport.delete(path)
1067
 
            except NoSuchFile:
1068
 
                pass
1069
 
 
1070
 
    def read_basis_inventory(self, revision_id):
 
1073
    def read_basis_inventory(self):
1071
1074
        """Read the cached basis inventory."""
1072
 
        path = self._basis_inventory_name(revision_id)
 
1075
        path = self._basis_inventory_name()
1073
1076
        return self._control_files.get_utf8(path).read()
1074
1077
        
1075
1078
    @needs_read_lock