Mercurial > hg-stable
diff 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 |
line wrap: on
line diff
--- 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