Parcourir la source

Add ShaFile._raw_length.

Jelmer Vernooij il y a 15 ans
Parent
commit
d6eefc6144
2 fichiers modifiés avec 9 ajouts et 1 suppressions
  1. 5 1
      dulwich/objects.py
  2. 4 0
      dulwich/tests/test_objects.py

+ 5 - 1
dulwich/objects.py

@@ -213,8 +213,12 @@ class ShaFile(object):
         shafile.set_raw_string(string)
         return shafile
 
+    def _raw_length(self):
+        """Returns the length of the raw string of this object."""
+        return len(self.as_raw_string())
+
     def _header(self):
-        return "%s %lu\0" % (self._type, len(self.as_raw_string()))
+        return "%s %lu\0" % (self._type, self._raw_length())
 
     def sha(self):
         """The SHA1 object that is the name of this object."""

+ 4 - 0
dulwich/tests/test_objects.py

@@ -180,6 +180,10 @@ class CommitSerializationTests(unittest.TestCase):
         c1.set_raw_string(c.as_raw_string())
         self.assertEquals(30, c1.commit_time)
 
+    def test_raw_length(self):
+        c = self.make_base()
+        self.assertEquals(len(c.as_raw_string()), c._raw_length())
+
     def test_simple(self):
         c = self.make_base()
         self.assertEquals(c.id, '5dac377bdded4c9aeb8dff595f0faeebcc8498cc')