This optimizes the CreateChange call. On googlesource.com, we observed
that these calls were expensive when a SHA1 was given as merge source,
on one of our large repositories.
In practice, these SHA1s are the SHA1s of the merge commits that
Gerrit creates. These merge commits are not registered especially, so
Gerrit has to delve through all branches to prove visibility for the
caller.
However, the merge commit is always in the target branch of the
change, and that branch is a good candidate for visibility. Get that
branch data by looking through the index for parents of the merge
commit.
By adding rudimentary statistics in ObjectLoader.SmallObject, we can
see that this change reduces the amount of read small objects (ie.
commits) by a factor 200 in this case.
The added test provides coverage for the new code path: throwing an
exception from the added if makes it fail. There seems to be no way to
instrument the amount of Git data read in such calls.
Thanks to Patrick Hiesel for coming up with this idea.
Change-Id: I7329c819b4bce13251145d7dab25fbcb99dab04f