Browse Source

Avoid storing all objects in memory when writing pack.

Jelmer Vernooij 13 years ago
parent
commit
64923e5d03
2 changed files with 20 additions and 11 deletions
  1. 5 0
      NEWS
  2. 15 11
      dulwich/pack.py

+ 5 - 0
NEWS

@@ -1,5 +1,10 @@
 0.8.0	UNRELEASED
 
+ BUG FIXES
+
+  * Avoid storing all objects in memory when writing pack.
+    (Jelmer Vernooij, #813268)
+
  API CHANGES
 
   * write_pack_data and write_pack no longer take a num_objects argument.

+ 15 - 11
dulwich/pack.py

@@ -1168,21 +1168,25 @@ def write_pack_data(f, objects, num_objects=None, window=10):
     if num_objects is not None:
         warnings.warn("num_objects argument to write_pack_data is deprecated",
                       DeprecationWarning)
+        # Previously it was possible to pass in an iterable
+        objects = list(objects)
     else:
         num_objects = len(objects)
+
     # FIXME: Somehow limit delta depth
     # FIXME: Make thin-pack optional (its not used when cloning a pack)
-    # Build a list of objects ordered by the magic Linus heuristic
-    # This helps us find good objects to diff against us
-    magic = []
-    for obj, path in objects:
-        magic.append( (obj.type_num, 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
-    offs = {}
-    for i in range(len(magic)):
-        offs[magic[i][4]] = i
+    # # Build a list of objects ordered by the magic Linus heuristic
+    # # This helps us find good objects to diff against us
+    # magic = []
+    # for obj, path in objects:
+    #     magic.append( (obj.type_num, 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
+    # offs = {}
+    # for i in range(len(magic)):
+    #     offs[magic[i][4]] = i
+
     # Write the pack
     entries = []
     f = SHA1Writer(f)