WinMerge - Is there a way to line up shifted/moved code blocks?
Asked Answered
S

2

12

When using WinMerge I am looking at a file that has had a block of code inserted into a function which causes the rest of the file to be out of sync in the comparison. Mine is much more complex but essentially the same as the simple example below:

  FILE 1                   FILE 2
1 int main() {             int main() {
2
3   int a = 3;               int a = 3;
4   a += 5;                  for(int i = 0; i < a; ++a)
5 }                             a += i;
6                           
7                            a += 5;
8                         }

WinMerge instead of recognizing the for-loop as an inserted block and showing the rest of the file the same it would show differences on line 4,5,6,7,8. I would expect it to sync line 4 of file 1 to line 7 of file 2 and make it a much cleaner diff. Is there a setting for this? I have played with the "Moved Code Block" setting but it simply highlights the matching code block later in the file instead of lining them up.

Any suggestions?

Sublingual answered 20/3, 2013 at 15:57 Comment(3)
After doing some research it does not appear to be possible. :(Sublingual
still not possible, or possible with any other tool?Banquette
Beyond Compare is a great diff tool that allows this. Unfortunately, it isn't freeGolliner
Q
9

Try this instead:

  • Select the line on the left file of the merge to match up.
  • Do the same on the right.
  • You now have 2 lines selected concurrently.
  • Menu merge -> Add Synchronization Point (Alt + S)

This will line up those lines on both files.

Quijano answered 11/5, 2023 at 2:30 Comment(1)
Thanks! The same result is possible in Beyond Compare with F7 but my client doesn't want to spring for a closed-source merge tool, so I'm learning and teaching them WinMerge.Aquileia
V
0

I know what you mean, but your example worked for me.

I have the problem when the compare syncs up on say, blank lines.

I'm looking into the line filter...

Virginiavirginie answered 9/4, 2013 at 20:9 Comment(2)
Thanks, for the follow up. The example I listed is pretty simplistic and it may actually work. But on a large file with many changes along with larger blocks of code changes like the one I listed it essentially calls the whole file different making the tool useless.Sublingual
A minimal working example would be useful here. Some of these diff issues come down to subtle changes like carriage returns, length of the line, etc.Superficies

© 2022 - 2024 — McMap. All rights reserved.