Rev 3715: Some Cification of iter_changes, and making the python one actually work. in http://people.ubuntu.com/~robertc/baz2.0/readdir

Robert Collins robertc at robertcollins.net
Thu Sep 18 02:37:53 BST 2008


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

------------------------------------------------------------
revno: 3715
revision-id: robertc at robertcollins.net-20080918013747-izkrcep6wirb5kil
parent: robertc at robertcollins.net-20080918011607-pt2s2la3r1vlncvr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: process-entry-optimised
timestamp: Thu 2008-09-18 11:37:47 +1000
message:
  Some Cification of iter_changes, and making the python one actually work.
modified:
  bzrlib/_dirstate_helpers_c.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/test__dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
=== modified file 'bzrlib/_dirstate_helpers_c.pyx'
--- a/bzrlib/_dirstate_helpers_c.pyx	2008-09-18 01:16:07 +0000
+++ b/bzrlib/_dirstate_helpers_c.pyx	2008-09-18 01:37:47 +0000
@@ -1013,7 +1013,7 @@
         self.root_dir_info = None
         self.bisect_left = bisect.bisect_left
 
-    def _process_entry(self, entry, path_info):
+    cdef _process_entry(self, entry, path_info):
         """Compare an entry and real disk to generate delta information.
 
         :param path_info: top_relpath, basename, kind, lstat, abspath for
@@ -1349,14 +1349,14 @@
         #       keeping a cache of directories that we have seen.
         cdef object current_dirname, current_blockname
         cdef char * current_dirname_c, * current_blockname_c
-        _process_entry = self._process_entry
+        cdef int advance_entry, advance_path
         uninteresting = self.uninteresting
         searched_specific_files = self.searched_specific_files
         # Are we walking a root?
         while self.root_entries_pos < self.root_entries_len:
             entry = self.root_entries[self.root_entries_pos]
             self.root_entries_pos = self.root_entries_pos + 1
-            result = _process_entry(entry, self.root_dir_info)
+            result = self._process_entry(entry, self.root_dir_info)
             if result is not None and result is not self.uninteresting:
                 return result
         # Have we finished the prior root, or never started one ?
@@ -1407,7 +1407,7 @@
             while self.root_entries_pos < self.root_entries_len:
                 entry = self.root_entries[self.root_entries_pos]
                 self.root_entries_pos = self.root_entries_pos + 1
-                result = _process_entry(entry, self.root_dir_info)
+                result = self._process_entry(entry, self.root_dir_info)
                 if result is not None:
                     self.path_handled = -1
                     if result is not self.uninteresting:
@@ -1551,16 +1551,15 @@
                         self.current_block_pos = self.current_block_pos + 1
                         # entry referring to file not present on disk.
                         # advance the entry only, after processing.
-                        result = _process_entry(current_entry, None)
+                        result = self._process_entry(current_entry, None)
                         if result is not None:
                             if result is not self.uninteresting:
                                 return result
                     self.block_index = self.block_index + 1
                     self._update_current_block()
                 continue # next loop-on-block/dir
-            # current_dir_info and current_block refer to the same directory.
-            advance_entry = True
-            advance_path = True
+            # current_dir_info and current_block refer to the same directory -
+            # this is the common case code.
             # Assign local variables for current path and entry:
             if (self.current_block and
                 self.current_block_pos < len(self.current_block[1])):
@@ -1579,6 +1578,8 @@
                 current_path_info = None
             self.path_handled = 0
             while (current_entry is not None or current_path_info is not None):
+                advance_entry = -1
+                advance_path = -1
                 result = None
                 if current_entry is None:
                     # unversioned -  the check for path_handled when the path
@@ -1586,7 +1587,7 @@
                     pass
                 elif current_path_info is None:
                     # no path is fine: the per entry code will handle it.
-                    result = _process_entry(current_entry, current_path_info)
+                    result = self._process_entry(current_entry, current_path_info)
                     if result is not None:
                         if result is self.uninteresting:
                             result = None
@@ -1603,22 +1604,22 @@
                     if current_path_info[1] < current_entry[0][1]:
                         # extra file on disk: pass for now, but only
                         # increment the path, not the entry
-                        advance_entry = False
+                        advance_entry = 0
                     else:
                         # entry referring to file not present on disk.
                         # advance the entry only, after processing.
-                        result = _process_entry(current_entry, None)
+                        result = self._process_entry(current_entry, None)
                         if result is not None:
                             if result is self.uninteresting:
                                 result = None
-                        advance_path = False
+                        advance_path = 0
                 else:
-                    result = _process_entry(current_entry, current_path_info)
+                    result = self._process_entry(current_entry, current_path_info)
                     if result is not None:
                         self.path_handled = -1
                         if result is self.uninteresting:
                             result = None
-                # >- loop control
+                # >- loop control starts here:
                 # >- entry
                 if advance_entry and current_entry is not None:
                     self.current_block_pos = self.current_block_pos + 1
@@ -1626,8 +1627,6 @@
                         current_entry = self.current_block[1][self.current_block_pos]
                     else:
                         current_entry = None
-                else:
-                    advance_entry = True # reset the advance flaga
                 # >- path
                 if advance_path and current_path_info is not None:
                     if not self.path_handled:
@@ -1673,8 +1672,6 @@
                     else:
                         current_path_info = None
                     self.path_handled = 0
-                else:
-                    advance_path = True # reset the advance flag.
                 if result is not None:
                     # Found a result on this pass, yield it
                     return result

=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2008-09-18 01:16:07 +0000
+++ b/bzrlib/dirstate.py	2008-09-18 01:37:47 +0000
@@ -2730,7 +2730,7 @@
             raise errors.ObjectNotLocked(self)
 
 
-def _update_entry(self, entry, abspath, stat_value,
+def py_update_entry(self, entry, abspath, stat_value,
                  _stat_to_minikind=DirState._stat_to_minikind,
                  _pack_stat=pack_stat):
     """Update the entry based on what is actually on disk.
