]> arthur.barton.de Git - bup.git/commitdiff
Send SHAs from the client to reduce server load
authorBrandon Low <lostlogic@lostlogicx.com>
Sun, 2 Jan 2011 08:49:23 +0000 (00:49 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 3 Jan 2011 03:10:53 +0000 (19:10 -0800)
Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
cmd/server-cmd.py
lib/bup/client.py

index 299e28dda9a1de76896cda171ffce4a1bdc13db1..b7272f4db0efc23c6538385fa1607749889c0d47 100755 (executable)
@@ -67,14 +67,14 @@ def receive_objects(conn, junk):
             conn.ok()
             return
             
+        sha = conn.read(20)
+        n -= 20
         buf = conn.read(n)  # object sizes in bup are reasonably small
         #debug2('read %d bytes\n' % n)
         if len(buf) < n:
             w.abort()
             raise Exception('object read: expected %d bytes, got %d\n'
                             % (n, len(buf)))
-        (type, content) = git._decode_packobj(buf)
-        sha = git.calc_hash(type, content)
         oldpack = w.exists(sha)
         # FIXME: we only suggest a single index per cycle, because the client
         # is currently too dumb to download more than one per cycle anyway.
index d1fdbbe155851563f026fc03d83e990b20cf1f26..f9d940e973eb56bc579530a384516224eff6ce16 100644 (file)
@@ -271,7 +271,7 @@ class PackWriter_Remote(git.PackWriter):
     def abort(self):
         raise GitError("don't know how to abort remote pack writing")
 
-    def _raw_write(self, datalist):
+    def _raw_write(self, datalist, sha=''):
         assert(self.file)
         if not self._packopen:
             self._open()
@@ -279,7 +279,7 @@ class PackWriter_Remote(git.PackWriter):
             self.ensure_busy()
         data = ''.join(datalist)
         assert(len(data))
-        outbuf = struct.pack('!I', len(data)) + data
+        outbuf = ''.join((struct.pack('!I', len(data)+len(sha)), sha, data))
         (self._bwcount, self._bwtime) = \
             _raw_write_bwlimit(self.file, outbuf, self._bwcount, self._bwtime)
         self.outbytes += len(data)
@@ -292,3 +292,11 @@ class PackWriter_Remote(git.PackWriter):
             if self.suggest_pack:
                 self.suggest_pack(idxname)
                 self.objcache.refresh()
+
+    def _write(self, bin, type, content):
+        if git.verbose:
+            log('>')
+        sha = git.calc_hash(type, content)
+        enc = git._encode_packobj(type, content)
+        self._raw_write(enc, sha=sha)
+        return bin