Use Git and Mercurial inbuilt commands to apply patch. Fixes #2563