WinMerge / winmerge

WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
https://winmerge.org/
GNU General Public License v2.0
6.57k stars 801 forks source link

Substitution filters and PrediffLineFIlter.sct plugin not working #1939

Open tumatanquang opened 1 year ago

tumatanquang commented 1 year ago

I am using version 2.16.30 (x64-PerUser). I want to ignore parts of the line so I wrote the rules according to two comments #597525 and #303958: These are rules in PrediffLineFIlter.sct: image P/s: I have correctly edited the desired file extension: image These are rules in Substitution Filters: image However, all of them do not work (red frame part): image I tried to disable 1 of 2 then tried again but the results were still similar. Something is not right here? Why does it not ignore the part of the line based on the rules that I have made?

sdottaka commented 1 year ago

Unfortunately, "Replace with" doesn't allow you to specify a regular expression. If you change the settings of the PrediffLineFilter plugin as follows, will it work? image

tumatanquang commented 1 year ago

Unfortunately, "Replace with" doesn't allow you to specify a regular expression. If you change the settings of the PrediffLineFilter plugin as follows, will it work? image

No, it doesn't work either! image

sdottaka commented 1 year ago

To reproduce the problem, we need to at least know all the characters to the left and right of the line. Could you put all the characters on the left and right of that one line here?

tumatanquang commented 1 year ago

To reproduce the problem, we need to at least know all the characters to the left and right of the line. Could you put all the characters on the left and right of that one line here?

Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2); I also tried to disable Use RegExp but it did not work. image

sdottaka commented 1 year ago

I think the below regex will do the trick.

Find what: (([^(]+) >> Macro.BW_(\d+)) Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

image

tumatanquang commented 1 year ago

I think the below regex will do the trick.

Find what: (([^(]+) >> Macro.BW_(\d+)) Replace with: $1 / $2

image

It does not work: image I tried escaped dot but it was the same, did not work: image

sdottaka commented 1 year ago

I'm sorry. It appears that the backslashes disappeared due to the rules of markdown. How about changing it to the following?

Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

tumatanquang commented 1 year ago

I'm sorry. It appears that the backslashes disappeared due to the rules of markdown. How about changing it to the following?

Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

Yes, it worked in specific cases: Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2);

Macro.BW_16 will only identical with 2 values are: / 16 or >> 4 And will NOT be identical to other values with the above two values. The above regex rules can only match the first value (/ 16).

Left line: new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16)}; Right line: new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)}; P/s: Only differ in >> Macro.BW_16 and/ 16 but also do not ignore it.

sdottaka commented 1 year ago

Unfortunately, it's hard to get those patterns to work.

If you can tolerate the side effect of ignoring the difference between "(" and ")" then something like the following will work.

image

tumatanquang commented 1 year ago

Unfortunately, it's hard to get those patterns to work.

If you can tolerate the side effect of ignoring the difference between "(" and ")" then something like the following will work.

image

Certainly, I don't care about ignoring the difference between "(" and ")", but maybe you are misunderstood my point. Examples of the case of ignoring and not ignoring:

Find what: >> Macro.BW_16 Replace with: / 16 => will ignore Replace with: >> 4 => will ignore Replace with: / 4 OR >> 8 (and other value) => will NOT ignore

Examples of identical and non-identical cases that I would like:

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 16 - 2); => Will identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 4) - 2); => Will identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 8 - 2); => Will NOT identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 8) - 2); => Will NOT identical.

Your 4th – 7th regex rule is misinterpreting what I meant. And all those rules won't work in cases where the front of that line contains something:

Left line: return new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16)}; Right line: byte[] _xy = new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)};

sdottaka commented 1 year ago

Perhaps I am misunderstanding, but I think it is to be expected that the following differences are not ignored.

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 8 - 2); => Will NOT identical.

If the Right line is (Macro.SCREEN_WIDTH / 16 - 2); I can see that the difference would be ignored, but since it is 8 and not 16, the result seems correct.

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 8) - 2); => Will NOT identical.

Similarly, if the Right line were (Macro.SCREEN_WIDTH >> 4 - 2); I can see that the difference would be ignored, but since it is 8 and not 4, the result seems correct.

Left line: return new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16 )}; } Right line: byte[] _xy = new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)};

