Use separate function for tree parsing, allow C extension for tree parsing.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 30 Apr 2009 09:57:10 +0000 (09:59 +0002)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 30 Apr 2009 09:57:10 +0000 (09:59 +0002)
Makefile
dulwich/objects.py

index 4a1a544075512a749af95f463b1faedfff4b5cd3..a65b20439d79c00d25fa5540e78ce002aaac79ea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,11 +6,12 @@ all: build
 
 build::
        $(SETUP) build
+       $(SETUP) build_ext -i
 
 install::
        $(SETUP) install
 
-check::
+check:: build
        PYTHONPATH=. $(TRIAL) dulwich
 
 clean::
index c43bd0a82c1766d93843251d9d28760f8d596a67..3657029035db975c20b41b6699eee0c13a7b6da6 100644 (file)
@@ -328,6 +328,33 @@ class Tag(ShaFile):
         return self._message
 
 
+def parse_tree(text):
+    ret = []
+    count = 0
+    while count < len(text):
+        mode = 0
+        chr = text[count]
+        while chr != ' ':
+            assert chr >= '0' and chr <= '7', "%s is not a valid mode char" % chr
+            mode = (mode << 3) + (ord(chr) - ord('0'))
+            count += 1
+            chr = text[count]
+        count += 1
+        chr = text[count]
+        name = ''
+        while chr != '\0':
+            name += chr
+            count += 1
+            chr = text[count]
+        count += 1
+        chr = text[count]
+        sha = text[count:count+20]
+        hexsha = sha_to_hex(sha)
+        ret.append((mode, name, hexsha))
+        count = count + 20
+    return ret
+
+
 class Tree(ShaFile):
     """A Git tree object"""
 
@@ -368,28 +395,7 @@ class Tree(ShaFile):
 
     def _parse_text(self):
         """Grab the entries in the tree"""
-        count = 0
-        while count < len(self._text):
-            mode = 0
-            chr = self._text[count]
-            while chr != ' ':
-                assert chr >= '0' and chr <= '7', "%s is not a valid mode char" % chr
-                mode = (mode << 3) + (ord(chr) - ord('0'))
-                count += 1
-                chr = self._text[count]
-            count += 1
-            chr = self._text[count]
-            name = ''
-            while chr != '\0':
-                name += chr
-                count += 1
-                chr = self._text[count]
-            count += 1
-            chr = self._text[count]
-            sha = self._text[count:count+20]
-            hexsha = sha_to_hex(sha)
-            self.add(mode, name, hexsha)
-            count = count + 20
+        self._entries = parse_tree(self._text)
 
     def serialize(self):
         self._text = ""
@@ -456,6 +462,7 @@ class Commit(ShaFile):
             count += 1
             self._author_time = int(text[count:count+10])
             while text[count] != ' ':
+                assert text[count] != '\n', "Malformed author information"
                 count += 1
             self._author_timezone = int(text[count:count+6])
             count += 1
@@ -480,6 +487,7 @@ class Commit(ShaFile):
             count += 1
             self._commit_time = int(text[count:count+10])
             while text[count] != ' ':
+                assert text[count] != '\n', "Malformed committer information"
                 count += 1
             self._commit_timezone = int(text[count:count+6])
             count += 1
@@ -573,7 +581,7 @@ num_type_map = {
 
 try:
     # Try to import C versions
-    from dulwich._objects import hex_to_sha, sha_to_hex
+    from dulwich._objects import hex_to_sha, sha_to_hex, parse_tree
 except ImportError:
     pass