templater: restructure open_template() a little to prepare for relative paths
I found that it was easier to add support for relative paths after
this restructuring. It also made it easier to explain each case with a
code comment (which I did).
Differential Revision: https://phab.mercurial-scm.org/D8906