Fix permission problems on Windows with large repositories

This uses a custom implementation of tmpfile() which works on Windows.
The problem was caused by io.tmpfile() and os.tmpname() returning
files in the root directory on Windows.
Normalize indentation in project