Don't create a temp reference for branch comparisons within project
A temp reference is only needed to fetch a branch from another project, as in the case for forked repositories. For branch comparisons within the same project, we can just use the existing branch names to do the comparison.
Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/38689#note_126107862
Results
Locally with a few more than 7 discussions it was taking 38 RPC requests (405ms). Now it's taking 19 RPC requests (61ms). Great improvements!
We'll have considerable improvements taking it along with https://gitlab.com/gitlab-org/gitlab-ce/issues/58297.
Edited by Oswaldo Ferreira