Rework the way we process snapshots and branches
The previous code uses a brittle double-iteration and would break in a subtle way when having several branches pointing at the same target. Surprisingly, we didn't notice it before, even though most snapshots have a HEAD and refs/heads/master branch pointing to the same object.
I've also added FIXMEs for things I noticed should be changed in the long run.
Depends on !54 (closed)
Test Plan
the test case has been updated to exert the issue in the old code
Migrated from D417 (view on Phabricator)