Improvements to hg-to-git script

Portability fixes regarding environment variables and removing files.
Performance and correctness fixes around reading metadata and branching.
Override autocrlf so that a binary-identical files are committed.
Other small bug fixes.
Small refactorings.