updated regex to match hg revision
even more refactoring - ready for tests