Ver Fonte

Don't allow setting custom headers, per the discussion on the git list.

Jelmer Vernooij há 15 anos atrás
pai
commit
12d7a5f078
2 ficheiros alterados com 8 adições e 15 exclusões
  1. 7 14
      dulwich/objects.py
  2. 1 1
      dulwich/tests/test_objects.py

+ 7 - 14
dulwich/objects.py

@@ -523,7 +523,7 @@ class Commit(ShaFile):
 
     def _parse_text(self):
         self._parents = []
-        self._extra = {}
+        self._extra = []
         self._author = None
         f = StringIO(self._text)
         for l in f:
@@ -547,9 +547,7 @@ class Commit(ShaFile):
             elif field == ENCODING_ID:
                 self._encoding = value
             else:
-                if field in self._extra:
-                    raise KeyError("%s already exists in extra" % field)
-                self._extra[field] = value
+                self._extra.append((field, value))
         self._message = f.read()
         self._needs_parsing = False
 
@@ -562,10 +560,10 @@ class Commit(ShaFile):
         f.write("%s %s %s %s\n" % (COMMITTER_ID, self._committer, str(self._commit_time), format_timezone(self._commit_timezone)))
         if self.encoding:
             f.write("%s %s\n" % (ENCODING_ID, self.encoding))
-        for k in sorted(self.extra.keys()):
-            if "\n" in k or "\n" in self.extra[k]:
-                raise AssertionError("newline in extra data: %r -> %r" % (k, self.extra[k]))
-            f.write("%s %s\n" % (k, self.extra[k]))
+        for k, v in self.extra:
+            if "\n" in k or "\n" in v:
+                raise AssertionError("newline in extra data: %r -> %r" % (k, v))
+            f.write("%s %s\n" % (k, v))
         f.write("\n") # There must be a new line after the headers
         f.write(self._message)
         self._text = f.getvalue()
@@ -591,12 +589,7 @@ class Commit(ShaFile):
         self._ensure_parsed()
         return self._extra
 
-    def set_extra(self, value):
-        self._ensure_parsed()
-        self._needs_serialization = True
-        self._extra = value
-
-    extra = property(get_extra, set_extra)
+    extra = property(get_extra)
 
     author = serializable_property("author",
         "The name of the author of the commit")

+ 1 - 1
dulwich/tests/test_objects.py

@@ -235,7 +235,7 @@ class CommitDeserializationTests(unittest.TestCase):
                 'extra-field data\n'
                 '\n'
                 'Merge ../b\n')
-        self.assertEquals('data', c.extra['extra-field'])
+        self.assertEquals([('extra-field', 'data')], c.extra)
 
 
 class TreeSerializationTests(unittest.TestCase):