Split next_backup_dir into several smaller functions

The functionality of getting the most recent backup number is
conceptually separate and will be useful for implementing latest.

It's also useful to turn a revnum into the corresponding file path.