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#66113: Apply the entire diff buffer Date: Sun, 24 Sep 2023 10:34:32 +0300 Organization: LINKOV.NET Message-ID: <86a5tcxbw7.fsf@mail.linkov.net> References: <86o7hx4a11.fsf@mail.linkov.net> <86v8c2u34b.fsf@mail.linkov.net> <9cb6c329-8a81-414a-00e0-b3d8aa73d037@gutov.dev> <86msxep69i.fsf@mail.linkov.net> <86lecwvjw4.fsf@mail.linkov.net> <095e4596-7c67-21e2-a69f-c0b7945773a3@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12090"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 66113@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 24 09:43:25 2023 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 1qkJm0-00032q-MT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Sep 2023 09:43:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkJlV-00046i-9s; Sun, 24 Sep 2023 03:42:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkJlT-00045Z-Av for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 03:42:51 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkJlT-0000xq-3M for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 03:42:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qkJle-0006Bp-Mx for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 03:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Sep 2023 07:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66113 X-GNU-PR-Package: emacs Original-Received: via spool by 66113-submit@debbugs.gnu.org id=B66113.169554134323702 (code B ref 66113); Sun, 24 Sep 2023 07:43:02 +0000 Original-Received: (at 66113) by debbugs.gnu.org; 24 Sep 2023 07:42:23 +0000 Original-Received: from localhost ([127.0.0.1]:40927 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkJl0-0006AE-Np for submit@debbugs.gnu.org; Sun, 24 Sep 2023 03:42:23 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:41127) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkJky-00069w-5l for 66113@debbugs.gnu.org; Sun, 24 Sep 2023 03:42:21 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id BBD091C0003; Sun, 24 Sep 2023 07:42:00 +0000 (UTC) In-Reply-To: <095e4596-7c67-21e2-a69f-c0b7945773a3@gutov.dev> (Dmitry Gutov's message of "Sun, 24 Sep 2023 04:34:33 +0300") X-GND-Sasl: juri@linkov.net 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271220 Archived-At: >> +(defun diff-apply-buffer () >> + "Apply the diff in the entire diff buffer. >> +When applying all hunks was successful, then save the changed buffers." >> + (interactive) >> + (let ((buffer-edits nil) >> + (failures 0) >> + (diff-refine nil)) >> + (save-excursion >> + (goto-char (point-min)) >> + (diff-beginning-of-hunk t) >> + (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched) >> + (diff-find-source-location nil nil))) >> + (cond ((and line-offset (not switched)) >> + (push (cons pos dst) >> + (alist-get buf buffer-edits))) >> + (t (setq failures (1+ failures)))) >> + (not (or (eq (prog1 (point) (diff-hunk-next)) (point)) >> + (eobp)))))) >> + (cond ((zerop failures) >> + (dolist (buf-edits (reverse buffer-edits)) >> + (with-current-buffer (car buf-edits) >> + (dolist (edit (cdr buf-edits)) >> + (let ((pos (car edit)) >> + (dst (cdr edit)) >> + (inhibit-read-only t)) >> + (goto-char (car pos)) >> + (delete-region (car pos) (cdr pos)) >> + (insert (car dst)))) >> + (save-buffer))) >> + (message "Saved %d buffers" (length buffer-edits))) >> + (t >> + (message "%d hunks failed; no buffers changed" failures))))) > > Sorry, was there supposed to be a call to diff-test-hunk here? Or I'm just > not following the implementation. diff-test-hunk was just an example of implementation. But the same way as diff-apply-hunk is not used here, also only the logic of diff-test-hunk is used. > I tried testing it out too. There is a patch where the third hunk doesn't > apply (errors with "can't find the text to patch" in regular usage). This > command ends with cryptic "No next hunk". This is what I expected that diff-hunk-next might signal an error that we should catch, but still couldn't find a patch that fails with such error. So I will try to construct such a patch manually.