Rev 2853: Merge improved stat lookup during commit. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Wed Oct 24 01:56:43 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2853
revision-id:robertc at robertcollins.net-20071024005634-0lved66u59xd9vlt
parent: robertc at robertcollins.net-20071023222241-iuqmck10xc2vz6xr
parent: robertc at robertcollins.net-20071024002950-5gri1p7b9m8t821c
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Wed 2007-10-24 10:56:34 +1000
message:
  Merge improved stat lookup during commit.
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 2592.1.25.2.7.1.28.1.6.1.3.1.9.2.1.3.74.1.31.3.18.1.9.1.2.1.12.1.8.1.46.1.18.1.1.2.21.2.10.3.8.1.1
    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-23 22:14:32 +0000
+++ b/bzrlib/dirstate.py	2007-10-24 00:56:34 +0000
@@ -329,6 +329,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 = {}
@@ -1884,6 +1886,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.
 
@@ -1945,6 +1961,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.
@@ -2230,6 +2247,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.
@@ -2538,6 +2556,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-23 22:22:41 +0000
+++ b/bzrlib/workingtree_4.py	2007-10-24 00:56:34 +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