Support the encoding field in commit messages.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 19 May 2009 18:26:40 +0000 (20:26 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 19 May 2009 18:26:40 +0000 (20:26 +0200)
dulwich/objects.py
dulwich/tests/test_objects.py

index fb43fd43340391c44247cb541e48d8c68ff2ccae..442adbacd41c8040a5d6763e9e3ee855f4d686e4 100644 (file)
@@ -49,6 +49,7 @@ COMMITTER_ID = "committer"
 OBJECT_ID = "object"
 TYPE_ID = "type"
 TAGGER_ID = "tagger"
+ENCODING_ID = "encoding"
 
 S_IFGITLINK    = 0160000
 def S_ISGITLINK(m):
@@ -491,6 +492,7 @@ class Commit(ShaFile):
     def __init__(self):
         super(Commit, self).__init__()
         self._parents = []
+        self._encoding = None
         self._needs_parsing = False
         self._needs_serialization = True
 
@@ -523,6 +525,8 @@ class Commit(ShaFile):
                 self._committer, timetext, timezonetext = value.rsplit(" ", 2)
                 self._commit_time = int(timetext)
                 self._commit_timezone = parse_timezone(timezonetext)
+            elif field == ENCODING_ID:
+                self._encoding = value
             else:
                 raise AssertionError("Unknown field %s" % field)
         self._message = f.read()
@@ -535,6 +539,8 @@ class Commit(ShaFile):
             f.write("%s %s\n" % (PARENT_ID, p))
         f.write("%s %s %s %s\n" % (AUTHOR_ID, self._author, str(self._author_time), format_timezone(self._author_timezone)))
         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))
         f.write("\n") # There must be a new line after the headers
         f.write(self._message)
         self._text = f.getvalue()
@@ -576,6 +582,9 @@ class Commit(ShaFile):
     author_timezone = serializable_property("author_timezone", 
         "Returns the zone the author time is in.")
 
+    encoding = serializable_property("encoding",
+        "Encoding of the commit message.")
+
 
 type_map = {
     BLOB_ID : Blob,
index 343f8ab30a7975f60e055f79edf1ac75085f92a6..39e10a7e1376b209a3c157a00e8740d462945dbe 100644 (file)
@@ -158,6 +158,11 @@ class CommitSerializationTests(unittest.TestCase):
         c.message =  'Merge ../b\n'
         return c
 
+    def test_encoding(self):
+        c = self.make_base()
+        c.encoding = "iso8859-1"
+        self.assertTrue("encoding iso8859-1\n" in c.as_raw_string())        
+
     def test_short_timestamp(self):
         c = self.make_base()
         c.commit_time = 30