Rev 2934: (robertc) Use a dictionary to obtain stat caches rather than digging into the dirstate on every path. (Robert Collins) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Oct 24 08:28:03 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2934
revision-id: pqm at pqm.ubuntu.com-20071024072800-p2qtv2632xrbrs02
parent: pqm at pqm.ubuntu.com-20071024064813-wjcmv8ofabf6kdrb
parent: robertc at robertcollins.net-20071024055927-m6ce9f0g9i2eshmk
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-10-24 08:28:00 +0100
message:
  (robertc) Use a dictionary to obtain stat caches rather than digging into the dirstate on every path. (Robert Collins)
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 2929.1.2
    merged: robertc at robertcollins.net-20071024055927-m6ce9f0g9i2eshmk
    parent: robertc at robertcollins.net-20071024002950-5gri1p7b9m8t821c
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: workingtree
    timestamp: Wed 2007-10-24 15:59:27 +1000
    message:
      Review feedback.
    ------------------------------------------------------------
    revno: 2929.1.1
    merged: 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 file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-10-23 23:01:26 +0000
+++ b/bzrlib/dirstate.py	2007-10-24 07:28:00 +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[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-24 06:48:13 +0000
+++ b/bzrlib/workingtree_4.py	2007-10-24 07:28:00 +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