hg2git.py: Refactor main code into hg2git() function