350
350
revision_id = self.last_revision()
351
351
if revision_id is not None:
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)
357
if inv is not None and inv.revision_id == revision_id:
355
358
return bzrlib.tree.RevisionTree(self.branch.repository, inv,
360
# FIXME? RBC 20060403 should we cache the inventory here ?
359
361
return self.branch.repository.revision_tree(revision_id)
1024
1026
self.branch.unlock()
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'
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)
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.
1041
This is used to allow WorkingTree3 instances to not affect branch
1042
when their last revision is set.
1039
1044
if new_revision is None:
1040
1045
self.branch.set_revision_history([])
1051
1056
def _cache_basis_inventory(self, new_revision):
1052
1057
"""Cache new_revision as the basis inventory."""
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
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)
1068
path = self._basis_inventory_name()
1056
1069
self._control_files.put_utf8(path, xml)
1057
1070
except WeaveRevisionNotPresent:
1060
def _remove_old_basis(self, old_revision):
1061
"""Remove the old basis inventory 'old_revision'."""
1062
if old_revision is not None:
1064
path = self._basis_inventory_name(old_revision)
1065
path = self._control_files._escape(path)
1066
self._control_files._transport.delete(path)
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()
1075
1078
@needs_read_lock