From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#62731: 29.0.60; diff-apply-hunk doesn't work for creating new files Date: Sat, 19 Oct 2024 02:29:51 +0100 Message-ID: <213a855a-4e27-4d15-828a-cadc97f25119@gutov.dev> References: <5afef01c-a8a8-485c-aa12-0b19e5bf21ba@gutov.dev> <87jzyln9g0.fsf@catern.com> <865xpt739v.fsf_-_@mail.linkov.net> <1cc9143d-96c2-47d8-afaa-70c4e766a953@gutov.dev> <86ttdazk89.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3550"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: sbaugh@catern.com, 62731@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 19 03:30:58 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 1t1yIz-0000m3-IC for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Oct 2024 03:30:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1yIl-0001u9-15; Fri, 18 Oct 2024 21:30:43 -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 1t1yIi-0001tk-J2 for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2024 21:30:41 -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 1t1yIh-0005lH-9J for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2024 21:30:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=tr/cEwexnPl47+98hd3SRGKcyD8ft7Rj1Qraum4FLXg=; b=vrNDDeBhhqm7adDINyw1fohfE1M1tdcmutsRxJFFAwxIT0W9seTQgiQf6uqSXqNPxpS747JpkXRxqo3TYrwvK0rLEvX1CoA5jEgU7KlekaY0SZe/m+q+dZqzmDLVhxHs2/t43n3yhO05Vv1qdn8bnjNeW/NPokVxqcgMnpvMuYwaOvr34iCQcroe8kjaKZgFm+aQjoAQnk1GiPXZLlLb2w2B8KnQBo54zFzTJNDMMe2QF+FZHS41tvvvs5VspdrPhdDeAN8few0K3wBhQnhf94LkRCRsOvZptjRdQZXQo1pBdPapAEdtH8tLZfT1+YmuqOrEW3kYEPw3LfbnAijN8g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t1yJ4-0008L0-2S for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2024 21:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Oct 2024 01:31: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.172930142531635 (code B ref 62731); Sat, 19 Oct 2024 01:31:02 +0000 Original-Received: (at 62731) by debbugs.gnu.org; 19 Oct 2024 01:30:25 +0000 Original-Received: from localhost ([127.0.0.1]:40589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1yIS-0008EA-DW for submit@debbugs.gnu.org; Fri, 18 Oct 2024 21:30:24 -0400 Original-Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]:41011) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1yIQ-0008Dv-Am for 62731@debbugs.gnu.org; Fri, 18 Oct 2024 21:30:23 -0400 Original-Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id A427C1140123; Fri, 18 Oct 2024 21:29:53 -0400 (EDT) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 18 Oct 2024 21:29:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1729301393; x=1729387793; bh=tr/cEwexnPl47+98hd3SRGKcyD8ft7Rj1Qraum4FLXg=; b= XsLioABDAJJFWEwEMXudY5EwbA/4q2VYm5zQayqSr3tVLFP1F5DwcwtoczbsssZb OXxt3E0KGYAOpJ336H4+eHhm/aZ4fCG1kRiJfgjIEYu67Wo1LksFuPPjVv6tlu9e GKkz3A4TLM5kshpMVqY7o6o3K2Rsfo8AiDR6EnBm57E2D0avz1oGu3vP45eP2t2T lNdhgttt+BFYqynhnPvb+aPKzLlrFi5XInsyoyl639FMPfAgPkIVI3g8tEXxYt6y eW+yz7aG4hnXl2pc9nID9jNO63iCqiPLVcCx5UIu0EEJ+F1joiFR94PUtOE1eSqy /h5OJUPwqz4eSjcOHnF59w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1729301393; x= 1729387793; bh=tr/cEwexnPl47+98hd3SRGKcyD8ft7Rj1Qraum4FLXg=; b=X XFQUturzfxUvZkM2R3NFO2IVdyVsbvzfUG+k3kR2RP284jQvURFNwUwExBJYNjP0 mn5X0uwHhsePA3yyNAV4GR93dfKyHXyFxi4PVkjYweFp3HbZX4FPam3GWhFQeifl 9PcTHaQYQzfm5LdqvHRNEDYrYjL2BaViXC+T4qmWlzLy+VlXTTzgN49yz0x5cXwR YgVhYdMGRHFBmX7wX/PbbxBOojoBHkfuTVGux1cCVQgO0lAWnbjpbZsUWP3fslQc 0tHpM7SSF90SFDZWJJGElqnNQgft43CQnKBq/S7FoVfcfPnW0MPwKYXb8YG6yaXS XwQSLqHt3BBsiNo3vmd6A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdrug gvvheqnecuggftrfgrthhtvghrnhepteduleejgeehtefgheegjeekueehvdevieekueef tddvtdevfefhvdevgedujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghvpdhnsggprhgtphhtthho peefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjuhhriheslhhinhhkohhvrd hnvghtpdhrtghpthhtohepshgsrghughhhsegtrghtvghrnhdrtghomhdprhgtphhtthho peeivdejfeduseguvggssghughhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 21:29:52 -0400 (EDT) Content-Language: en-US In-Reply-To: <86ttdazk89.fsf@mail.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:293824 Archived-At: On 17/10/2024 20:56, Juri Linkov wrote: >>>>> 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. It seemed logical that if the diff is between two different files, then reversing the direction would make the "old" file the current one. I suppose that might be true only in some cases (e.g. creation or deletion diffs, or files of equal importance), but not when the comparison base is the backup file. >> 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) Yes ok, let's try moving that to the caller. Pushed as commit 1374f20491b. A few other callers use non-nil 'reverse', but I suppose diff-test-hunk is not very useful for file creation/deletion. Note that the new (same as previous) behavior is to always visit the source buffer, newer the backup file's buffer. I hope that is the goal.