Implement smart-apply-patch.sh from Hadoop