浏览代码

pack: Factor out write_pack_header.

Dave Borowitz 14 年之前
父节点
当前提交
70305b65ff
共有 2 个文件被更改,包括 16 次插入6 次删除
  1. 2 0
      NEWS
  2. 14 6
      dulwich/pack.py

+ 2 - 0
NEWS

@@ -10,6 +10,8 @@
 
   * Web server supports streaming progress/pack output. (Dave Borowitz)
 
+  * New public function dulwich.pack.write_pack_header. (Dave Borowitz)
+
 
 0.6.1	2010-07-22
 

+ 14 - 6
dulwich/pack.py

@@ -1061,11 +1061,21 @@ def write_pack(filename, objects, num_objects):
         f.close()
 
 
+def write_pack_header(f, num_objects):
+    """Write a pack header for the given number of objects."""
+    f.write('PACK')                          # Pack header
+    f.write(struct.pack('>L', 2))            # Pack version
+    f.write(struct.pack('>L', num_objects))  # Number of objects in pack
+
+
 def write_pack_data(f, objects, num_objects, window=10):
-    """Write a new pack file.
+    """Write a new pack data file.
 
-    :param filename: The filename of the new pack file.
-    :param objects: List of objects to write (tuples with object and path)
+    :param f: File to write to
+    :param objects: Iterable over (object, path) tuples to write
+    :param num_objects: Number of objects to write
+    :param window: Sliding window size for searching for deltas; currently
+                   unimplemented
     :return: List with (name, offset, crc32 checksum) entries, pack checksum
     """
     recency = list(objects)
@@ -1085,9 +1095,7 @@ def write_pack_data(f, objects, num_objects, window=10):
     # Write the pack
     entries = []
     f = SHA1Writer(f)
-    f.write("PACK")               # Pack header
-    f.write(struct.pack(">L", 2)) # Pack version
-    f.write(struct.pack(">L", num_objects)) # Number of objects in pack
+    write_pack_header(f, num_objects)
     for o, path in recency:
         sha1 = o.sha().digest()
         orig_t = o.type_num