@@ -2802,6 +2802,7 @@
                            False, DirState.NULLSTAT)
     self._dirblock_state = DirState.IN_MEMORY_MODIFIED
     return link_or_sha1
+update_entry = py_update_entry
 
 
 class ProcessEntryPython(object):
@@ -2862,7 +2863,7 @@
         if path_info is not None and target_minikind in 'fdlt':
             if not (self.target_index == 0):
                 raise AssertionError()
-            link_or_sha1 = _update_entry(self.state, entry,
+            link_or_sha1 = update_entry(self.state, entry,
                 abspath=path_info[4], stat_value=path_info[3])
             # The entry may have been modified by update_entry
             target_details = entry[1][self.target_index]
@@ -2882,7 +2883,7 @@
                 # has.  TODO ? : only add if it is a container ?
                 if not osutils.is_inside_any(self.searched_specific_files,
                                              source_details[1]):
-                    search_specific_files.add(source_details[1])
+                    self.search_specific_files.add(source_details[1])
                 # generate the old path; this is needed for stating later
                 # as well.
                 old_path = source_details[1]
@@ -3081,7 +3082,7 @@
             # common case to rename dirs though, so a correct but slow
             # implementation will do.
             if not osutils.is_inside_any(self.searched_specific_files, target_details[1]):
-                search_specific_files.add(target_details[1])
+                self.search_specific_files.add(target_details[1])
         elif source_minikind in 'ra' and target_minikind in 'ra':
             # neither of the selected trees contain this file,
             # so skip over it. This is not currently directly tested, but
@@ -3227,7 +3228,7 @@
                 else:
                     if current_dir_info[0][0] == '':
                         # remove .bzr from iteration
-                        bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
+                        bzr_index = bisect.bisect_left(current_dir_info[1], ('.bzr',))
                         if current_dir_info[1][bzr_index][0] != '.bzr':
                             raise AssertionError()
                         del current_dir_info[1][bzr_index]

=== modified file 'bzrlib/tests/test__dirstate_helpers.py'
--- a/bzrlib/tests/test__dirstate_helpers.py	2008-09-18 01:16:07 +0000
+++ b/bzrlib/tests/test__dirstate_helpers.py	2008-09-18 01:37:47 +0000
@@ -768,6 +768,14 @@
             from bzrlib._dirstate_helpers_py import _read_dirblocks_py
             self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)
 
+    def test_update_entry(self):
+        if CompiledDirstateHelpersFeature.available():
+            from bzrlib._dirstate_helpers_c import update_entry
+            self.assertIs(update_entry, dirstate.update_entry)
+        else:
+            from bzrlib.dirstate import py_update_entry
+            self.assertIs(py_update_entry, dirstate.py_update_entry)
+
     def test_process_entry(self):
         if CompiledDirstateHelpersFeature.available():
             from bzrlib._dirstate_helpers_c import ProcessEntryC




More information about the bazaar-commits mailing list