From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Certner Newsgroups: gmane.emacs.bugs Subject: bug#59182: Proposed fix Date: Thu, 10 Nov 2022 19:35:28 +0100 Message-ID: <7839380.iDzAj6rjnq@ravel> References: <1855192.vslOlgHxSZ@ravel> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2020089.x0N0T6uNKo" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35738"; mail-complaints-to="usenet@ciao.gmane.io" To: 59182@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 10 19:36:15 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 1otCPO-00095K-CY for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Nov 2022 19:36:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otCPE-0006Q3-KH; Thu, 10 Nov 2022 13:36:04 -0500 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 1otCPD-0006Pl-NF for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 13:36:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otCPC-00059Q-8I for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 13:36:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otCPB-0000Il-Sg for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 13:36:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <1855192.vslOlgHxSZ@ravel> Resent-From: Olivier Certner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 10 Nov 2022 18:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59182 X-GNU-PR-Package: emacs Original-Received: via spool by 59182-submit@debbugs.gnu.org id=B59182.16681053321113 (code B ref 59182); Thu, 10 Nov 2022 18:36:01 +0000 Original-Received: (at 59182) by debbugs.gnu.org; 10 Nov 2022 18:35:32 +0000 Original-Received: from localhost ([127.0.0.1]:44363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otCOi-0000Hs-A6 for submit@debbugs.gnu.org; Thu, 10 Nov 2022 13:35:32 -0500 Original-Received: from smtp6-g21.free.fr ([212.27.42.6]:57502) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otCOg-0000Hk-Ce for 59182@debbugs.gnu.org; Thu, 10 Nov 2022 13:35:31 -0500 Original-Received: from ravel.localnet (unknown [109.210.33.132]) (Authenticated sender: ocert.dev@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id 42938780344 for <59182@debbugs.gnu.org>; Thu, 10 Nov 2022 19:35:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1668105329; bh=2wRfWPYzGqqy78HTJvbbHG+KZD4953u7v3bDpShHnok=; h=From:To:Subject:Date:From; b=MjzP5KY5DvM66/TTwiJ4KxbpfI5P8RA0pI0TXG9Zlg6fqbYFxzg283v/ZhsJfoFUG GfPw+v9gFaRzErwgglLFWgyDNjW1O1qudLg+O2eSLHu5BahgkgIYe/CgQTc+Kj2p/r grMOI4XirwC3OQg2AtGrZhPqci6hICZh0fGx+eIqapcfrPwDXlkt+7mAW/GMTD9lbJ Qvg4ZbSMq/4Gk/Ytnrsy4srg6SsApohsM5281Xwbu6NsvXaiUWR15o64Us/vBzb3nP Ph8ORLg8uuYicPnSSOhRZeiKqlILlJisItQapHhFd+JXA/tc0+XC/lWECFjDP46wD/ kprh39cj+MClQ== 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:247535 Archived-At: This is a multi-part message in MIME format. --nextPart2020089.x0N0T6uNKo Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" On top of emacs-28 branch (49a14c4375ce4c2c). The fix is "minimal", in the sense that it doesn't try to refactor/modify unrelated code. -- Olivier Certner --nextPart2020089.x0N0T6uNKo Content-Disposition: attachment; filename="0001-ediff-Merges-with-ancestor-Fix-computation-of-hunks-.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-ediff-Merges-with-ancestor-Fix-computation-of-hunks-.patch" >From 49a14c4375ce4c2c260f52db53d151742f6edeff Mon Sep 17 00:00:00 2001 From: Olivier Certner Date: Thu, 10 Nov 2022 18:57:27 +0100 Subject: [PATCH] ediff: Merges with ancestor: Fix computation of hunks and proposed merge Hunks were not computed correctly because the diff3 command was invoked with arguments in an incorrect order. The correct order is the local file first, the base (or "ancestor") second and the other file third. This erroneous behavior had two consequences. First, the output of diff3 would change, since it tries to merge chunks according to maximal matches between the second and first files, and the second and third files. Second, ediff, more precisely, `ediff-do-merge', would consequently try to merge the reverse of the changes from the base to the other file. * lisp/vc/ediff-diff.el (ediff-setup-diff-regions3): In the arguments to `ediff-exec-process', swap the other file with the ancestor (only when merging with an ancestor). (ediff-extract-diffs3): Match the hunk data for the ancestor and the other file correctly. The local variable `three-way-comp' indicates this is a merge with ancestors when it is nil. (Bug#59182) --- lisp/vc/ediff-diff.el | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lisp/vc/ediff-diff.el b/lisp/vc/ediff-diff.el index ca56a2851db..61c6dc39aa7 100644 --- a/lisp/vc/ediff-diff.el +++ b/lisp/vc/ediff-diff.el @@ -939,6 +939,9 @@ ediff-extract-diffs3 (c-prev-pt nil) (anc-prev 1) diff-list shift-A shift-B shift-C + (A-idx "1") + (B-idx (if three-way-comp "2" "3")) + (C-idx (if three-way-comp "3" "2")) ) ;; diff list contains word numbers or points, depending on word-mode @@ -976,23 +979,23 @@ ediff-extract-diffs3 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1)))) ;; if the files A and B are the same and not 3way-comparison, ;; ignore the difference - (if (or three-way-comp (not (string-equal agreement "3"))) - (let* ((a-begin (car (ediff-get-diff3-group "1"))) - (a-end (nth 1 (ediff-get-diff3-group "1"))) - (b-begin (car (ediff-get-diff3-group "2"))) - (b-end (nth 1 (ediff-get-diff3-group "2"))) - (c-or-anc-begin (car (ediff-get-diff3-group "3"))) - (c-or-anc-end (nth 1 (ediff-get-diff3-group "3"))) + (if (or three-way-comp (not (string-equal agreement C-idx))) + (let* ((a-begin (car (ediff-get-diff3-group A-idx))) + (a-end (nth 1 (ediff-get-diff3-group A-idx))) + (b-begin (car (ediff-get-diff3-group B-idx))) + (b-end (nth 1 (ediff-get-diff3-group B-idx))) + (c-or-anc-begin (car (ediff-get-diff3-group C-idx))) + (c-or-anc-end (nth 1 (ediff-get-diff3-group C-idx))) (state-of-merge - (cond ((string-equal agreement "1") 'prefer-A) - ((string-equal agreement "2") 'prefer-B) + (cond ((string-equal agreement A-idx) 'prefer-A) + ((string-equal agreement B-idx) 'prefer-B) (t ediff-default-variant))) (state-of-diff-merge (if (memq state-of-merge '(default-A prefer-A)) 'B 'A)) (state-of-diff-comparison - (cond ((string-equal agreement "1") 'A) - ((string-equal agreement "2") 'B) - ((string-equal agreement "3") 'C))) + (cond ((string-equal agreement A-idx) 'A) + ((string-equal agreement B-idx) 'B) + ((string-equal agreement C-idx) 'C))) state-of-ancestor c-begin c-end a-begin-pt a-end-pt @@ -1105,8 +1108,12 @@ ediff-setup-diff-regions3 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*")))) (message "Computing differences ...") - (ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize - ediff-actual-diff3-options file-A file-B file-C) + (apply #'ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize + ediff-actual-diff3-options + (cons file-A (if ediff-merge-with-ancestor-job + ;; Ancestor must be the middle file + (list file-C file-B) + (list file-B file-C)))) (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer) ;;(message "Computing differences ... done") -- 2.37.3 --nextPart2020089.x0N0T6uNKo--