directory: Build snapshot with git ref name
Otherwise, we'd lose the context in the snapshot. Except for the case of commit.
This also adds other commits:
- 1 which drops a redundant catch and raise exception instruction.
- 1 which moves from local to global imports (to unify with other base code)
Refs. swh/meta#4979 (closed)
Edited by Antoine R. Dumont