Add and adapt stuff from zplrepo/misc.