Mercurial > public > mercurial-scm > hg
comparison mercurial/changegroup.py @ 12335:e21fe9c5fb25
bundle: get rid of chunkiter
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 19 Sep 2010 12:51:54 -0500 |
parents | 50946802593d |
children | 9d234f7d8a77 |
comparison
equal
deleted
inserted
replaced
12334:50946802593d | 12335:e21fe9c5fb25 |
---|---|
21 if len(d) < l - 4: | 21 if len(d) < l - 4: |
22 raise util.Abort(_("premature EOF reading chunk" | 22 raise util.Abort(_("premature EOF reading chunk" |
23 " (got %d bytes, expected %d)") | 23 " (got %d bytes, expected %d)") |
24 % (len(d), l - 4)) | 24 % (len(d), l - 4)) |
25 return d | 25 return d |
26 | |
27 def chunkiter(source, progress=None): | |
28 """iterate through the chunks in source, yielding a sequence of chunks | |
29 (strings)""" | |
30 while 1: | |
31 c = getchunk(source) | |
32 if not c: | |
33 break | |
34 elif progress is not None: | |
35 progress() | |
36 yield c | |
37 | 26 |
38 def chunkheader(length): | 27 def chunkheader(length): |
39 """return a changegroup chunk header (string)""" | 28 """return a changegroup chunk header (string)""" |
40 return struct.pack(">l", length + 4) | 29 return struct.pack(">l", length + 4) |
41 | 30 |
92 z = compressor() | 81 z = compressor() |
93 | 82 |
94 # parse the changegroup data, otherwise we will block | 83 # parse the changegroup data, otherwise we will block |
95 # in case of sshrepo because we don't know the end of the stream | 84 # in case of sshrepo because we don't know the end of the stream |
96 | 85 |
97 # an empty chunkiter is the end of the changegroup | 86 # an empty chunkgroup is the end of the changegroup |
98 # a changegroup has at least 2 chunkiters (changelog and manifest). | 87 # a changegroup has at least 2 chunkgroups (changelog and manifest). |
99 # after that, an empty chunkiter is the end of the changegroup | 88 # after that, an empty chunkgroup is the end of the changegroup |
100 empty = False | 89 empty = False |
101 count = 0 | 90 count = 0 |
102 while not empty or count <= 2: | 91 while not empty or count <= 2: |
103 empty = True | 92 empty = True |
104 count += 1 | 93 count += 1 |
105 for chunk in chunkiter(cg): | 94 while 1: |
95 chunk = getchunk(cg) | |
96 if not chunk: | |
97 break | |
106 empty = False | 98 empty = False |
107 fh.write(z.compress(chunkheader(len(chunk)))) | 99 fh.write(z.compress(chunkheader(len(chunk)))) |
108 pos = 0 | 100 pos = 0 |
109 while pos < len(chunk): | 101 while pos < len(chunk): |
110 next = pos + 2**20 | 102 next = pos + 2**20 |
169 raise util.Abort(_("premature EOF reading chunk" | 161 raise util.Abort(_("premature EOF reading chunk" |
170 " (got %d bytes, expected %d)") | 162 " (got %d bytes, expected %d)") |
171 % (len(d), l)) | 163 % (len(d), l)) |
172 return d | 164 return d |
173 | 165 |
174 def chunks(self): | |
175 while 1: | |
176 c = self.chunk() | |
177 if not c: | |
178 break | |
179 yield c | |
180 | |
181 class headerlessfixup(object): | 166 class headerlessfixup(object): |
182 def __init__(self, fh, h): | 167 def __init__(self, fh, h): |
183 self._h = h | 168 self._h = h |
184 self._fh = fh | 169 self._fh = fh |
185 def read(self, n): | 170 def read(self, n): |