I've pushed a variant of this patch as af8f7eb4f2a664c2d0fb3faabaf2e80c72993ef6