# HG changeset patch # User Durham Goode # Date 1395700700 25200 # Node ID 925c2d6043890e64c26b2b802a2e681f2464c5b2 # Parent cd03854a2e060179eae490a00560dca9c5c4eba9 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. diff -r cd03854a2e06 -r 925c2d604389 mercurial/localrepo.py --- a/mercurial/localrepo.py Mon Mar 24 15:31:47 2014 -0700 +++ b/mercurial/localrepo.py Mon Mar 24 15:38:20 2014 -0700 @@ -2021,26 +2021,36 @@ handled_bytes = 0 self.ui.progress(_('clone'), 0, total=total_bytes) start = time.time() - for i in xrange(total_files): - # XXX doesn't support '\n' or '\r' in filenames - l = fp.readline() - try: - name, size = l.split('\0', 1) - size = int(size) - except (ValueError, TypeError): - raise error.ResponseError( - _('unexpected response from remote server:'), l) - if self.ui.debugflag: - self.ui.debug('adding %s (%s)\n' % - (name, util.bytecount(size))) - # for backwards compat, name was partially encoded - ofp = self.sopener(store.decodedir(name), 'w') - for chunk in util.filechunkiter(fp, limit=size): - handled_bytes += len(chunk) - self.ui.progress(_('clone'), handled_bytes, - total=total_bytes) - ofp.write(chunk) - ofp.close() + + tr = self.transaction(_('clone')) + try: + for i in xrange(total_files): + # XXX doesn't support '\n' or '\r' in filenames + l = fp.readline() + try: + name, size = l.split('\0', 1) + size = int(size) + except (ValueError, TypeError): + raise error.ResponseError( + _('unexpected response from remote server:'), l) + if self.ui.debugflag: + self.ui.debug('adding %s (%s)\n' % + (name, util.bytecount(size))) + # for backwards compat, name was partially encoded + ofp = self.sopener(store.decodedir(name), 'w') + for chunk in util.filechunkiter(fp, limit=size): + handled_bytes += len(chunk) + self.ui.progress(_('clone'), handled_bytes, + total=total_bytes) + ofp.write(chunk) + ofp.close() + tr.close() + finally: + tr.release() + + # Writing straight to files circumvented the inmemory caches + self.invalidate() + elapsed = time.time() - start if elapsed <= 0: elapsed = 0.001