comparison mercurial/streamclone.py @ 6782:b9d6ab187523

streamclone yields chunks instead of accepting a file-like object
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sun, 29 Jun 2008 14:20:01 +0200
parents f67d1468ac50
children 8ff321a381d0
comparison
equal deleted inserted replaced
6781:b4b7261164d5 6782:b9d6ab187523
49 # server writes out line that says file name, how many bytes in 49 # server writes out line that says file name, how many bytes in
50 # file. separator is ascii nul, byte count is string. 50 # file. separator is ascii nul, byte count is string.
51 # 51 #
52 # server writes out raw file data. 52 # server writes out raw file data.
53 53
54 def stream_out(repo, fileobj, untrusted=False): 54 def stream_out(repo, untrusted=False):
55 '''stream out all metadata files in repository. 55 '''stream out all metadata files in repository.
56 writes to file-like object, must support write() and optional flush().''' 56 writes to file-like object, must support write() and optional flush().'''
57 57
58 if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted): 58 if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
59 fileobj.write('1\n') 59 yield '1\n'
60 return 60 return
61 61
62 # get consistent snapshot of repo. lock during scan so lock not 62 # get consistent snapshot of repo. lock during scan so lock not
63 # needed while we stream, and commits can happen. 63 # needed while we stream, and commits can happen.
64 repolock = None 64 repolock = None
65 try: 65 try:
66 try: 66 try:
67 repolock = repo.lock() 67 repolock = repo.lock()
68 except (lock.LockHeld, lock.LockUnavailable), inst: 68 except (lock.LockHeld, lock.LockUnavailable), inst:
69 repo.ui.warn('locking the repository failed: %s\n' % (inst,)) 69 repo.ui.warn('locking the repository failed: %s\n' % (inst,))
70 fileobj.write('2\n') 70 yield '2\n'
71 return 71 return
72 72
73 fileobj.write('0\n') 73 yield '0\n'
74 repo.ui.debug('scanning\n') 74 repo.ui.debug('scanning\n')
75 entries = [] 75 entries = []
76 total_bytes = 0 76 total_bytes = 0
77 for name, size in walkrepo(repo.spath): 77 for name, size in walkrepo(repo.spath):
78 name = repo.decodefn(util.pconvert(name)) 78 name = repo.decodefn(util.pconvert(name))
81 finally: 81 finally:
82 del repolock 82 del repolock
83 83
84 repo.ui.debug('%d files, %d bytes to transfer\n' % 84 repo.ui.debug('%d files, %d bytes to transfer\n' %
85 (len(entries), total_bytes)) 85 (len(entries), total_bytes))
86 fileobj.write('%d %d\n' % (len(entries), total_bytes)) 86 yield '%d %d\n' % (len(entries), total_bytes)
87 for name, size in entries: 87 for name, size in entries:
88 repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) 88 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
89 fileobj.write('%s\0%d\n' % (name, size)) 89 yield '%s\0%d\n' % (name, size)
90 for chunk in util.filechunkiter(repo.sopener(name), limit=size): 90 for chunk in util.filechunkiter(repo.sopener(name), limit=size):
91 fileobj.write(chunk) 91 yield chunk
92 flush = getattr(fileobj, 'flush', None)
93 if flush: flush()