Guest User

a guest
Apr 16th, 2013
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  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:
  7. - do the usual line diffing
  8. - do character diffing within each difference hunk thus found
  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.
  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.
  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.
  16. --------
  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
  21. --------
  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.
  26. [1]:
Add Comment
Please, Sign In to add comment