# HG changeset patch # User Dan Villiom Podlaski Christiansen <danchr@gmail.com> # Date 1600207993 -7200 # Wed Sep 16 00:13:13 2020 +0200 # Node ID ef16c92cdb3e1f7a09472c16a3c987aa85b50685 # Parent cc59977fec4d86f0bf3873448166d7e8097c3332 optimise writing the map file We currently write the map file to a BytesIO buffer, and _then_ write it to an atomic temporary file. However, the file is opened for atomic write, so the extra buffering doesn't really add anything other than overhead. diff --git a/hggit/git_handler.py b/hggit/git_handler.py --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -217,16 +217,11 @@ def save_map(self, map_file): wlock = self.repo.wlock() try: - file = self.vfs(map_file, b'w+', atomictemp=True) map_hg = self._map_hg - buf = io.BytesIO() - bwrite = buf.write - for hgsha, gitsha in compat.iteritems(map_hg): - bwrite(b"%s %s\n" % (gitsha, hgsha)) - file.write(buf.getvalue()) - buf.close() - # If this complains, atomictempfile no longer has close - file.close() + with self.vfs(map_file, b'wb+', atomictemp=True) as buf: + bwrite = buf.write + for hgsha, gitsha in compat.iteritems(map_hg): + bwrite(b"%s %s\n" % (gitsha, hgsha)) finally: wlock.release()