Skip to content

Commit 993d21e

Browse files
committed
tweak(core): simple and efficient implementation of +apply-patch-dwim
1 parent 7c554af commit 993d21e

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

core/me-lib-extra.el

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,13 @@ When a region is active, propose to use it as the patch buffer."
380380
((length> results 1) (completing-read "Select a target directory: " results))
381381
(t (read-directory-name "Cannot deduce the target directory, select one: ")))))
382382
(when (y-or-n-p (format "Apply patch %S in directory %S?" (file-name-nondirectory (buffer-file-name patch-buf)) target-dir))
383-
;; Add the `+apply-patch-dwim-extra-options' to `ediff-patch-options'
384-
(require 'ediff-ptch) ; for `ediff-patch-options'
385-
(let ((ediff-patch-options (format "%s %s" ediff-patch-options +apply-patch-dwim-extra-options)))
386-
(run-hook-with-args '+apply-patch-dwim-pre-patch-functions patch-buf patch-files target-dir)
387-
;; Hackish way of forcing `ediff-patch-file' to use the `target-file-or-dir' without asking
388-
(cl-letf (((symbol-function 'read-file-name)
389-
(lambda (&rest args)
390-
(if (length= patch-files 2)
391-
(expand-file-name (caar candidates) target-dir)
392-
target-dir))))
393-
(ediff-patch-file nil patch-buf))
383+
(let ((default-directory target-dir)
384+
(out-buf (get-buffer-create " *apply-patch-dwim*"))
385+
(patch-file (with-current-buffer patch-buf
386+
(let ((temp-filename (make-temp-file "apply-patch-dwim-" nil ".patch")))
387+
(write-file temp-filename)
388+
temp-filename))))
389+
(shell-command (format "patch -p1 %s -i %S" +apply-patch-dwim-extra-options patch-file) out-buf out-buf)
394390
(run-hook-with-args '+apply-patch-dwim-post-patch-functions patch-buf patch-files target-dir))))))))
395391

396392
;;;###autoload

0 commit comments

Comments
 (0)