Refactor "tracking statistics" code used by "git checkout"