1

Is there a diff tool that allows me to write regular expression to remove a line from difference?

Like, see the two lines:

this.Visible = true;
Visible = true;

And can I write an expression such that if the line difference is exactly this ignore the difference.

How do I specifically do that?

I give you one more example. Like System.Exception and Exception both are same for me, I don't want to show them in the diff.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Priyank Bolia
  • 12,942
  • 13
  • 57
  • 81
  • Instead of forcing a diff tool to do the exact opposite of what it's supposed to do (show you what is different), and relying on availability of such a tool, why not use a simple tool like sed or m4 to patch the file first? – z5h Dec 22 '09 at 19:48
  • patching file would change contents, and how would you patch a file partially, not all this or System are removed. I just want to ignore those that causing any diff. – Priyank Bolia Dec 22 '09 at 20:10
  • 2
    The other thing I would consider is that this is simply a bad practice. this.xxx does not mean the same thing as xxx. The first gets you the xxx property of the current object, the second gets the xxx in the nearest scope. There could be a bug that you miss as a result of ignoring the differences. It just seems like a bad habit to get into. In any case, good luck in finding a solution. – z5h Dec 22 '09 at 20:15
  • I suppose that it depends on why you are doing the diff in the first place. Presumably, it's part of your source control check-in process? If so, then just take the opportunity to resolve the differences between the 2 files (To whatever your organisations coding standard is) and check the file in - the problem should then no longer be an issue. My apologies if my assumptions are incorrect – belugabob Dec 24 '09 at 09:49
  • @belugabob: Ok, let me explain, first of all I don't care whether I am removing correct 'this.' or not, I have lots of such differences and I want to focus on just the important one, and 'this.' is non important to me, as most of the refactoring is done by me only using CodeRush, so I know they are right, but before checking I need to double check what I am checking in. Why this feature is important may be the http://www.scootersoftware.com/videos/WN3Replacements.html video will explain more, but this is important to me. "resolve the differences between the 2 files" I don't get how's that diff – Priyank Bolia Dec 24 '09 at 10:03

8 Answers8

3

You can do this with KDiff3. See the documentation section on Preprocessor Commands.

Update: I see you have a further request that appears to need a semantic diff program. See Semantic Diff Utilities for some suggestions.

Community
  • 1
  • 1
Greg Hewgill
  • 828,234
  • 170
  • 1,097
  • 1,237
  • Can you explain more, as I guess the preprocessor matches the whole line and you can't specify ignore when the difference is this. – Priyank Bolia Dec 22 '09 at 18:25
  • Right, you can't directly say "ignore this kind of difference". However, you can normalise the inputs so that the differences no longer appear. For example, to ignore the case of letters in the inputs, you might convert all uppercase characters to lowercase using the "line-matching preprocessor command". For your example, you could remove all instances of `this.` from your input lines using the same filter. – Greg Hewgill Dec 22 '09 at 18:30
  • that would give completely wrong results and that is not my question. I guess WinMerge also have line filtering. I am interested in Diff filtering. – Priyank Bolia Dec 22 '09 at 18:32
  • It sounds like you're more interested in a semantic diff, rather than a textual diff. I've updated my answer with a link to more info. – Greg Hewgill Dec 22 '09 at 18:42
  • that has accepted answer as Eclipse, which is no use to C# people. Also I still looking for something configurable rather than semantic diff, though I am doing semantic diff only, but hide only the diff that I am interested in. – Priyank Bolia Dec 22 '09 at 18:53
1

DiffMerge from SourceGear supports this. You'll need to create a Ruleset that matches the files you are merging or edit the default Rule set. In the ruleset add patterns to the Lines to Omit property. See the Ommitted Lines property in the online help for more info.

David Norman
  • 18,146
  • 11
  • 60
  • 53
1

The best source comparing software that I ever used was Beyond Compare. With it, you could do exactly what you asked for: input a regular expression that told the software to ignore certain differences. However, it's not free.

If you really need a free applicative, you can try WinMerge. I'm not very fond of the interface, though.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Bruno Brant
  • 7,558
  • 5
  • 40
  • 76
  • And how to do that in BeyondCompare, I can't find a option in that, the interface is pretty messy. – Priyank Bolia Dec 22 '09 at 20:11
  • 1
    On version 2, on "File Compare", go to "Tools"->"Pick Rules"->"New rules". Then go to Importance tab, and on Unimportant Text click on "New", choose "Regular Expression", and ta-da! – Bruno Brant Dec 22 '09 at 21:07
  • If you are using version 3, let me know, I will look for the configuration. – Bruno Brant Dec 22 '09 at 21:09
  • Thanks I asked the support, and it looks like it working. Its in the Rules replacement tab. There is no Unimportant Text in ver 3. I guess they have modified it. – Priyank Bolia Dec 22 '09 at 21:21
  • this\.(.*) <> $1 available under the Text Compare's Session menu -> Session Settings, Replacements tab – Priyank Bolia Dec 22 '09 at 21:22
0

Notepad++ has a compare plugin, which is pretty configurable.

Jay Zeng
  • 1,407
  • 10
  • 10
0

If you can't find an existing diff tool that will do what you want, you could write your own.

Python has a diff module for writing diff-like tools, which will handle all the complexities of the diffing algorithm for you. They have an example script that will do a file diff in standard Unix diff/patch format or side-by-side HTML in 60 lines of code.

The differs in the module let you define 'junk' filters to pre-process lines to remove parts that you do not want included in the diff. These are Python functions, so you are not limited to regular expression matches.

I had a quick re-read of the documentation, and the filters only work for ignoring whole lines or individual chars, which is not what you want. However, you can easily pre-process the data you feed into the differ to remove the text you want to ignore.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Dave Kirby
  • 23,068
  • 5
  • 60
  • 79
0

I was not able to find the feature in any software, though Beyond Compare and Araxis have this feature.

From the WinMerge wiki it looks like they won't support plugins or any such feature in new future. Too bad.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Priyank Bolia
  • 12,942
  • 13
  • 57
  • 81
0

If you know how to write JavaScript you can insert the regular expression in question into the minification portion of the Pretty Diff tool. The tool is entirely free and the code is completely open with inline documentation.

If there is a specific feature you would like added to the tool, aside from a personal customization, please let me know, and I will add it.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
  • To be honest, it doesn't look like a diff tool, in any sense. A good tool is one that doesn't need any time to learn and a good UI is that: Don't make me think. – Priyank Bolia Jan 01 '10 at 08:48
  • You get what you pay for. A good tool is one that comes with well written documentation. –  Jan 01 '10 at 15:29
0

Try GNU diffutils. If you are on Windows, you can have GNU diff distributed with Cygwin from www.cygwin.com.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Ken
  • 1
  • don't think it is any different, it suppress the whole line as others and not just the difference. Correct me please, if I am wrong. – Priyank Bolia Jan 01 '10 at 08:45