Bladeren bron

Cope with timestamps not always being 10 characters long.

Jelmer Vernooij 16 jaren geleden
bovenliggende
commit
722067ed4b
2 gewijzigde bestanden met toevoegingen van 13 en 2 verwijderingen
  1. 6 2
      dulwich/objects.py
  2. 7 0
      dulwich/tests/test_objects.py

+ 6 - 2
dulwich/objects.py

@@ -543,10 +543,12 @@ class Commit(ShaFile):
             assert text[count] == ' ', "Invalid commit object, " \
                  "author information must be followed by space not %s" % text[count]
             count += 1
-            self._author_time = int(text[count:count+10])
+            time_text = ''
             while text[count] != ' ':
                 assert text[count] != '\n', "Malformed author information"
+                time_text += text[count]
                 count += 1
+            self._author_time = int(time_text)
             self._author_timezone = parse_timezone(text[count:count+6])
             count += 1
             while text[count] != '\n':
@@ -568,10 +570,12 @@ class Commit(ShaFile):
             assert text[count] == ' ', "Invalid commit object, " \
                  "commiter information must be followed by space not %s" % text[count]
             count += 1
-            self._commit_time = int(text[count:count+10])
+            time_text = ""
             while text[count] != ' ':
                 assert text[count] != '\n', "Malformed committer information"
+                time_text += text[count]
                 count += 1
+            self._commit_time = int(time_text)
             self._commit_timezone = parse_timezone(text[count:count+6])
             count += 1
             while text[count] != '\n':

+ 7 - 0
dulwich/tests/test_objects.py

@@ -158,6 +158,13 @@ class CommitSerializationTests(unittest.TestCase):
         c.message =  'Merge ../b\n'
         return c
 
+    def test_short_timestamp(self):
+        c = self.make_base()
+        c.commit_time = 30
+        c1 = Commit()
+        c1.set_raw_string(c.as_raw_string())
+        self.assertEquals(30, c1.commit_time)
+
     def test_simple(self):
         c = self.make_base()
         self.assertEquals(c.id, '5dac377bdded4c9aeb8dff595f0faeebcc8498cc')