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#62731: 29.0.60; diff-apply-hunk doesn't work for creating new files Date: Thu, 17 Oct 2024 20:56:38 +0300 Organization: LINKOV.NET Message-ID: <86ttdazk89.fsf@mail.linkov.net> References: <5afef01c-a8a8-485c-aa12-0b19e5bf21ba@gutov.dev> <87jzyln9g0.fsf@catern.com> <865xpt739v.fsf_-_@mail.linkov.net> <1cc9143d-96c2-47d8-afaa-70c4e766a953@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="14094"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: sbaugh@catern.com, 62731@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 17 19:58:53 2024 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 1t1Ulw-0003VT-Lq for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Oct 2024 19:58:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1Uls-0001S6-AV; Thu, 17 Oct 2024 13:58:48 -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 1t1Ulm-0001Fn-3G for bug-gnu-emacs@gnu.org; Thu, 17 Oct 2024 13:58:43 -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 1t1Ull-0004JC-0Y for bug-gnu-emacs@gnu.org; Thu, 17 Oct 2024 13:58:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=tjR5WbSSJ/Zad7Y0rNLaA4G+3JgiJzoJ+PUkEcIGF5c=; b=vxsW4peoibPEo4/Me2jZPw2/Aq17N9uOSL3/hmwqoHxhaLmZn8sXtQKbJl2yl7F8yQSZ6kfk+pZR8dDfwWJMfvJF1Gr7VbqeqCcAAenhjn5qCU/LmpDFvnmhD3G59fVznvrcj9cQKLYkKXxVruGtaf0HL5ECw6d9t4YEdgp6104y+Wb4XzP9SMYvZ9DEbyS2gg46cOP5h+z10jQBiI8MjMEC+t7wMUqJ+M8znu9Sg6Mdp+DPTdXcRh9X1tMo5u37cpTOsolB8ytW0vq01X5zLeHnr5SCaHoLvu6aJedotxlIoj9NgidrwFAu5j4U7vjqM48LUFSaRn6KVPtxJXYQgw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t1Um6-00046D-2v for bug-gnu-emacs@gnu.org; Thu, 17 Oct 2024 13:59: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: Thu, 17 Oct 2024 17:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62731 X-GNU-PR-Package: emacs Original-Received: via spool by 62731-submit@debbugs.gnu.org id=B62731.172918793815747 (code B ref 62731); Thu, 17 Oct 2024 17:59:02 +0000 Original-Received: (at 62731) by debbugs.gnu.org; 17 Oct 2024 17:58:58 +0000 Original-Received: from localhost ([127.0.0.1]:35537 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1Um1-00045u-Vi for submit@debbugs.gnu.org; Thu, 17 Oct 2024 13:58:58 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:49937) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1Ulz-00045e-E0 for 62731@debbugs.gnu.org; Thu, 17 Oct 2024 13:58:56 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 8AFA31BF206; Thu, 17 Oct 2024 17:58:06 +0000 (UTC) In-Reply-To: <1cc9143d-96c2-47d8-afaa-70c4e766a953@gutov.dev> (Dmitry Gutov's message of "Wed, 16 Oct 2024 22:37:40 +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:293742 Archived-At: >>>> All right, the attached seems to support both creation and deletion, >>>> including applying hunks in reverse direction. >>>> Things got trickier but not by a lot. >>> >>> Now pushed to master, seems useful enough. Let's see if some unforeseen >>> problems are reported. >> >> This change broke diff of files: >> >> @@ -1957,7 +1970,7 @@ diff-find-source-location >> diff-context-mid-hunk-header-re nil t) >> (error "Can't find the hunk separator")) >> (match-string 1))))) >> - (file (or (diff-find-file-name other noprompt) >> + (file (or (diff-find-file-name (xor other reverse) noprompt) >> (error "Can't find the file"))) >> (revision (and other diff-vc-backend >> (if reverse (nth 1 diff-vc-revisions) >> >> So after 'dired-backup-diff', typing 'C-c C-c' visits wrong file: >> visits the backup when point is on the file line, and vice versa: >> visits the file when point is on backup file line. > > Thanks for reporting. > > Do you think we can fix it this way? > > diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el > index cfa90d380ad..374df3ee2cb 100644 > --- a/lisp/vc/diff-mode.el > +++ b/lisp/vc/diff-mode.el > @@ -2196,7 +2196,7 @@ diff-goto-source > ;; This is a convenient detail when using smerge-diff. > (if event (posn-set-point (event-end event))) > (let ((buffer (when event (current-buffer))) > - (reverse (not (save-excursion (beginning-of-line) (looking-at "[-<]"))))) > + (reverse (not (save-excursion (beginning-of-line) (looking-at "[+<]"))))) > (pcase-let ((`(,buf ,_line-offset ,pos ,src ,_dst ,_switched) > (diff-find-source-location other-file reverse))) > (pop-to-buffer buf) I don't understand this change. > Otherwise, I don't quite understand the intent behind that line. But it > might have been masking the problem which I (hopefully) fixed in the > hunk you quoted/ There is already one 'xor' here. Maybe the second 'xor' not needed: (defun diff-find-source-location (&optional other-file reverse noprompt) ... (let* ((other (xor other-file diff-jump-to-old-file)) ... (file (or (diff-find-file-name (xor other reverse) noprompt)