From af81dfeb33e1a92f737bc0557a4fe5ce8cf80406 Mon Sep 17 00:00:00 2001 From: Brandon Low Date: Sun, 2 Jan 2011 00:49:23 -0800 Subject: [PATCH] Send SHAs from the client to reduce server load Signed-off-by: Brandon Low --- cmd/server-cmd.py | 4 ++-- lib/bup/client.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/server-cmd.py b/cmd/server-cmd.py index 299e28d..b7272f4 100755 --- a/cmd/server-cmd.py +++ b/cmd/server-cmd.py @@ -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. diff --git a/lib/bup/client.py b/lib/bup/client.py index d1fdbbe..f9d940e 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -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 -- 2.39.2