Proper remerge algorithm

The previous implementation suffered in a number of ways, most notably that
it merged the tip of the topic branch, which isn't desirable---if
development has continued in the topic branch, then we wouldn't want those
changes.

This will now, for each merge commit in the provided ref, gather a list of
commits that were merged into $ref and determine the branch from which it
originated (as long as the remote branch still exists); it will then take
the commit with the most recent timestamp and will end up re-merging that
commit rather than the tip of the branch.

This process takes considerably longer than the initial approach, but it
actually does something sane.