Rev 2508: Delay reading fields until in parse loop in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

John Arbash Meinel john at arbash-meinel.com
Fri May 4 23:29:15 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

------------------------------------------------------------
revno: 2508
revision-id: john at arbash-meinel.com-20070504222904-6f6i8yxr9qpf8lpw
parent: john at arbash-meinel.com-20070504221204-d9mjz2nl8fd5maxp
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate_pyrex
timestamp: Fri 2007-05-04 17:29:04 -0500
message:
  Delay reading fields until in parse loop
modified:
  bzrlib/compiled/dirstate_helpers.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
-------------- next part --------------
=== modified file 'bzrlib/compiled/dirstate_helpers.pyx'
--- a/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 22:12:04 +0000
+++ b/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 22:29:04 +0000
@@ -248,7 +248,7 @@
         )])
 
 
-cdef void _parse_dirblocks_0_parents(object state, object fields,
+cdef void _parse_dirblocks_0_parents(object state, object reader,
                                      int entry_size):
     cdef object current_block
     cdef object entry
@@ -257,10 +257,12 @@
     cdef int field_count
     cdef int pos
 
+    # Ignore the first record
+    fields = reader.get_all_fields()
     if not PyList_CheckExact(fields):
         raise TypeError('fields must be a list')
 
-    pos = 1
+    pos = 0
     field_count = len(fields)
 
     state._dirblocks = [('', []), ('', [])]
@@ -315,6 +317,15 @@
         """Get the next field as a Python string."""
         return PyString_FromString(self.get_next())
 
+    def get_n_fields(self, count):
+        cdef int i
+
+        fields = []
+        for i from 0 <= i < count:
+            PyList_Append(fields, self.get_next_str())
+        assert len(fields) == count
+        return fields
+
     def get_all_fields(self):
         """Get a list of all fields"""
         cdef char *first
@@ -352,17 +363,20 @@
     text = state._state_file.read()
     # TODO: check the crc checksums. crc_measured = zlib.crc32(text)
 
-    # reader = Reader(text)
+    reader = Reader(text)
 
     num_present_parents = state._num_present_parents()
     entry_size = state._fields_per_entry()
 
-    # fields = reader.get_all_fields()
-    fields = text.split('\0')
-    fields.pop()
+    if num_present_parents == 0:
+        # Move the iterator to the current position
+        _parse_dirblocks_0_parents(state, reader, entry_size)
+        state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
+        return
+    fields = reader.get_all_fields()
 
     # skip the first field which is the trailing null from the header.
-    cur = 1
+    cur = 0
 
     # Each line now has an extra '\n' field which is not used
     # so we just skip over it
@@ -373,20 +387,14 @@
     num_entries = state._num_entries
     expected_field_count = entry_size * num_entries
     field_count = len(fields)
-    if (field_count - cur) != expected_field_count:
+    if field_count - cur != expected_field_count:
         # this checks our adjustment, and also catches file too short.
         raise AssertionError(
             'field count incorrect %s != %s, entry_size=%s, '
             'num_entries=%s fields=%r' % (
-                (field_count - cur), expected_field_count, entry_size,
+                field_count - cur, expected_field_count, entry_size,
                 state._num_entries, fields))
 
-    if num_present_parents == 0:
-        # Move the iterator to the current position
-        #fields = reader.get_all_fields()
-        _parse_dirblocks_0_parents(state, fields, entry_size)
-        state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
-        return
     if num_present_parents == 1:
         # Bind external functions to local names
         _int = int



More information about the bazaar-commits mailing list