Rev 2930: Use a dict to access stat cache information from dirstate. in http://people.ubuntu.com/~robertc/baz2.0/workingtree
Robert Collins
robertc at robertcollins.net
Wed Oct 24 01:29:56 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/workingtree
------------------------------------------------------------
revno: 2930
revision-id:robertc at robertcollins.net-20071024002950-5gri1p7b9m8t821c
parent: pqm at pqm.ubuntu.com-20071023082111-h6u34i4gvlb2nwch
committer: Robert Collins <robertc at robertcollins.net>
branch nick: workingtree
timestamp: Wed 2007-10-24 10:29:50 +1000
message:
Use a dict to access stat cache information from dirstate.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-10-22 20:05:12 +0000
+++ b/bzrlib/dirstate.py 2007-10-24 00:29:50 +0000
@@ -337,6 +337,8 @@
self._lock_token = None
self._lock_state = None
self._id_index = None
+ # a map from packed_stat to sha's.
+ self._packed_stat_index = None
self._end_of_header = None
self._cutoff_time = None
self._split_path_cache = {}
@@ -1641,6 +1643,20 @@
assert num_entries_line.startswith('num_entries: '), 'missing num_entries line'
self._num_entries = int(num_entries_line[len('num_entries: '):-1])
+ def sha1_from_stat(self, path, stat_result, _pack_stat=pack_stat):
+ """Find a sha1 given a stat lookup."""
+ return self._get_packed_stat_index().get(_pack_stat(stat_result), None)
+
+ def _get_packed_stat_index(self):
+ """Get a packed_stat index of self._dirblocks."""
+ if self._packed_stat_index is None:
+ index = {}
+ for key, tree_details in self._iter_entries():
+ if tree_details[0][0] == 'f':
+ index.setdefault(tree_details[0][4], tree_details[0][1])
+ self._packed_stat_index = index
+ return self._packed_stat_index
+
def save(self):
"""Save any pending changes created during this session.
@@ -1702,6 +1718,7 @@
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
self._parents = list(parent_ids)
self._id_index = None
+ self._packed_stat_index = None
def set_path_id(self, path, new_id):
"""Change the id of path to new_id in the current working tree.
@@ -1987,6 +2004,7 @@
current_old = advance(old_iterator)
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
self._id_index = None
+ self._packed_stat_index = None
def _make_absent(self, current_old):
"""Mark current_old - an entry - as absent for tree 0.
@@ -2295,6 +2313,7 @@
self._ghosts = []
self._dirblocks = []
self._id_index = None
+ self._packed_stat_index = None
self._end_of_header = None
self._cutoff_time = None
self._split_path_cache = {}
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-10-17 17:03:06 +0000
+++ b/bzrlib/workingtree_4.py 2007-10-24 00:29:50 +0000
@@ -1098,15 +1098,7 @@
:param path: The path.
:param stat_result: The stat result being looked up.
"""
- state = self.current_dirstate()
- # XXX: should we make the path be passed in as utf8 ?
- entry = state._get_entry(0, path_utf8=cache_utf8.encode(path))
- tree_details = entry[1][0]
- packed_stat = dirstate.pack_stat(stat_result)
- if tree_details[4] == packed_stat:
- return tree_details[1]
- else:
- return None
+ return self.current_dirstate().sha1_from_stat(path, stat_result)
@needs_read_lock
def supports_tree_reference(self):
More information about the bazaar-commits
mailing list