浏览代码

Add separate functions for formatting / parsing timezones.

Jelmer Vernooij 16 年之前
父节点
当前提交
2a4a3f5de9
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      dulwich/objects.py

+ 12 - 4
dulwich/objects.py

@@ -453,6 +453,14 @@ class Tree(ShaFile):
         return text
 
 
+def parse_timezone(text):
+    return int(text)
+
+
+def format_timezone(text):
+    return "%+04d" % text
+
+
 class Commit(ShaFile):
     """A git commit object"""
 
@@ -516,7 +524,7 @@ class Commit(ShaFile):
             while text[count] != ' ':
                 assert text[count] != '\n', "Malformed author information"
                 count += 1
-            self._author_timezone = int(text[count:count+6])
+            self._author_timezone = parse_timezone(text[count:count+6])
             count += 1
             while text[count] != '\n':
                 count += 1
@@ -541,7 +549,7 @@ class Commit(ShaFile):
             while text[count] != ' ':
                 assert text[count] != '\n', "Malformed committer information"
                 count += 1
-            self._commit_timezone = int(text[count:count+6])
+            self._commit_timezone = parse_timezone(text[count:count+6])
             count += 1
             while text[count] != '\n':
                 count += 1
@@ -557,8 +565,8 @@ class Commit(ShaFile):
         self._text += "%s %s\n" % (TREE_ID, self._tree)
         for p in self._parents:
             self._text += "%s %s\n" % (PARENT_ID, p)
-        self._text += "%s %s %s %+05d\n" % (AUTHOR_ID, self._author, str(self._author_time), self._author_timezone)
-        self._text += "%s %s %s %+05d\n" % (COMMITTER_ID, self._committer, str(self._commit_time), self._commit_timezone)
+        self._text += "%s %s %s %s\n" % (AUTHOR_ID, self._author, str(self._author_time), format_timezone(self._author_timezone))
+        self._text += "%s %s %s %s\n" % (COMMITTER_ID, self._committer, str(self._commit_time), format_timezone(self._commit_timezone))
         self._text += "\n" # There must be a new line after the headers
         self._text += self._message
         self._needs_serialization = False