##// END OF EJS Templates
streamclone: move payload header generation into own function...
Gregory Szorc -
r26469:fb743268 default
parent child Browse files
Show More
@@ -164,13 +164,12 b' def _walkstreamfiles(repo):'
164 164 def generatev1(repo):
165 165 """Emit content for version 1 of a streaming clone.
166 166
167 This is a generator of raw chunks that constitute a streaming clone.
167 This returns a 3-tuple of (file count, byte size, data iterator).
168 168
169 The stream begins with a line of 2 space-delimited integers containing the
170 number of entries and total bytes size.
169 The data iterator consists of N entries for each file being transferred.
170 Each file entry starts as a line with the file name and integer size
171 delimited by a null byte.
171 172
172 Next, are N entries for each file being transferred. Each file entry starts
173 as a line with the file name and integer size delimited by a null byte.
174 173 The raw file data follows. Following the raw file data is the next file
175 174 entry, or EOF.
176 175
@@ -196,31 +195,44 b' def generatev1(repo):'
196 195
197 196 repo.ui.debug('%d files, %d bytes to transfer\n' %
198 197 (len(entries), total_bytes))
199 yield '%d %d\n' % (len(entries), total_bytes)
200 198
201 199 svfs = repo.svfs
202 200 oldaudit = svfs.mustaudit
203 201 debugflag = repo.ui.debugflag
204 202 svfs.mustaudit = False
205 203
206 try:
207 for name, size in entries:
208 if debugflag:
209 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
210 # partially encode name over the wire for backwards compat
211 yield '%s\0%d\n' % (store.encodedir(name), size)
212 if size <= 65536:
213 fp = svfs(name)
214 try:
215 data = fp.read(size)
216 finally:
217 fp.close()
218 yield data
219 else:
220 for chunk in util.filechunkiter(svfs(name), limit=size):
221 yield chunk
222 finally:
223 svfs.mustaudit = oldaudit
204 def emitrevlogdata():
205 try:
206 for name, size in entries:
207 if debugflag:
208 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
209 # partially encode name over the wire for backwards compat
210 yield '%s\0%d\n' % (store.encodedir(name), size)
211 if size <= 65536:
212 fp = svfs(name)
213 try:
214 data = fp.read(size)
215 finally:
216 fp.close()
217 yield data
218 else:
219 for chunk in util.filechunkiter(svfs(name), limit=size):
220 yield chunk
221 finally:
222 svfs.mustaudit = oldaudit
223
224 return len(entries), total_bytes, emitrevlogdata()
225
226 def generatev1wireproto(repo):
227 """Emit content for version 1 of streaming clone suitable for the wire.
228
229 This is the data output from ``generatev1()`` with a header line
230 indicating file count and byte size.
231 """
232 filecount, bytecount, it = generatev1(repo)
233 yield '%d %d\n' % (filecount, bytecount)
234 for chunk in it:
235 yield chunk
224 236
225 237 def consumev1(repo, fp, filecount, bytecount):
226 238 """Apply the contents from version 1 of a streaming clone file handle.
@@ -718,7 +718,7 b' def stream(repo, proto):'
718 718 try:
719 719 # LockError may be raised before the first result is yielded. Don't
720 720 # emit output until we're sure we got the lock successfully.
721 it = streamclone.generatev1(repo)
721 it = streamclone.generatev1wireproto(repo)
722 722 return streamres(getstream(it))
723 723 except error.LockError:
724 724 return '2\n'
General Comments 0
You need to be logged in to leave comments. Login now