This function is exclusively used in commitctx. So we should extract it too
for consistency and to reduce the localrepo bloat.
This is part of a larger refactoring/cleanup of the commitctx code to clarify
and augment the logic gathering metadata useful for copy tracing. The current
code is a tad too long and entangled to make such update easy.