diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index d93be951a3..d6eda2b688 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1667,6 +1667,41 @@ vc-checkin backend patch-string)) +(declare-function diff-apply-hunk "diff-mode" (&optional reverse)) + +(defun vc-default-checkin-patch (backend patch-string comment) + (with-current-buffer (get-buffer-create " *vc-checkin-patch*") + (erase-buffer) + (insert patch-string) + (diff-mode) + (pcase-let ((`(,backend ,files) (diff-vc-deduce-fileset)) + (root (vc-call-backend backend 'root default-directory)) + (tmpdir (make-temp-file "vc-checkin-patch" t))) + (dolist (f files) + (copy-file (expand-file-name f root) + (expand-file-name f tmpdir))) + (unwind-protect + (let ((default-directory root)) + (dolist (f files) + (with-current-buffer (get-file-buffer f) + (vc-revert-file f) + (revert-buffer t t t))) + (goto-char (point-min)) + (while (not (eobp)) + (diff-apply-hunk)) + (dolist (f files) + (with-current-buffer (get-file-buffer f) + (save-buffer 0))) + (vc-checkin files backend comment)) + (dolist (f files) + (copy-file (expand-file-name f tmpdir) + (expand-file-name f root) + t) + (with-current-buffer (get-file-buffer f) + (revert-buffer t t t)) + (delete-directory tmpdir t)) + (bury-buffer))))) + ;;; Additional entry points for examining version histories ;; (defun vc-default-diff-tree (backend dir rev1 rev2)