# HG changeset patch # User Dirkjan Ochtman # Date 1279311610 -7200 # Node ID 31d0a6d50ee2a3facaac487becdaf2f483256bb8 # Parent 1d48681b17a42bc912552c961e148ff6440957d2 protocol: extract compression from streaming mechanics diff -r 1d48681b17a4 -r 31d0a6d50ee2 mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py Fri Jul 16 18:18:35 2010 +0200 +++ b/mercurial/hgweb/protocol.py Fri Jul 16 22:20:10 2010 +0200 @@ -35,22 +35,21 @@ def redirect(self): self.oldio = sys.stdout, sys.stderr sys.stderr = sys.stdout = cStringIO.StringIO() - def sendresponse(self, s): - self.req.respond(HTTP_OK, HGTYPE, length=len(s)) - self.response = s - def sendchangegroup(self, cg): - self.req.respond(HTTP_OK, HGTYPE) + def groupchunks(self, cg): z = zlib.compressobj() while 1: chunk = cg.read(4096) if not chunk: break - self.req.write(z.compress(chunk)) - self.req.write(z.flush()) + yield z.compress(chunk) + yield z.flush() + def sendresponse(self, s): + self.req.respond(HTTP_OK, HGTYPE, length=len(s)) + self.response = s def sendstream(self, source): self.req.respond(HTTP_OK, HGTYPE) for chunk in source: - self.req.write(chunk) + self.req.write(str(chunk)) def sendpushresponse(self, ret): val = sys.stdout.getvalue() sys.stdout, sys.stderr = self.oldio diff -r 1d48681b17a4 -r 31d0a6d50ee2 mercurial/sshserver.py --- a/mercurial/sshserver.py Fri Jul 16 18:18:35 2010 +0200 +++ b/mercurial/sshserver.py Fri Jul 16 22:20:10 2010 +0200 @@ -59,18 +59,16 @@ def redirect(self): pass - def sendresponse(self, v): - self.fout.write("%d\n" % len(v)) - self.fout.write(v) - self.fout.flush() - - def sendchangegroup(self, changegroup): + def groupchunks(self, changegroup): while True: d = changegroup.read(4096) if not d: break - self.fout.write(d) + yield d + def sendresponse(self, v): + self.fout.write("%d\n" % len(v)) + self.fout.write(v) self.fout.flush() def sendstream(self, source): diff -r 1d48681b17a4 -r 31d0a6d50ee2 mercurial/wireproto.py --- a/mercurial/wireproto.py Fri Jul 16 18:18:35 2010 +0200 +++ b/mercurial/wireproto.py Fri Jul 16 22:20:10 2010 +0200 @@ -173,13 +173,13 @@ def changegroup(repo, proto, roots): nodes = decodelist(roots) cg = repo.changegroup(nodes, 'serve') - proto.sendchangegroup(cg) + proto.sendstream(proto.groupchunks(cg)) def changegroupsubset(repo, proto, bases, heads): bases = decodelist(bases) heads = decodelist(heads) cg = repo.changegroupsubset(bases, heads, 'serve') - proto.sendchangegroup(cg) + proto.sendstream(proto.groupchunks(cg)) def heads(repo, proto): h = repo.heads() @@ -215,10 +215,7 @@ return '%s\n' % int(r) def stream(repo, proto): - try: - proto.sendstream(streamclone.stream_out(repo)) - except streamclone.StreamException, inst: - return str(inst) + proto.sendstream(streamclone.stream_out(repo)) def unbundle(repo, proto, heads): their_heads = decodelist(heads)