Skip to content

Commit

Permalink
Support the encoding field in commit messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed May 19, 2009
1 parent f9ca0eb commit 879786c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
OBJECT_ID = "object"
TYPE_ID = "type"
TAGGER_ID = "tagger"
ENCODING_ID = "encoding"

S_IFGITLINK = 0160000
def S_ISGITLINK(m):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -523,6 +525,8 @@ def _parse_text(self):
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()
Expand All @@ -535,6 +539,8 @@ def serialize(self):
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()
Expand Down Expand Up @@ -576,6 +582,9 @@ def set_parents(self, value):
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,
Expand Down
5 changes: 5 additions & 0 deletions dulwich/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def make_base(self):
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
Expand Down

0 comments on commit 879786c

Please sign in to comment.