From unknown Mon Aug 18 14:23:50 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#59182 <59182@debbugs.gnu.org> To: bug#59182 <59182@debbugs.gnu.org> Subject: Status: 28.1; ediff: Merges with ancestor: Fix computation of hunks and proposed merge Reply-To: bug#59182 <59182@debbugs.gnu.org> Date: Mon, 18 Aug 2025 21:23:50 +0000 retitle 59182 28.1; ediff: Merges with ancestor: Fix computation of hunks a= nd proposed merge reassign 59182 emacs submitter 59182 Olivier Certner severity 59182 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 10 13:29:20 2022 Received: (at submit) by debbugs.gnu.org; 10 Nov 2022 18:29:20 +0000 Received: from localhost ([127.0.0.1]:44351 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otCIi-00007N-6q for submit@debbugs.gnu.org; Thu, 10 Nov 2022 13:29:20 -0500 Received: from lists.gnu.org ([209.51.188.17]:43548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otCIg-00007G-H7 for submit@debbugs.gnu.org; Thu, 10 Nov 2022 13:29:18 -0500 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 1otCIg-0002Ya-CS for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 13:29:18 -0500 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otCIb-0007v0-Eg for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 13:29:18 -0500 Received: from ravel.localnet (unknown [109.210.33.132]) (Authenticated sender: ocert.dev@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id C32D8780310 for ; Thu, 10 Nov 2022 19:29:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1668104949; bh=D0CKz3toqMNgxhn77ZZXHf6COef0Yo8WGeHr5wW8JQ4=; h=From:To:Subject:Date:From; b=XMGBr9Myw0ruSLmMFi11x+9GYC2LF3nQQIPwOGWl03JdcZQ5qZtp6WmEyw9YIAVcr 6IXKgX09BH1cTF6lNtInbj60a6fyX4o+IoOLa4QINykI8Ul7KhteJYO4vqjyPecJKR o9PT91JcAaQGgG0soaDFgeZourCOaiD3j7ThQ4oDzv3bTTvX1kBBK/rRiG6/eumBVK 7vAyYAJNYqEsxXM78oZMh6xtnRQ/GdR/qX7u79GWlm6RXDy3Sm8zkh+8Qm6zs91lM4 KHrlC9pQWOKUJzLLqF6r2A2ox8ocp5RyLGKxpXu7m4NdQJ30phCrP+w/EEVs5M/CTO 4Du43VJ4qNtmQ== From: Olivier Certner To: bug-gnu-emacs@gnu.org Subject: 28.1; ediff: Merges with ancestor: Fix computation of hunks and proposed merge Date: Thu, 10 Nov 2022 19:29:09 +0100 Message-ID: <1855192.vslOlgHxSZ@ravel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart5740219.Zv9zXsTiuT" Content-Transfer-Encoding: 7Bit Received-SPF: pass client-ip=2a01:e0c:1:1599::15; envelope-from=ocert.dev@free.fr; helo=smtp6-g21.free.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.0 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) This is a multi-part message in MIME format. --nextPart5740219.Zv9zXsTiuT Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" Hunks are not computed correctly because the diff3 command is 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 has 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, leading to a hard to understand merge result in some cases. To see the effect on a simple example, consider what `ediff-merge-with-ancestors` suggests on the three files attached (run `ediff-merge-with-ancestor' with file A being 'local.txt', file B being 'other.txt' and file C being 'ancestor.txt'). I noticed this problem on a very hairy merge that I can't reproduce here. Fix to be attached as soon as the bug is created. -- Olivier Certner --nextPart5740219.Zv9zXsTiuT Content-Disposition: attachment; filename="local.txt" Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8"; name="local.txt" 4 5 1 2 3 --nextPart5740219.Zv9zXsTiuT Content-Disposition: attachment; filename="ancestor.txt" Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8"; name="ancestor.txt" 1 2 3 4 5 6 --nextPart5740219.Zv9zXsTiuT Content-Disposition: attachment; filename="other.txt" Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8"; name="other.txt" 4 5 6 1 2 --nextPart5740219.Zv9zXsTiuT-- From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 10 13:35:32 2022 Received: (at 59182) by debbugs.gnu.org; 10 Nov 2022 18:35:32 +0000 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 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 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== From: Olivier Certner To: 59182@debbugs.gnu.org Subject: Proposed fix Date: Thu, 10 Nov 2022 19:35:28 +0100 Message-ID: <7839380.iDzAj6rjnq@ravel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2020089.x0N0T6uNKo" Content-Transfer-Encoding: 7Bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 59182 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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-- From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 17 04:42:01 2022 Received: (at 59182-done) by debbugs.gnu.org; 17 Nov 2022 09:42:02 +0000 Received: from localhost ([127.0.0.1]:59130 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ovbPF-0002Xl-Ma for submit@debbugs.gnu.org; Thu, 17 Nov 2022 04:42:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52272) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ovbPD-0002XU-K2 for 59182-done@debbugs.gnu.org; Thu, 17 Nov 2022 04:42:00 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovbP7-0008Kr-91; Thu, 17 Nov 2022 04:41:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=a5fFQBk1KsnSyh7KxYdR7jcqykb23//3C3U0hhTO7tQ=; b=jWJMjWMnzuYQ rWa/p6HBhVVw69lksXRW8gE20Mvvx9ige/yR9Px5zHk052o87phxQcFUHnC3QF1oD7ZhMtjhwdd1X oIlOYbHWNmoDMgru6q8GBSkTgsV7pmc++8oAbGmOvvQpKOcMfpDIMoUatP4d0WSZVWhtGEQlJggf5 RMfs6RPEN7EoQhAUFm6n0onUALnh+YjrsN6wFTIwJ8fH2gh9fYd35FQTexI3jSGlDuDez8jxtWfeg JtPPmUFzTqpwsG0lsdjSstGD8X4ZbyJlLHWjscN7vbafHTbIdPgOlJDs6e25RroSof/oS73+dLiMm jiA/d0ynVzHCL71yW/kAww==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovbP6-0005DV-D3; Thu, 17 Nov 2022 04:41:52 -0500 Date: Thu, 17 Nov 2022 11:41:53 +0200 Message-Id: <83cz9lex3y.fsf@gnu.org> From: Eli Zaretskii To: Olivier Certner In-Reply-To: <7839380.iDzAj6rjnq@ravel> (message from Olivier Certner on Thu, 10 Nov 2022 19:35:28 +0100) Subject: Re: bug#59182: Proposed fix References: <1855192.vslOlgHxSZ@ravel> <7839380.iDzAj6rjnq@ravel> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 59182-done Cc: 59182-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Olivier Certner > Date: Thu, 10 Nov 2022 19:35:28 +0100 > > On top of emacs-28 branch (49a14c4375ce4c2c). > > The fix is "minimal", in the sense that it doesn't try to refactor/modify unrelated code. Thanks, I've now installed this on the master branch, and I'm closing the bug. From unknown Mon Aug 18 14:23:50 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 15 Dec 2022 12:24:15 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator