comparison mercurial/localrepo.py @ 20880:925c2d604389

clone: put streaming clones in a transaction Streaming clones were writing to files outside of a transaction. Soon the fncache will be written at transaction close time, so we need streaming clones to be in a transaction.
author Durham Goode <durham@fb.com>
date Mon, 24 Mar 2014 15:38:20 -0700
parents ca5dd216cb62
children cd443c7589cc
comparison
equal deleted inserted replaced
20879:cd03854a2e06 20880:925c2d604389
2019 self.ui.status(_('%d files to transfer, %s of data\n') % 2019 self.ui.status(_('%d files to transfer, %s of data\n') %
2020 (total_files, util.bytecount(total_bytes))) 2020 (total_files, util.bytecount(total_bytes)))
2021 handled_bytes = 0 2021 handled_bytes = 0
2022 self.ui.progress(_('clone'), 0, total=total_bytes) 2022 self.ui.progress(_('clone'), 0, total=total_bytes)
2023 start = time.time() 2023 start = time.time()
2024 for i in xrange(total_files): 2024
2025 # XXX doesn't support '\n' or '\r' in filenames 2025 tr = self.transaction(_('clone'))
2026 l = fp.readline() 2026 try:
2027 try: 2027 for i in xrange(total_files):
2028 name, size = l.split('\0', 1) 2028 # XXX doesn't support '\n' or '\r' in filenames
2029 size = int(size) 2029 l = fp.readline()
2030 except (ValueError, TypeError): 2030 try:
2031 raise error.ResponseError( 2031 name, size = l.split('\0', 1)
2032 _('unexpected response from remote server:'), l) 2032 size = int(size)
2033 if self.ui.debugflag: 2033 except (ValueError, TypeError):
2034 self.ui.debug('adding %s (%s)\n' % 2034 raise error.ResponseError(
2035 (name, util.bytecount(size))) 2035 _('unexpected response from remote server:'), l)
2036 # for backwards compat, name was partially encoded 2036 if self.ui.debugflag:
2037 ofp = self.sopener(store.decodedir(name), 'w') 2037 self.ui.debug('adding %s (%s)\n' %
2038 for chunk in util.filechunkiter(fp, limit=size): 2038 (name, util.bytecount(size)))
2039 handled_bytes += len(chunk) 2039 # for backwards compat, name was partially encoded
2040 self.ui.progress(_('clone'), handled_bytes, 2040 ofp = self.sopener(store.decodedir(name), 'w')
2041 total=total_bytes) 2041 for chunk in util.filechunkiter(fp, limit=size):
2042 ofp.write(chunk) 2042 handled_bytes += len(chunk)
2043 ofp.close() 2043 self.ui.progress(_('clone'), handled_bytes,
2044 total=total_bytes)
2045 ofp.write(chunk)
2046 ofp.close()
2047 tr.close()
2048 finally:
2049 tr.release()
2050
2051 # Writing straight to files circumvented the inmemory caches
2052 self.invalidate()
2053
2044 elapsed = time.time() - start 2054 elapsed = time.time() - start
2045 if elapsed <= 0: 2055 if elapsed <= 0:
2046 elapsed = 0.001 2056 elapsed = 0.001
2047 self.ui.progress(_('clone'), None) 2057 self.ui.progress(_('clone'), None)
2048 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % 2058 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %