sha1-name: refactor get_sha1() parsing

Instead of parsing left to right, do it right do left, this way it is
much more natural and probably efficient too, as there's less
recursivity.

In theory there shouldn't be any functional changes, although there's at
least one error message that has changed.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>