Move & adapt .hgignore to .gitignore
Rework version retrieval code from Hg to Git-compatible

This is partially based on the changes contained in
e2e8d007c743020a32314ca1a4487382f0556618