Question

In a branch of code I have changed all of the code from obj.varname to obj("varname") and when I compare the code I would like to ignore these differences since varname is the same.

I have a regular expression that I think I need but unfortunately can't get the comparison to be ignored using Beyond Compare from Scooter

^obj\("\w*"\)|obj\.\w*$

I am following this tutorial http://www.scootersoftware.com/support.php?zz=kb_unimportantv3

So my question: is this even possible with beyond compare? If yes, please share a solution including either instructions or post your screenshots.

Was it helpful?

Solution

Beyond Compare 3's Professional edition supports this through its Text Replacements feature. If you've already purchased a Standard edition license you need to revert to trial mode to test it: http://www.scootersoftware.com/suppo...?zz=kb_evalpro

  1. Load your two files in the Text Compare.
  2. Open the Session Settings dialog from the the Session menu, and on the Replacements tab click New to create a new replacement.
  3. In the Text to find edit, use (\w+)\.(\w+)
  4. In the Replace with edit, use $1("$2")
  5. Check the Regular expression checkbox.

The alternative would be to mark any instance of obj.varname and obj("varname") as unimportant. The basic steps would be this:

  1. Load your two files in the Text Compare.
  2. Open the Session Settings dialog from the Session menu, and on the Importance tab click the Edit Grammar... button.
  3. In the next dialog click the New... button below the top listbox.
  4. Change the Element name field to something useful (say, "PropertyAccess").
  5. Change the Category* to List.
  6. In the Text in list* edit, add these two lines:

    obj.varname
    obj("varname")

  7. Click OK to close the Grammar Item dialog and then click OK again to close the Text Format* grammar item.

  8. Uncheck "PropertyAccess" (or whatever you named it) in the Grammar elements listbox in the Session Settings dialog, then click OK to close it.

This approach isn't as flexible or clean. In the steps above you're matching specific, hardcoded object and variable names, so obj.varname is unimportant but obj.othervar isn't, even if it's aligned against obj("othervar"). If text on both sides is unimportant the difference will be unimportant; if one side is important it will be an important difference. So, with the above steps, obj.varname and obj("varname") will be unimportant everywhere, but it will work correctly since they'll either be matched to other cases that also match those definitions (and thus unimportant) or will be matched to something else that doesn't match that definition, which will be important and will make the difference important.

You can use regular expressions to match more general text categories, but you probably don't want to. For example, if you wanted to match all text that followed that pattern you could use these two lines instead:

\w+\.\w+
\w+\("\w+"\)

And then check the Regular expressions checkbox in the Grammar Item dialog so they're matched that way.

The upside/downside to that is that any text that matches those patterns is then unimportant. abc.newvar vs. def.varname would be considered an unimportant difference because both sides match the unimportant definition. That's good for things like comments or whitespace changes, but probably isn't what you want to do here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top