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: Tue, 08 Feb 2022 21:57:58 +0200 Organization: LINKOV.NET Message-ID: <8635ktjfll.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> 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="39282"; 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 Tue Feb 08 21:31:56 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 1nHX9X-000A5k-MN for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Feb 2022 21:31:55 +0100 Original-Received: from localhost ([::1]:56034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHX9W-0006Be-6k for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Feb 2022 15:31:54 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHWgc-000228-Sa for bug-gnu-emacs@gnu.org; Tue, 08 Feb 2022 15:02:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHWgc-00051v-EW for bug-gnu-emacs@gnu.org; Tue, 08 Feb 2022 15:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHWgc-000289-9H for bug-gnu-emacs@gnu.org; Tue, 08 Feb 2022 15:02: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: Tue, 08 Feb 2022 20:02: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.16443505178179 (code B ref 52349); Tue, 08 Feb 2022 20:02:02 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 8 Feb 2022 20:01:57 +0000 Original-Received: from localhost ([127.0.0.1]:48739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHWgX-00027r-CJ for submit@debbugs.gnu.org; Tue, 08 Feb 2022 15:01:57 -0500 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:34503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHWgV-00027Z-44 for 52349@debbugs.gnu.org; Tue, 08 Feb 2022 15:01:56 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 55E8A100004; Tue, 8 Feb 2022 20:01:46 +0000 (UTC) In-Reply-To: <95d2d999-49ad-13c4-9f25-0935650a1e42@yandex.ru> (Dmitry Gutov's message of "Fri, 10 Dec 2021 02:17:18 +0300") 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:226412 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Dmitry, >> So if using ‘git apply --cached’ is the preferred solution, >> then I could finish the patch with it. > > I don't have a particularly strong opinion, but the approach with 'git > apply --cached' followed by 'git commit' seems easier to implement and > avoids changing the file contents on disk, or risking any of the > stashes. So I'd try implementing it first and then see if the remaining > problems are worth the trouble of doing it in a more difficult way. This is implemented now, and I'm already using it without problems. Please review this patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-git-checkin-from-diff.patch diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 0bf7899246..84128d40b8 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2860,6 +2860,17 @@ diff-syntax-fontify-props (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 ;; Strip the `display' properties added by diff-font-lock-prettify, diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index 5c664d58f1..5400352efe 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -753,7 +753,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..ddadca2084 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -942,13 +942,23 @@ vc-git-checkin ;; message. Handle also remote files. (if (eq system-type 'windows-nt) (let ((default-directory (file-name-directory file1))) - (make-nearby-temp-file "git-msg"))))) + (make-nearby-temp-file "git-msg")))) + (patch-buffer (derived-mode-p 'diff-mode))) + (when patch-buffer + (let ((patch-string (buffer-string)) + (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-buffer)) files) (nconc (if msg-file (list "commit" "-F" (file-local-name msg-file)) (list "commit" "-m")) @@ -966,7 +976,8 @@ vc-git-checkin (write-region (car args) nil msg-file)) (setq args (cdr args))) args) - (if only (list "--only" "--") '("-a"))))) + (unless patch-buffer + (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..d55cf64b3d 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1098,6 +1098,8 @@ vc-deduce-fileset-1 state-model-only-files) (let (backend) (cond + ((derived-mode-p 'diff-mode) + (diff-vc-deduce-fileset)) ((derived-mode-p 'vc-dir-mode) (vc-dir-deduce-fileset state-model-only-files)) ((derived-mode-p 'dired-mode) @@ -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,7 @@ 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)) ((or (null state) (eq state 'unregistered)) (cond (verbose (let ((backend (vc-read-backend "Backend to register to: "))) @@ -1800,7 +1804,11 @@ vc-diff-internal (orig-diff-buffer-clone (if revert-buffer-in-progress-p (clone-buffer - (generate-new-buffer-name " *vc-diff-clone*") nil)))) + (generate-new-buffer-name " *vc-diff-clone*") nil))) + (patch-buffer (and (buffer-live-p vc-parent-buffer) + (with-current-buffer vc-parent-buffer + (derived-mode-p 'diff-mode)) + vc-parent-buffer))) ;; On MS-Windows and MS-DOS, Diff is likely to produce DOS-style ;; EOLs, which will look ugly if (car files) happens to have Unix ;; EOLs. @@ -1837,8 +1845,11 @@ vc-diff-internal (if async 'async 1) "diff" file (append (vc-switches nil 'diff) `(,(null-device))))))) (setq files (nreverse filtered)))) - (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async) + (unless patch-buffer + (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async)) (set-buffer buffer) + (when patch-buffer + (insert (with-current-buffer patch-buffer (buffer-string)))) ;; Make the *vc-diff* buffer read only, the diff-mode key ;; bindings are nicer for read only buffers. pcl-cvs does the ;; same thing. --=-=-=--