comparison mercurial/changegroup.py @ 12329:7458de933f26

bundle: push chunkbuffer down into decompress We replace the fixup iterator with a file-like object so that uncompressed file streams can be passed end to end through the stack.
author Matt Mackall <mpm@selenic.com>
date Fri, 17 Sep 2010 19:02:26 -0500
parents bcc7139521b7
children e527b8635881
comparison
equal deleted inserted replaced
12328:b63f6422d2a7 12329:7458de933f26
134 zd.decompress("BZ") 134 zd.decompress("BZ")
135 for chunk in util.filechunkiter(f, 4096): 135 for chunk in util.filechunkiter(f, 4096):
136 yield zd.decompress(chunk) 136 yield zd.decompress(chunk)
137 else: 137 else:
138 raise util.Abort("unknown bundle compression '%s'" % alg) 138 raise util.Abort("unknown bundle compression '%s'" % alg)
139 return generator(fh) 139 return util.chunkbuffer(generator(fh))
140 140
141 class unbundle10(object): 141 class unbundle10(object):
142 def __init__(self, fh, alg): 142 def __init__(self, fh, alg):
143 self._stream = util.chunkbuffer(decompressor(fh, alg)) 143 self._stream = decompressor(fh, alg)
144 self._type = alg 144 self._type = alg
145 def compressed(self): 145 def compressed(self):
146 return self._type != 'UN' 146 return self._type != 'UN'
147 def read(self, l): 147 def read(self, l):
148 return self._stream.read(l) 148 return self._stream.read(l)
149
150 class headerlessfixup(object):
151 def __init__(self, fh, h):
152 self._h = h
153 self._fh = fh
154 def read(self, n):
155 if self._h:
156 d, self._h = self._h[:n], self._h[n:]
157 if len(d) < n:
158 d += self._fh.read(n - len(d))
159 return d
160 return self._fh.read(n)
149 161
150 def readbundle(fh, fname): 162 def readbundle(fh, fname):
151 header = fh.read(6) 163 header = fh.read(6)
152 164
153 if not fname: 165 if not fname:
154 fname = "stream" 166 fname = "stream"
155 if not header.startswith('HG') and header.startswith('\0'): 167 if not header.startswith('HG') and header.startswith('\0'):
156 # headerless bundle, clean things up 168 fh = headerlessfixup(fh, header)
157 def fixup(f, h):
158 yield h
159 for x in f:
160 yield x
161 fh = fixup(fh, header)
162 header = "HG10UN" 169 header = "HG10UN"
163 170
164 magic, version, alg = header[0:2], header[2:4], header[4:6] 171 magic, version, alg = header[0:2], header[2:4], header[4:6]
165 172
166 if magic != 'HG': 173 if magic != 'HG':