Guest User

http://stackoverflow.com/questions/15988796/is-there-a-file-

a guest
Apr 16th, 2013
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----------------
  2. Title: Is there a file comparison/diffing tool that considers whitespace less important while not ignoring it?
  3. Tags: diff
  4. -----------------
  5. In the codebase I work on, people take indentation very seriously; not just for control structures (if, while, functions, etc.) but also parameters of functions on multiple lines, content inside comments, etc. What I observe in the graphical diff and merging tools I have used is that they seem to work as follows:
  6.  
  7. - do the usual line diffing
  8. - do character diffing within each difference hunk thus found
  9.  
  10. While this works for the most part, when there is an indenting difference (say something has been wrapped in an if) I get suboptimal results, a bit as if the tool told me "Nope, these lines are different: in the second file there are four more spaces, they cannot possibly be related, same for this one… Ooh, shiny, two closing braces at the same indentation level! They must necessarily match! Let me move around the lines before and after these braces so that the braces can match, and prevent these (actually related) moved lines from being compared character by character! There, aren't you glad I did all the work for you?" This is even worse when you want to do a merge, good luck figuring out where a single-line change from base to right must land when the same section has been indented between base and left.
  11.  
  12. Ignoring whitespace works only to a point here, I do want to review whitespace changes, and I do want the merged single-line change to end up as the right indentation level, for example.
  13.  
  14. So my question is, is there a file comparison/diffing tool (graphical or not), or an algorithm, that would have more sensible behavior: take whitespace changes into account, but consider them much less important than other changes, so that matching works better with indentation or other whitespace-only changes? Seems to me I am not alone with this issue, and it could even be as simple as doing the line diffing while ignoring whitespace but then doing the character diffing while taking it into account.
  15.  
  16. --------
  17.  
  18. Answer 1:
  19. As a general rule, I don't think you are actually interested in the whitespace; the code (in many languages) mostly doesn't care. You want to compare the code structure. See http://stackoverflow.com/a/2828866
  20.  
  21. --------
  22.  
  23. Answer 2:
  24. Our program, [Beyond Compare][1], does that. It classifies text as important (strings, identifiers, operators, etc) and unimportant (comments, whitespace). The alignment is done on the important text first and the unimportant text afterwards, and it shows the important and unimportant differences in different colors so it's obvious what kind it is.
  25.  
  26. [1]: http://www.scootersoftware.com/
RAW Paste Data