Sfoglia il codice sorgente

client: allow send_pack callers to override how packs are emitted

Sometimes, a client will already have a pack computed for the
(have, want) negotiated with the server. Rather than re-compute the
pack each time, we could instead allow the send_pack caller to handle
writing pack data themselves.

This patch leaves much of the send_pack structure intact by using
write_pack_objects as the default write strategy.
Mike Edgar 10 anni fa
parent
commit
2cb9191d2f
1 ha cambiato i file con 14 aggiunte e 6 eliminazioni
  1. 14 6
      dulwich/client.py

+ 14 - 6
dulwich/client.py

@@ -178,13 +178,15 @@ class GitClient(object):
             self._fetch_capabilities.remove('thin-pack')
 
     def send_pack(self, path, determine_wants, generate_pack_contents,
-                  progress=None):
+                  progress=None, write_pack=write_pack_objects):
         """Upload a pack to a remote repository.
 
         :param path: Repository path
         :param generate_pack_contents: Function that can return a sequence of
             the shas of the objects to upload.
         :param progress: Optional progress function
+        :param write_pack: Function called with (file, iterable of objects) to
+            write the objects returned by generate_pack_contents to the server.
 
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
@@ -426,13 +428,15 @@ class TraditionalGitClient(GitClient):
         raise NotImplementedError()
 
     def send_pack(self, path, determine_wants, generate_pack_contents,
-                  progress=None):
+                  progress=None, write_pack=write_pack_objects):
         """Upload a pack to a remote repository.
 
         :param path: Repository path
         :param generate_pack_contents: Function that can return a sequence of
             the shas of the objects to upload.
         :param progress: Optional callback called with progress updates
+        :param write_pack: Function called with (file, iterable of objects) to
+            write the objects returned by generate_pack_contents to the server.
 
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
@@ -487,7 +491,7 @@ class TraditionalGitClient(GitClient):
                                      for (ref, sha) in new_refs.iteritems()
                                      if sha != ZERO_SHA)
             if dowrite:
-                entries, sha = write_pack_objects(proto.write_file(), objects)
+                write_pack(proto.write_file(), objects)
 
             self._handle_receive_pack_tail(
                 proto, negotiated_capabilities, progress)
@@ -656,13 +660,15 @@ class LocalGitClient(GitClient):
         # Ignore the thin_packs argument
 
     def send_pack(self, path, determine_wants, generate_pack_contents,
-                  progress=None):
+                  progress=None, write_pack=write_pack_objects):
         """Upload a pack to a remote repository.
 
         :param path: Repository path
         :param generate_pack_contents: Function that can return a sequence of
             the shas of the objects to upload.
         :param progress: Optional progress function
+        :param write_pack: Function called with (file, iterable of objects) to
+            write the objects returned by generate_pack_contents to the server.
 
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
@@ -971,13 +977,15 @@ class HttpGitClient(GitClient):
         return resp
 
     def send_pack(self, path, determine_wants, generate_pack_contents,
-                  progress=None):
+                  progress=None, write_pack=write_pack_objects):
         """Upload a pack to a remote repository.
 
         :param path: Repository path
         :param generate_pack_contents: Function that can return a sequence of
             the shas of the objects to upload.
         :param progress: Optional progress function
+        :param write_pack: Function called with (file, iterable of objects) to
+            write the objects returned by generate_pack_contents to the server.
 
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
@@ -1004,7 +1012,7 @@ class HttpGitClient(GitClient):
             return new_refs
         objects = generate_pack_contents(have, want)
         if len(objects) > 0:
-            entries, sha = write_pack_objects(req_proto.write_file(), objects)
+            write_pack(req_proto.write_file(), objects)
         resp = self._smart_request("git-receive-pack", url,
                                    data=req_data.getvalue())
         try: