Improve finding commit for changeset number

Because commits can be shared across branches, it is better to do a single
search starting from the branches than to do a search for each branch
separately. The revision walking implemented in the git library will take
care of efficiently enumerating the graph, not visiting shared commits
multiple times.