cherry-pick an upstream patch to fix --compare issues