Upstream import hg@726eae4
Adapt patches to new custom version