Unfortunately, if even a portion of the resultant lines substituted by the substitution filter do not match, the differences in those lines are not ignored. This is a limitation of the current substitution filter: if "byte[] _xy = " at the beginning of the Right line is "return" then the difference will be ignored.

tumatanquang commented 1 year ago

Perhaps I am misunderstanding, but I think it is to be expected that the following differences are not ignored.

If the Right line is (Macro.SCREEN_WIDTH / 16 - 2); I can see that the difference would be ignored, but since it is 8 and not 16, the result seems correct.

Similarly, if the Right line were (Macro.SCREEN_WIDTH >> 4 - 2); I can see that the difference would be ignored, but since it is 8 and not 4, the result seems correct.

I mean you misunderstood these syntax: image

Find what is always: >> Macro.BW_X. It will be identical to: >> X or X / 2. Suppose: >> Macro.BW_16 will be identical to >> 4 or identical to / 16 (>> Macro.BW_16 identical [>> 4 || / 16]).

Unfortunately, if even a portion of the resultant lines substituted by the substitution filter do not match, the differences in those lines are not ignored. This is a limitation of the current substitution filter: if "byte[] _xy = " at the beginning of the Right line is "return" then the difference will be ignored.

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case: image

sdottaka commented 1 year ago

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case:

I understand that you want to ignore the difference between ">> Macro.BW_16" and "/16", but unfortunately the current Substitution filters only apply per line. If the difference between "byte[] _xy" and "return" is resolved, the difference on that line will be ignored.

tumatanquang commented 1 year ago

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case:

I understand that you want to ignore the difference between ">> Macro.BW_16" and "/16", but unfortunately the current Substitution filters only apply per line. If the difference between "byte[] _xy" and "return" is resolved, the difference on that line will be ignored.

Yes. However, both the Substitution Filters and PrediffLineFilter.sct plugin are not working correctly. Now I just want it to ignore (not highlight) when encountering the cases that I have specified (>> Macro.BW_X). It doesn't matter if it ignores other cases that have changes in the same line or not.

tumatanquang commented 1 year ago

@sdottaka I have created a Find what and Replace with table to indicate my desired behavior: For each value in the Find what column, if it has been changed to the corresponding value in the Replace with column, the tool will igore (not highlight) those changes. image

sdottaka commented 1 year ago

Unfortunately, the 5th to 8th definitions will not work. This is because these definitions are applied sequentially from the top, but "Macro.BW" has already been replaced with "/ " by the 1st to 4th definitions. Therefore, when applying the 5th to 8th definitions, "Macro.BW" no longer exists.

tumatanquang commented 1 year ago

Unfortunately, the 5th to 8th definitions will not work. This is because these definitions are applied sequentially from the top, but "Macro.BW" has already been replaced with "/ " by the 1st to 4th definitions. Therefore, when applying the 5th to 8th definitions, "Macro.BW" no longer exists.

It seems that this is a highlight error that has occurred. As far as I understand, the PrediffLineFilter.sct plugin will replace the Find what value with the corresponding value in Replace with. In the example case you provided: Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2); The left line will be replaced with: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH / 16) - 2); If so, the tool should only highlight left line as follows: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); But in reality, it has ignored all the changes from the PrediffLineFilter.sct plugin and highlighted the changes as if there were no changes from the PrediffLineFilter.sct plugin.

sdottaka commented 1 year ago

Isn't it because there is a definition that ignores "(" and ")" like the following? Also, I think my wording is bad, so I'll say it again, Substitution filters such as PrediffLineFilter.sct are only applied line by line. Even if two lines are almost identical after being substituted by the Substitution filters, all inline differences will be highlighted if there are any remaining differences within the line.

image

tumatanquang commented 1 year ago

Isn't it because there is a definition that ignores "(" and ")" like the following? Also, I think my wording is bad, so I'll say it again, Substitution filters such as PrediffLineFilter.sct are only applied line by line. Even if two lines are almost identical after being substituted by the Substitution filters, all inline differences will be highlighted if there are any remaining differences within the line.

I apologize, because I explain it is confusing. I used Beyond Compare software. That software has the Replacements feature, I have set the rules I want. I want WinMerge to do the same thing:

image

P/s: The right-hand side of line 3 has been edited by me using photo editing software to change the value to / 16.

sdottaka commented 1 year ago

I understand that you want it to behave like the image above, but with the current WinMerge Substitution filters feature, you can't get results like the one above. I understand this issuse is an enhancement request.