Browse Source

Support author/committer timezones.

Jelmer Vernooij 16 years ago
parent
commit
657bfe9a17
3 changed files with 32 additions and 2 deletions
  1. 2 0
      dulwich/object_store.py
  2. 24 2
      dulwich/objects.py
  3. 6 0
      dulwich/tests/test_objects.py

+ 2 - 0
dulwich/object_store.py

@@ -295,5 +295,7 @@ def tree_lookup_path(object_store, root_sha, path):
         obj = object_store[sha]
         if type(obj) is not Tree:
             raise NotTreeError(sha)
+        if p == '':
+            continue
         mode, sha = obj[p]
     return object_store[sha]

+ 24 - 2
dulwich/objects.py

@@ -435,7 +435,14 @@ class Commit(ShaFile):
                 count += 1
             self._author += text[count]
             count += 1
+            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])
+            while text[count] != ' ':
+                count += 1
+            self._author_timezone = int(text[count:count+6])
+            count += 1
             while text[count] != '\n':
                 count += 1
             count += 1
@@ -456,6 +463,10 @@ class Commit(ShaFile):
                  "commiter information must be followed by space not %s" % text[count]
             count += 1
             self._commit_time = int(text[count:count+10])
+            while text[count] != ' ':
+                count += 1
+            self._commit_timezone = int(text[count:count+6])
+            count += 1
             while text[count] != '\n':
                 count += 1
             count += 1
@@ -469,8 +480,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 +0000\n" % (AUTHOR_ID, self._author, str(self._author_time))
-        self._text += "%s %s %s +0000\n" % (COMMITTER_ID, self._committer, str(self._commit_time))
+        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 += "\n" # There must be a new line after the headers
         self._text += self._message
 
@@ -507,6 +518,12 @@ class Commit(ShaFile):
         """
         return self._commit_time
 
+    @property
+    def commit_timezone(self):
+        """Returns the zone the commit time is in
+        """
+        return self._commit_timezone
+
     @property
     def author_time(self):
         """Returns the timestamp the commit was written.
@@ -515,6 +532,11 @@ class Commit(ShaFile):
         """
         return self._author_time
 
+    @property
+    def author_timezone(self):
+        """Returns the zone the author time is in
+        """
+        return self._author_timezone
 
 
 type_map = {

+ 6 - 0
dulwich/tests/test_objects.py

@@ -105,6 +105,8 @@ class BlobReadTests(unittest.TestCase):
         self.assertEqual(c.committer,
             'James Westby <jw+debian@jameswestby.net>')
         self.assertEqual(c.commit_time, 1174759230)
+        self.assertEqual(c.commit_timezone, 0)
+        self.assertEqual(c.author_timezone, 0)
         self.assertEqual(c.message, 'Test commit\n')
   
     def test_read_commit_no_parents(self):
@@ -117,6 +119,8 @@ class BlobReadTests(unittest.TestCase):
         self.assertEqual(c.committer,
             'James Westby <jw+debian@jameswestby.net>')
         self.assertEqual(c.commit_time, 1174758034)
+        self.assertEqual(c.commit_timezone, 0)
+        self.assertEqual(c.author_timezone, 0)
         self.assertEqual(c.message, 'Test commit\n')
   
     def test_read_commit_two_parents(self):
@@ -130,5 +134,7 @@ class BlobReadTests(unittest.TestCase):
         self.assertEqual(c.committer,
             'James Westby <jw+debian@jameswestby.net>')
         self.assertEqual(c.commit_time, 1174773719)
+        self.assertEqual(c.commit_timezone, 0)
+        self.assertEqual(c.author_timezone, 0)
         self.assertEqual(c.message, 'Merge ../b\n')