0

In Beyond Compare, how do you ignore a line on both sides depending on a text on the right side?

e.g.

File 1

if (a==b)
{
    c++;
    d--;
    //e--;
    f--;
}

File 2

if (a==b)
{
    c++;
    //d--; /* GG2018 */
    e--;
    //f--;  
}

I want beyond compare to show the line of d-- as having minor differences. The line of e-- and f-- should be shown as major differences. This is based on the word GG2018

I have tried grammar and importance, but only for line d--, one side is shown as unimportant. The left side is shown in red and does not have minor differences.

Edit: The files are in C, and the grammar rule is

GG2018=Text matching ^.*GG2018.*

GG2018 set as unimportant.

Also a rule for Unimportant text was created as --

^.*GG2018.*

Edit2: Added line e-- and f-- in example above.

Also, The identifier GG2018 comment location can be modified if the rules can be made easier.

** Method 2 **

//d--; /* GG2018 */  changed to         /* GG2018 */ //d--; 

Expected results are the same as before.

Rishikesh Raje
  • 8,556
  • 2
  • 16
  • 31

2 Answers2

1

You didn't show your grammar and importance setting so it is difficult to giva an answer. But the code looks like Java or C. So my answer is based on the assumption you use the default Java File Format of BC4.

I think you overlooked the // in your 2nd file. With this comment flag it is no minor difference, it is a very important difference: enter image description here

If you remove the comment flag in file two you get only minor changes, if you set the rule Java. enter image description here

knut
  • 27,320
  • 6
  • 84
  • 112
  • The purpose of the extra comment is to not show all lines with the comment GG2018. This comment indicates that these lines are reviewed and are differences are expected to be there. So, even if there is some other important change, the difference should be ignored. – Rishikesh Raje Jan 29 '18 at 00:00
1

Even if the text is the same, if the grammar element type is different, then Beyond Compare will show it as a difference.

The Text Compare shows the grammar element type at the current cursor position in the status bar at the bottom of the window. If you cursor to the d in the d--; line on the left, it shows the left grammar element is Identifier, the right grammar element is Comment. This will always be a difference because the element types are different.

It isn't possible to ignore the differences in your example using unimportant grammar. If you have a Beyond Compare Pro license, you can ignore the difference using a text replacement.

Load the files in the Text Compare with d--; on the left, //d--; /* GG2018 */ on the right.

  1. Click the Rules toolbar button (referee icon).
  2. Go to the Replacements tab.
  3. Click + to add a replacement.
  4. Text to find: (\s+)//(.*) /* GG2018 */
  5. Replace with: $1$2
  6. Check Regular expression.
  7. Set Side: to Right.

Expressions in () are grouped and saved in the variables $1 through $9.

Chris Kennedy
  • 2,639
  • 12
  • 11
  • Thanks fir your answer, However I think that in the above method, other differences will be masked. e.g. File 1 -> e--; File2 -> \\e--; ..... In Such a case, the difference is required to be seen. – Rishikesh Raje Feb 01 '18 at 00:19
  • Based on your updated example, you'll need to use a text replacement instead of defining unimportant grammar. See updated instructions in my answer. Note that text replacements are a Pro only feature of Beyond Compare. – Chris Kennedy Feb 05 '18 at 20:12