git: Allow an explicit length to be set for the SHA-1 hash.

I want to name AWS AMI images based on the git version, and I think it will be good to allow an explicit length to be set for the SHA-1 hash.

For the same use case, I would like to send another PR to make sure `before` and `after` are set in all non-fail returns. The hg module currently does that, but the git module doesn't. Please advise if the change would be desirable.