I'm not entirely sure my fix is the way to go, I've been reading source code for a good couple of hours so I may have lost track somewhere along the way. Regardless, working on this gave me an opportunity to better understand Mercurial internals so I won't consider this to be a complete waste of time :)