Merge "applypatch: Refactor applypatch()."