2
0
Эх сурвалжийг харах

Use raw_length in pack generation.

Jelmer Vernooij 15 жил өмнө
parent
commit
f97d50a2dc

+ 3 - 3
dulwich/objects.py

@@ -214,12 +214,12 @@ class ShaFile(object):
         shafile.set_raw_string(string)
         return shafile
 
-    def _raw_length(self):
+    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, self._raw_length())
+        return "%s %lu\0" % (self._type, self.raw_length())
 
     def _make_sha(self):
         ret = make_sha()
@@ -303,7 +303,7 @@ class Blob(ShaFile):
     def _serialize(self):
         self._text = "".join(self._chunked)
 
-    def _raw_length(self):
+    def raw_length(self):
         ret = 0
         for chunk in self.chunked:
             ret += len(chunk)

+ 1 - 1
dulwich/pack.py

@@ -848,7 +848,7 @@ def write_pack_data(f, objects, num_objects, window=10):
     # This helps us find good objects to diff against us
     magic = []
     for obj, path in recency:
-        magic.append( (obj.type, path, 1, -len(obj.as_raw_string()), obj) )
+        magic.append( (obj.type, path, 1, -obj.raw_length(), obj) )
     magic.sort()
     # Build a map of objects and their index in magic - so we can find preceeding objects
     # to diff against

+ 1 - 1
dulwich/tests/test_objects.py

@@ -194,7 +194,7 @@ class CommitSerializationTests(unittest.TestCase):
 
     def test_raw_length(self):
         c = self.make_base()
-        self.assertEquals(len(c.as_raw_string()), c._raw_length())
+        self.assertEquals(len(c.as_raw_string()), c.raw_length())
 
     def test_simple(self):
         c = self.make_base()