Pārlūkot izejas kodu

Pass chunks rather than full text to _parse_commit_or_tag.

Jelmer Vernooij 11 gadi atpakaļ
vecāks
revīzija
2218b43ffc
1 mainītis faili ar 12 papildinājumiem un 12 dzēšanām
  1. 12 12
      dulwich/objects.py

+ 12 - 12
dulwich/objects.py

@@ -579,15 +579,15 @@ class Blob(ShaFile):
         super(Blob, self).check()
 
 
-def _parse_tag_or_commit(text):
-    """Parse tag or commit text.
+def _parse_tag_or_commit(chunks):
+    """Parse tag or commit chunks.
 
-    :param text: the raw text of the tag or commit object.
+    :param chunks: the raw chunks of the tag or commit object.
     :return: iterator of tuples of (field, value), one per header line, in the
         order read from the text, possibly including duplicates. Includes a
         field named None for the freeform tag/commit text.
     """
-    f = StringIO(text)
+    f = StringIO("".join(chunks))
     k = None
     v = ""
     for l in f:
@@ -604,9 +604,9 @@ def _parse_tag_or_commit(text):
     f.close()
 
 
-def parse_tag(text):
+def parse_tag(chunks):
     """Parse a tag object."""
-    return _parse_tag_or_commit(text)
+    return _parse_tag_or_commit(chunks)
 
 
 class Tag(ShaFile):
@@ -649,7 +649,7 @@ class Tag(ShaFile):
             check_identity(self._tagger, "invalid tagger")
 
         last = None
-        for field, _ in parse_tag("".join(self._chunked_text)):
+        for field, _ in parse_tag(self._chunked_text):
             if field == _OBJECT_HEADER and last is not None:
                 raise ObjectFormatException("unexpected object")
             elif field == _TYPE_HEADER and last != _OBJECT_HEADER:
@@ -680,7 +680,7 @@ class Tag(ShaFile):
     def _deserialize(self, chunks):
         """Grab the metadata attached to the tag"""
         self._tagger = None
-        for field, value in parse_tag("".join(chunks)):
+        for field, value in parse_tag(chunks):
             if field == _OBJECT_HEADER:
                 self._object_sha = value
             elif field == _TYPE_HEADER:
@@ -1035,8 +1035,8 @@ def format_timezone(offset, unnecessary_negative_timezone=False):
     return '%c%02d%02d' % (sign, offset / 3600, (offset / 60) % 60)
 
 
-def parse_commit(text):
-    return _parse_tag_or_commit(text)
+def parse_commit(chunks):
+    return _parse_tag_or_commit(chunks)
 
 
 class Commit(ShaFile):
@@ -1071,7 +1071,7 @@ class Commit(ShaFile):
         self._parents = []
         self._extra = []
         self._author = None
-        for field, value in parse_commit(''.join(chunks)):
+        for field, value in parse_commit(chunks):
             if field == _TREE_HEADER:
                 self._tree = value
             elif field == _PARENT_HEADER:
@@ -1114,7 +1114,7 @@ class Commit(ShaFile):
         check_identity(self._committer, "invalid committer")
 
         last = None
-        for field, _ in parse_commit("".join(self._chunked_text)):
+        for field, _ in parse_commit(self._chunked_text):
             if field == _TREE_HEADER and last is not None:
                 raise ObjectFormatException("unexpected tree")
             elif field == _PARENT_HEADER and last not in (_PARENT_HEADER,