Martin von Zweigbergk [off-list ref] writes:
I think
git merge-base HEAD $(git rev-list -g "$upstream_name")
is roughly correct and hopefully fast enough. That can lead to too
long a command line, so I was planning on teaching merge-base a
--stdin option, but never got around to it.
Sorry for coming in late.
I think the above with s/HEAD/$curr_branch/ is a good way to compute
what the whole "for reflog in $(git rev-list -g $remoteref" loop
computes when one of the historic tips recorded in the reflog was
where $curr_branch forked from, i.e. the loop actually finds at
least one ancestor in the reflog and breaks out after setting
oldremoteref. But it would give a completely different commit if
none of the reflog entries is a fork point.
A two patch series forthcoming.