remote: refactor the reference-update decision

This is an ugly chunk of code, so let's put it into its own function.