From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks Date: Sat, 12 Feb 2022 21:42:50 +0200 Organization: LINKOV.NET Message-ID: <86v8xjx45h.fsf@mail.linkov.net> References: <268cee0d-465d-b862-d1d6-f5da4d69e737@inventati.org> <9106387a-98cf-396f-bf45-ccb04581787b@yandex.ru> <864k7kfd56.fsf@mail.linkov.net> <86fsr3uen2.fsf@mail.linkov.net> <95d2d999-49ad-13c4-9f25-0935650a1e42@yandex.ru> <8635ktjfll.fsf@mail.linkov.net> <36b963e4-5af7-dd9e-af92-4404541b9f4d@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28199"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 52349@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 12 20:49:42 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nIyOs-0007Bg-OY for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Feb 2022 20:49:42 +0100 Original-Received: from localhost ([::1]:41612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nIyOr-0000NM-9L for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Feb 2022 14:49:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIyOE-0000ML-Vv for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 14:49:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nIyOE-000105-MB for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 14:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nIyOE-0002Kg-LL for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 14:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Feb 2022 19:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52349 X-GNU-PR-Package: emacs Original-Received: via spool by 52349-submit@debbugs.gnu.org id=B52349.16446952848852 (code B ref 52349); Sat, 12 Feb 2022 19:49:02 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 12 Feb 2022 19:48:04 +0000 Original-Received: from localhost ([127.0.0.1]:35694 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIyNI-0002Ig-5P for submit@debbugs.gnu.org; Sat, 12 Feb 2022 14:48:04 -0500 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:46207) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIyNG-0002HW-Df for 52349@debbugs.gnu.org; Sat, 12 Feb 2022 14:48:03 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 45A7D60003; Sat, 12 Feb 2022 19:47:54 +0000 (UTC) In-Reply-To: <36b963e4-5af7-dd9e-af92-4404541b9f4d@yandex.ru> (Dmitry Gutov's message of "Sat, 12 Feb 2022 03:43:49 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226743 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit > But could you explain the case when the changes to 'vc-diff-internal' are > going to be used? If those are only for log-edit-show-diff, I think it'd be > better if the new logic was implemented in the new value of > log-edit-diff-function, rather than having it spliced into the common code > path. Would that result in a lot of code duplication? Not much code duplication, thanks for the suggestion, the patch below sets log-edit-diff-function for log-edit-show-diff. > It might also be worth it to thread the 'patch-buffer' value through the > backend method arguments (the actual value will be the patch string), so > that vc-git-checkin gets it in the 4th argument, rather than having it call > (derived-mode-p 'diff-mode) (this feels a little brittle: I suppose which > buffer is current during this call might change in the future). It would > also automatically weed out backends which don't support this feature, > rather than having an attempt to commit from a diff buffer using Hg fail > silently. I agree that in the first version ‘(derived-mode-p 'diff-mode)’ was brittle. But changing the established API with a new argument doesn't look right. So the next version below uses the buffer-local variable ‘vc-patch-string’. In other backends such as Hg it shouldn't fail silently, but it will be just less granular, and will commit whole files instead of edited diffs. There is a new problem however. After starting vc-log-edit from *vc-diff*, and using log-edit-show-diff, it reuses the original buffer *vc-diff*. This is not a problem, because the buffer-local variable ‘vc-patch-string’ is saved in the *vc-log* buffer. But after deleting *vc-diff*, log-edit-done fails on the deleted vc-parent-buffer with Debugger entered--Lisp error: (error "Selecting deleted buffer") vc-finish-logentry() funcall-interactively(vc-finish-logentry) log-edit-done() But this is an old problem. The same error is signaled after typing ‘v’ in *vc-dir* buffer, then deleting the original *vc-dir* buffer, and trying to type ‘C-c C-c’ (log-edit-done) in the *vc-log* buffer. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-patch-string.patch 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..dc141fd650 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -653,9 +653,14 @@ vc-log-edit (mapcar (lambda (file) (file-relative-name file root)) ',fileset)))) - (log-edit-diff-function . vc-diff) + (log-edit-diff-function + . ,(if (buffer-local-value 'vc-patch-buffer vc-parent-buffer) + 'vc-diff-patch 'vc-diff)) (log-edit-vc-backend . ,backend) - (vc-log-fileset . ,fileset)) + (vc-log-fileset . ,fileset) + ,@(if (buffer-local-value 'vc-patch-buffer vc-parent-buffer) + `((vc-patch-string . ,(with-current-buffer vc-parent-buffer + (buffer-string)))))) nil mode) (set-buffer-modified-p nil) @@ -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..4eb114633d 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -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 vc-patch-string + (let ((patch-file (make-temp-file "git-patch"))) + (with-temp-file patch-file + (insert vc-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 vc-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 vc-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..1b30e9b671 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -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,9 @@ 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) + (setq-local vc-patch-buffer t) + (vc-checkin files backend)) ((or (null state) (eq state 'unregistered)) (cond (verbose (let ((backend (vc-read-backend "Backend to register to: "))) @@ -1779,6 +1785,24 @@ 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) +(defvar vc-patch-string 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*. --=-=-=--