Versioning fixes

Hi,

Here's a first set of commits to do versioning (see PR #1025 for a draft of where I'm planning to take it next.)

Right now it's still not relying on command such as "git describe" but its building the internal infrastructure for it.

I'm also fixing a bug from PR #1045 where the git sha1 was only being generated when the tree was clean (please take a look @smarterclayton)

I'll try to do this in small steps, so let's get this one figured out first and I'll send a PR for the next step.

@lavalamp Can you please take a look? I think you're probably the best reviewer for this PR...

Thanks,
Filipe

Done. PTAL at the latest snapshot in this PR.