diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 0bf7899246..50f68bef70 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2859,6 +2859,15 @@ diff-syntax-fontify-props (forward-line 1))) (nreverse props))) +;;;###autoload +(defun diff-vc-deduce-fileset () + (let ((backend (vc-responsible-backend default-directory)) + files) + (save-excursion + (goto-char (point-min)) + (while (progn (diff-file-next) (not (eobp))) + (push (diff-find-file-name nil t) files))) + (list backend (nreverse files) nil nil 'patch))) (defun diff--filter-substring (str) (when diff-font-lock-prettify diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index 5c664d58f1..d000e8eedc 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -653,15 +655,17 @@ vc-log-edit (mapcar (lambda (file) (file-relative-name file root)) ',fileset)))) - (log-edit-diff-function . vc-diff) + (log-edit-diff-function + . ,(if vc-patch-string 'vc-diff-patch 'vc-diff)) (log-edit-vc-backend . ,backend) - (vc-log-fileset . ,fileset)) + (vc-log-fileset . ,fileset) + (vc-patch-string . ,vc-patch-string)) nil mode) (set-buffer-modified-p nil) (setq buffer-file-name nil)) -(defun vc-start-logentry (files comment initial-contents msg logbuf mode action &optional after-hook backend) +(defun vc-start-logentry (files comment initial-contents msg logbuf mode action &optional after-hook backend patch-string) "Accept a comment for an operation on FILES. If COMMENT is nil, pop up a LOGBUF buffer, emit MSG, and set the action on close to ACTION. If COMMENT is a string and @@ -688,6 +692,7 @@ vc-start-logentry (setq-local vc-parent-buffer parent) (setq-local vc-parent-buffer-name (concat " from " (buffer-name vc-parent-buffer))) + (setq-local vc-patch-string patch-string) (vc-log-edit files mode backend) (make-local-variable 'vc-log-after-operation-hook) (when after-hook @@ -753,7 +758,8 @@ vc-finish-logentry (defun vc-dispatcher-browsing () "Are we in a directory browser buffer?" (or (derived-mode-p 'vc-dir-mode) - (derived-mode-p 'dired-mode))) + (derived-mode-p 'dired-mode) + (derived-mode-p 'diff-mode))) ;; These are unused. ;; (defun vc-dispatcher-in-fileset-p (fileset) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 208cbee0e6..aa8bf5ca44 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -53,7 +53,7 @@ ;; - responsible-p (file) OK ;; - receive-file (file rev) NOT NEEDED ;; - unregister (file) OK -;; * checkin (files rev comment) OK +;; * checkin (files comment rev patch-string) OK ;; * find-revision (file rev buffer) OK ;; * checkout (file &optional rev) OK ;; * revert (file &optional contents-done) OK @@ -921,7 +921,7 @@ vc-git-log-edit-mode "Major mode for editing Git log messages. It is based on `log-edit-mode', and has Git-specific extensions.") -(defun vc-git-checkin (files comment &optional _rev) +(defun vc-git-checkin (files comment &optional _rev patch-string) (let* ((file1 (or (car files) default-directory)) (root (vc-git-root file1)) (default-directory (expand-file-name root)) @@ -943,12 +943,20 @@ vc-git-checkin (if (eq system-type 'windows-nt) (let ((default-directory (file-name-directory file1))) (make-nearby-temp-file "git-msg"))))) + (when patch-string + (let ((patch-file (make-temp-file "git-patch"))) + (with-temp-file patch-file + (insert patch-string)) + (unwind-protect + (apply #'vc-git-command nil 0 patch-file + (list "apply" "--cached")) + (delete-file patch-file)))) (cl-flet ((boolean-arg-fn (argument) (lambda (value) (when (equal value "yes") (list argument))))) ;; When operating on the whole tree, better pass "-a" than ".", since "." ;; fails when we're committing a merge. - (apply #'vc-git-command nil 0 (if only files) + (apply #'vc-git-command nil 0 (if (and only (not patch-string)) files) (nconc (if msg-file (list "commit" "-F" (file-local-name msg-file)) (list "commit" "-m")) @@ -966,7 +974,8 @@ vc-git-checkin (write-region (car args) nil msg-file)) (setq args (cdr args))) args) - (if only (list "--only" "--") '("-a"))))) + (unless patch-string + (if only (list "--only" "--") '("-a")))))) (if (and msg-file (file-exists-p msg-file)) (delete-file msg-file)))) (defun vc-git-find-revision (file rev buffer) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index a6124acadd..6834de503f 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -239,7 +239,7 @@ ;; Unregister FILE from this backend. This is only needed if this ;; backend may be used as a "more local" backend for temporary editing. ;; -;; * checkin (files comment &optional rev) +;; * checkin (files comment &optional rev patch-string) ;; ;; Commit changes in FILES to this backend. COMMENT is used as a ;; check-in comment. The implementation should pass the value of @@ -1102,6 +1102,8 @@ vc-deduce-fileset-1 (vc-dir-deduce-fileset state-model-only-files)) ((derived-mode-p 'dired-mode) (dired-vc-deduce-fileset state-model-only-files not-state-changing)) + ((derived-mode-p 'diff-mode) + (diff-vc-deduce-fileset)) ((setq backend (vc-backend buffer-file-name)) (if state-model-only-files (list backend (list buffer-file-name) @@ -1114,7 +1116,8 @@ vc-deduce-fileset-1 (or (buffer-file-name vc-parent-buffer) (with-current-buffer vc-parent-buffer (or (derived-mode-p 'vc-dir-mode) - (derived-mode-p 'dired-mode))))) + (derived-mode-p 'dired-mode) + (derived-mode-p 'diff-mode))))) (progn ;FIXME: Why not `with-current-buffer'? --Stef. (set-buffer vc-parent-buffer) (vc-deduce-fileset-1 not-state-changing allow-unregistered state-model-only-files))) @@ -1230,6 +1233,8 @@ vc-next-action (error "Fileset files are missing, so cannot be operated on")) ((eq state 'ignored) (error "Fileset files are ignored by the version-control system")) + ((eq model 'patch) + (vc-checkin files backend nil nil nil (buffer-string))) ((or (null state) (eq state 'unregistered)) (cond (verbose (let ((backend (vc-read-backend "Backend to register to: "))) @@ -1615,7 +1620,7 @@ vc-steal-lock ".\n") (message "Please explain why you stole the lock. Type C-c C-c when done."))) -(defun vc-checkin (files backend &optional comment initial-contents rev) +(defun vc-checkin (files backend &optional comment initial-contents rev patch-string) "Check in FILES. COMMENT is a comment string; if omitted, a buffer is popped up to accept a comment. If INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents of the log @@ -1643,7 +1650,9 @@ vc-checkin ;; vc-checkin-switches, but 'the' local buffer is ;; not a well-defined concept for filesets. (progn - (vc-call-backend backend 'checkin files comment rev) + (if patch-string + (vc-call-backend backend 'checkin files comment rev patch-string) + (vc-call-backend backend 'checkin files comment rev)) (mapc #'vc-delete-automatic-version-backups files)) `((vc-state . up-to-date) (vc-checkout-time . ,(file-attribute-modification-time @@ -1651,7 +1660,8 @@ vc-checkin (vc-working-revision . nil))) (message "Checking in %s...done" (vc-delistify files))) 'vc-checkin-hook - backend)) + backend + patch-string)) ;;; Additional entry points for examining version histories @@ -1779,6 +1789,23 @@ vc-diff-finish (defvar vc-diff-added-files nil "If non-nil, diff added files by comparing them to /dev/null.") +(defvar vc-patch-buffer nil) + +(defun vc-diff-patch () + (let ((buffer "*vc-diff*") + (patch-string vc-patch-string)) + (vc-setup-buffer buffer) + (set-buffer buffer) + (let ((buffer-undo-list t) + (inhibit-read-only t)) + (insert patch-string)) + (setq buffer-read-only t) + (diff-mode) + (setq-local diff-vc-backend (vc-responsible-backend default-directory)) + (setq-local revert-buffer-function (lambda (_ _) (vc-diff-patch))) + (pop-to-buffer (current-buffer)) + (vc-run-delayed (vc-diff-finish (current-buffer) nil)))) + (defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose buffer) "Report diffs between two revisions of a fileset. Output goes to the buffer BUFFER, which defaults to *vc-diff*.