* bug#59182: 28.1; ediff: Merges with ancestor: Fix computation of hunks and proposed merge
@ 2022-11-10 18:29 Olivier Certner
2022-11-10 18:35 ` bug#59182: Proposed fix Olivier Certner
0 siblings, 1 reply; 3+ messages in thread
From: Olivier Certner @ 2022-11-10 18:29 UTC (permalink / raw)
To: 59182
[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]
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
[-- Attachment #2: local.txt --]
[-- Type: text/plain, Size: 10 bytes --]
4
5
1
2
3
[-- Attachment #3: ancestor.txt --]
[-- Type: text/plain, Size: 12 bytes --]
1
2
3
4
5
6
[-- Attachment #4: other.txt --]
[-- Type: text/plain, Size: 10 bytes --]
4
5
6
1
2
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#59182: Proposed fix
2022-11-10 18:29 bug#59182: 28.1; ediff: Merges with ancestor: Fix computation of hunks and proposed merge Olivier Certner
@ 2022-11-10 18:35 ` Olivier Certner
2022-11-17 9:41 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: Olivier Certner @ 2022-11-10 18:35 UTC (permalink / raw)
To: 59182
[-- Attachment #1: Type: text/plain, Size: 157 bytes --]
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
[-- Attachment #2: 0001-ediff-Merges-with-ancestor-Fix-computation-of-hunks-.patch --]
[-- Type: text/x-patch, Size: 4275 bytes --]
From 49a14c4375ce4c2c260f52db53d151742f6edeff Mon Sep 17 00:00:00 2001
From: Olivier Certner <olce.emacs@certner.fr>
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#59182: Proposed fix
2022-11-10 18:35 ` bug#59182: Proposed fix Olivier Certner
@ 2022-11-17 9:41 ` Eli Zaretskii
0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2022-11-17 9:41 UTC (permalink / raw)
To: Olivier Certner; +Cc: 59182-done
> From: Olivier Certner <ocert.dev@free.fr>
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-17 9:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10 18:29 bug#59182: 28.1; ediff: Merges with ancestor: Fix computation of hunks and proposed merge Olivier Certner
2022-11-10 18:35 ` bug#59182: Proposed fix Olivier Certner
2022-11-17 9:41 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.