-P: put the repo code into a function, as it's used twice.