Browse Source

Use standard pack write functions in daemon.

Jelmer Vernooij 16 năm trước cách đây
mục cha
commit
55542024ed
3 tập tin đã thay đổi với 8 bổ sung18 xóa
  1. 3 13
      bin/dul-daemon
  2. 4 4
      dulwich/pack.py
  3. 1 1
      dulwich/tests/test_pack.py

+ 3 - 13
bin/dul-daemon

@@ -20,10 +20,10 @@
 import os, sys, tempfile, struct
 from dulwich.server import Backend, TCPGitServer
 from dulwich.repo import Repo
-from dulwich.pack import PackData, Pack
+from dulwich.pack import PackData, Pack, write_pack_data
 
 import sha
-from dulwich.pack import write_pack_object
+
 class PackWriteWrapper(object):
 
     def __init__(self, write):
@@ -121,17 +121,7 @@ class GitBackend(Backend):
 
         progress("counting objects: %d, done.\n" % len(sha_queue))
 
-        w = PackWriteWrapper(write)
-        w.write("PACK")
-        w.write(struct.pack(">L", 2))
-        w.write(struct.pack(">L", len(sha_queue)))
-
-        for t, sha in sha_queue:
-            ty, obj = self.repo.get_object(sha).as_raw_string()
-            write_pack_object(w, t, obj)
-
-        # send sha1 of pack
-        write(w.digest)
+        write_pack_data(write, (self.repo.get_object(sha).as_raw_string() for sha in sha_queue))
 
         progress("how was that, then?\n")
 

+ 4 - 4
dulwich/pack.py

@@ -528,16 +528,16 @@ def write_pack_object(f, type, object):
     return f.tell()
 
 
-def write_pack(filename, objects):
+def write_pack(filename, objects, num_objects):
     f = open(filename + ".pack", 'w')
     try:
-        entries, data_sum = write_pack_data(f, objects)
+        entries, data_sum = write_pack_data(f, objects, num_objects)
     except:
         f.close()
     write_pack_index_v2(filename + ".idx", entries, data_sum)
 
 
-def write_pack_data(f, objects):
+def write_pack_data(f, objects, num_objects):
     """Write a new pack file.
 
     :param filename: The filename of the new pack file.
@@ -548,7 +548,7 @@ def write_pack_data(f, objects):
     f = SHA1Writer(f)
     f.write("PACK")               # Pack header
     f.write(struct.pack(">L", 2)) # Pack version
-    f.write(struct.pack(">L", len(objects))) # Number of objects in pack
+    f.write(struct.pack(">L", num_objects)) # Number of objects in pack
     for o in objects:
         sha1 = o.sha().digest()
         crc32 = o.crc32()

+ 1 - 1
dulwich/tests/test_pack.py

@@ -162,7 +162,7 @@ class TestPack(PackTests):
 
     def test_copy(self):
         p = self.get_pack(pack1_sha)
-        write_pack("testcopy", list(p.iterobjects()))
+        write_pack("testcopy", p.iterobjects(), len(p))
         self.assertEquals(p, Pack("testcopy"))
 
     def test_commit_obj(self):