##// 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 def generatev1(repo):
164 def generatev1(repo):
165 """Emit content for version 1 of a streaming clone.
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
169 The data iterator consists of N entries for each file being transferred.
170 number of entries and total bytes size.
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 The raw file data follows. Following the raw file data is the next file
173 The raw file data follows. Following the raw file data is the next file
175 entry, or EOF.
174 entry, or EOF.
176
175
@@ -196,31 +195,44 b' def generatev1(repo):'
196
195
197 repo.ui.debug('%d files, %d bytes to transfer\n' %
196 repo.ui.debug('%d files, %d bytes to transfer\n' %
198 (len(entries), total_bytes))
197 (len(entries), total_bytes))
199 yield '%d %d\n' % (len(entries), total_bytes)
200
198
201 svfs = repo.svfs
199 svfs = repo.svfs
202 oldaudit = svfs.mustaudit
200 oldaudit = svfs.mustaudit
203 debugflag = repo.ui.debugflag
201 debugflag = repo.ui.debugflag
204 svfs.mustaudit = False
202 svfs.mustaudit = False
205
203
206 try:
204 def emitrevlogdata():
207 for name, size in entries:
205 try:
208 if debugflag:
206 for name, size in entries:
209 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
207 if debugflag:
210 # partially encode name over the wire for backwards compat
208 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
211 yield '%s\0%d\n' % (store.encodedir(name), size)
209 # partially encode name over the wire for backwards compat
212 if size <= 65536:
210 yield '%s\0%d\n' % (store.encodedir(name), size)
213 fp = svfs(name)
211 if size <= 65536:
214 try:
212 fp = svfs(name)
215 data = fp.read(size)
213 try:
216 finally:
214 data = fp.read(size)
217 fp.close()
215 finally:
218 yield data
216 fp.close()
219 else:
217 yield data
220 for chunk in util.filechunkiter(svfs(name), limit=size):
218 else:
221 yield chunk
219 for chunk in util.filechunkiter(svfs(name), limit=size):
222 finally:
220 yield chunk
223 svfs.mustaudit = oldaudit
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 def consumev1(repo, fp, filecount, bytecount):
237 def consumev1(repo, fp, filecount, bytecount):
226 """Apply the contents from version 1 of a streaming clone file handle.
238 """Apply the contents from version 1 of a streaming clone file handle.
@@ -718,7 +718,7 b' def stream(repo, proto):'
718 try:
718 try:
719 # LockError may be raised before the first result is yielded. Don't
719 # LockError may be raised before the first result is yielded. Don't
720 # emit output until we're sure we got the lock successfully.
720 # emit output until we're sure we got the lock successfully.
721 it = streamclone.generatev1(repo)
721 it = streamclone.generatev1wireproto(repo)
722 return streamres(getstream(it))
722 return streamres(getstream(it))
723 except error.LockError:
723 except error.LockError:
724 return '2\n'
724 return '2\n'
General Comments 0
You need to be logged in to leave comments. Login now