Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/changegroup.py @ 5370:61462e7d62ed
changegroup: avoid large copies
- handle chunk headers separately rather than prepending them to
(potentially large) chunks
- break large chunks into 1M pieces for compression
- don't prepend file metadata onto (potentially large) file data
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 03 Oct 2007 17:17:28 -0500 |
parents | e0793314360e |
children |
comparison
equal
deleted
inserted
replaced
5369:7530334bf301 | 5370:61462e7d62ed |
---|---|
31 c = getchunk(source) | 31 c = getchunk(source) |
32 if not c: | 32 if not c: |
33 break | 33 break |
34 yield c | 34 yield c |
35 | 35 |
36 def genchunk(data): | 36 def chunkheader(length): |
37 """build a changegroup chunk""" | 37 """build a changegroup chunk header""" |
38 header = struct.pack(">l", len(data)+ 4) | 38 return struct.pack(">l", length + 4) |
39 return "%s%s" % (header, data) | |
40 | 39 |
41 def closechunk(): | 40 def closechunk(): |
42 return struct.pack(">l", 0) | 41 return struct.pack(">l", 0) |
43 | 42 |
44 class nocompress(object): | 43 class nocompress(object): |
84 empty = False | 83 empty = False |
85 while not empty: | 84 while not empty: |
86 empty = True | 85 empty = True |
87 for chunk in chunkiter(cg): | 86 for chunk in chunkiter(cg): |
88 empty = False | 87 empty = False |
89 fh.write(z.compress(genchunk(chunk))) | 88 fh.write(z.compress(chunkheader(len(chunk)))) |
89 pos = 0 | |
90 while pos < len(chunk): | |
91 next = pos + 2**20 | |
92 fh.write(z.compress(chunk[pos:next])) | |
93 pos = next | |
90 fh.write(z.compress(closechunk())) | 94 fh.write(z.compress(closechunk())) |
91 fh.write(z.flush()) | 95 fh.write(z.flush()) |
92 cleanup = None | 96 cleanup = None |
93 return filename | 97 return filename |
94 finally: | 98 finally: |