Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 210688

Summary: Three-way compare shows wrong changes
Product: [Eclipse Project] Platform Reporter: Markus Keller <markus.kell.r>
Component: CompareAssignee: Michael Valenta <Michael.Valenta>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: Michael.Valenta, Mike_Wilson, sseidel, Szymon.Brandys, tomasz.zarna
Version: 3.4Flags: Mike_Wilson: pmc_approved+
tomasz.zarna: review+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
files
none
Patch that fixes the problem
none
Confusing comparisons
none
An exception thrown while reproducing 34746
none
Patch for consideration for inclusion in 3.3.2 none

Description Markus Keller CLA 2007-11-22 12:04:55 EST
Created attachment 83547 [details]
files

I20071120-1300 and 3.3, was OK in 3.2.2, maybe the same problem as bug 196147

Three-way compare sometimes shows wrong changes. Compare the three files in the attachment and choose anc.txt as ancestor.

The included screenshot shows how the addition of K_SIMPLE_NAME on both children has not been detected as single pseudo conflict, but is rather interpreted as two changes. This makes three-way compares hard to use.
Comment 1 Michael Valenta CLA 2007-11-22 17:22:48 EST
I have verified that this is caused by the new differencer we added in 3.3. The differencer is only responsible for calculating a two way diff. A three way comparison is performing by diffing the ancestor and right and ancestor and left and then combining the results. The new differencer yields slightly different results from the old differencer but the results are still valid. In this particuar case, a two way compare between anc.txt and one.txt with the new differencer yields different results than with the old differencer. It turns out that the new diff is better from a java semantic standpoint but the diff of the anc.txt and two.txt is the same (and sematically worse) for both the old and new differencer which works out well with the old differencer but causes problems with the new differencer. I'm going to investigate how we could modify the diffs that the new differencer produces so that the results are consistent.
Comment 2 Michael Valenta CLA 2007-11-22 18:25:04 EST
Created attachment 83590 [details]
Patch that fixes the problem

It turns out this was my fault. When I converted the contributed algorithm to use IRangeComparator, I left out the part that shifted the diff as far down in the file as possible (i.e. when the lines before and after the diff are the same). Adding this shift fixes the problem. I have comitted the fix to head. We should consider contributing the fix to 3.3.2
Comment 3 Michael Valenta CLA 2007-11-22 18:27:44 EST
*** Bug 208864 has been marked as a duplicate of this bug. ***
Comment 4 Michael Valenta CLA 2007-11-22 18:38:39 EST
Tomek, can you look over the patch to make sure everything looks OK before we ask for PMC approval?
Comment 5 Michael Valenta CLA 2007-11-23 08:46:23 EST
*** Bug 196147 has been marked as a duplicate of this bug. ***
Comment 6 Tomasz Zarna CLA 2007-11-23 08:56:23 EST
I'm sure if there is much I can say about the patch itself without getting into details of the differencing algorithm. To provide some assistance I did the following:
* run tests on Windows and Linux (just in case)
* played around with the compare editor to make sure everything works fine
* I looked for any other bugs related to the problem, this way I could find other cases to check (as Markus did for bug 196147)

I found one case that made me a little bit worried. I had a file with outgoing changes, compared it with HEAD. With the compare editor opened I replaced the file with the latest version from HEAD, so both local and remote files became the same. But this was not what the compare editor showed me (ie it claimed that there some outgoing changes). After closing the editor and opening it again everything went back to normal. Please take a look at a following screen shot. I'm not if this is a related issue but thought it's worth mentioning.

BTW,You made me realized that it's high time for me to grab Myers' article and get familiar with the algorithm. I hope I will become more helpful next time.
Comment 7 Tomasz Zarna CLA 2007-11-23 08:58:00 EST
Created attachment 83634 [details]
Confusing comparisons
Comment 8 Tomasz Zarna CLA 2007-11-23 09:07:44 EST
Created attachment 83637 [details]
An exception thrown while reproducing 34746

I was trying to reproduce bug 34746 when I was hit by the attached exception.
Comment 9 Michael Valenta CLA 2007-11-23 10:13:56 EST
Tomek, thanks for the additional testing. The problem was that the array can be null if one of the inputs is empty but that only occurs for the structure compare since a text compare assumes that each input has at least one line even if there are no characters. I've added the null check to head.
Comment 10 Tomasz Zarna CLA 2007-11-26 09:41:11 EST
I'm glad I could help. 

After further investigation it seems that the issue I mentioned in comment 6 is not related to the patch you provided. I will check if there is a bug for it and if not will log a new one.

Again, as mentioned in comment 6 I treated the differencer as a block-box. I haven't been able to find any other issues so I'll give the patch a "+".
Comment 11 Michael Valenta CLA 2007-11-27 16:43:40 EST
Created attachment 83901 [details]
Patch for consideration for inclusion in 3.3.2
Comment 12 Michael Valenta CLA 2007-11-27 16:45:52 EST
The latest patch addresses the issue in comment 8 and is optimized to compress and shift the LCS in place instead of creating another array. I think we should consider this for 3.3.2 since it is a regression and results in confusing false conflicts in the compare editor.
Comment 13 Michael Valenta CLA 2007-11-29 16:40:56 EST
Fix released to 3.3.2
Comment 14 Tomasz Zarna CLA 2008-01-17 07:54:51 EST
Verified in I20080115-0800.