private void applyPatch(SinglePatch patch, boolean dryRun) throws IOException, PatchException {
        lastPatchedLine = 1;
        List<String> target;
        patch.targetFile = computeTargetFile(patch);
        if (patch.targetFile.exists() && !patch.binary) {
            target = readFile(patch.targetFile);
            if (patchCreatesNewFileThatAlreadyExists(patch, target)) return;
        } else {
            target = new ArrayList<String>();
        }
        if (patch.mode==Mode.DELETE) {
            target = new ArrayList<String>();
        } else {
            if (!patch.binary) {
                for (Hunk hunk : patch.hunks) {
                    applyHunk(target, hunk);
                }
            }
        }
        if (!dryRun) {
            backup(patch.targetFile);
            writeFile(patch, target);
        }
    }