Show More
@@ -9,18 +9,22 b' from i18n import _' | |||
|
9 | 9 | import util |
|
10 | 10 | import struct, os, bz2, zlib, tempfile |
|
11 | 11 | |
|
12 | def getchunk(source): | |
|
13 | """return the next chunk from changegroup 'source' as a string""" | |
|
14 |
|
|
|
12 | def readexactly(stream, n): | |
|
13 | '''read n bytes from stream.read and abort if less was available''' | |
|
14 | s = stream.read(n) | |
|
15 | if len(s) < n: | |
|
16 | raise util.Abort(_("stream ended unexpectedly" | |
|
17 | " (got %d bytes, expected %d)") | |
|
18 | % (len(s), n)) | |
|
19 | return s | |
|
20 | ||
|
21 | def getchunk(stream): | |
|
22 | """return the next chunk from stream as a string""" | |
|
23 | d = readexactly(stream, 4) | |
|
15 | 24 | l = struct.unpack(">l", d)[0] |
|
16 | 25 | if l <= 4: |
|
17 | 26 | return "" |
|
18 | d = source.read(l - 4) | |
|
19 | if len(d) < l - 4: | |
|
20 | raise util.Abort(_("premature EOF reading chunk" | |
|
21 | " (got %d bytes, expected %d)") | |
|
22 | % (len(d), l - 4)) | |
|
23 | return d | |
|
27 | return readexactly(stream, l - 4) | |
|
24 | 28 | |
|
25 | 29 | def chunkheader(length): |
|
26 | 30 | """return a changegroup chunk header (string)""" |
@@ -145,7 +149,7 b' class unbundle10(object):' | |||
|
145 | 149 | return self._stream.close() |
|
146 | 150 | |
|
147 | 151 | def chunklength(self): |
|
148 |
d = self. |
|
|
152 | d = readexactly(self._stream, 4) | |
|
149 | 153 | l = max(0, struct.unpack(">l", d)[0] - 4) |
|
150 | 154 | if l and self.callback: |
|
151 | 155 | self.callback() |
@@ -154,20 +158,15 b' class unbundle10(object):' | |||
|
154 | 158 | def chunk(self): |
|
155 | 159 | """return the next chunk from changegroup 'source' as a string""" |
|
156 | 160 | l = self.chunklength() |
|
157 | d = self.read(l) | |
|
158 | if len(d) < l: | |
|
159 | raise util.Abort(_("premature EOF reading chunk" | |
|
160 | " (got %d bytes, expected %d)") | |
|
161 | % (len(d), l)) | |
|
162 | return d | |
|
161 | return readexactly(self._stream, l) | |
|
163 | 162 | |
|
164 | 163 | def parsechunk(self): |
|
165 | 164 | l = self.chunklength() |
|
166 | 165 | if not l: |
|
167 | 166 | return {} |
|
168 |
h = self. |
|
|
167 | h = readexactly(self._stream, 80) | |
|
169 | 168 | node, p1, p2, cs = struct.unpack("20s20s20s20s", h) |
|
170 |
data = self. |
|
|
169 | data = readexactly(self._stream, l - 80) | |
|
171 | 170 | return dict(node=node, p1=p1, p2=p2, cs=cs, data=data) |
|
172 | 171 | |
|
173 | 172 | class headerlessfixup(object): |
@@ -178,12 +177,12 b' class headerlessfixup(object):' | |||
|
178 | 177 | if self._h: |
|
179 | 178 | d, self._h = self._h[:n], self._h[n:] |
|
180 | 179 | if len(d) < n: |
|
181 |
d += self._fh |
|
|
180 | d += readexactly(self._fh, n - len(d)) | |
|
182 | 181 | return d |
|
183 |
return self._fh |
|
|
182 | return readexactly(self._fh, n) | |
|
184 | 183 | |
|
185 | 184 | def readbundle(fh, fname): |
|
186 |
header = fh |
|
|
185 | header = readexactly(fh, 6) | |
|
187 | 186 | |
|
188 | 187 | if not fname: |
|
189 | 188 | fname = "stream" |
General Comments 0
You need to be logged in to leave comments.
Login now