Opened 18 years ago
Last modified 9 years ago
#4329 new defect
diff does not treat TAB as whitespace
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | unscheduled |
Component: | version control/browser | Version: | 0.10.3 |
Severity: | minor | Keywords: | diff review |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Checking the box to ignore whitespace still ends up highlighting changes from TAB to space(s).
Attachments (1)
Change History (16)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Component: | general → browser |
---|---|
Owner: | changed from | to
Version: | 0.10.2 → 0.10.3 |
I have just checked this and it is not quite true. The ignore whitespace functionality does work but not in the way this user expected.
If the diff turns up a changed section of the file and the only changes to that are whitespace then that section of changes is excluded when the whitespace box is ticked.
However, if a block contains both whitespace and other changes the entire section is shown in the diff listing and that section may include a number of lines which only have whitespace changes.
I would expect the whitespace changes to be discarded more completely so that only the lines of the files which have non-whitespace changes are shown.
comment:3 by , 18 years ago
Keywords: | diff added |
---|---|
Milestone: | → 1.0 |
Priority: | normal → low |
Severity: | normal → minor |
Thanks for the above explanations. Indeed, this looks like an useful thing to do, but it's not completely trivial to do (markup_intraline_changes
would have to have extra logic to ignore whitespace changes).
comment:4 by , 18 years ago
I just ran into this too, and after looking at it have another idea. What if when given a "changed" diff block, Trac would rediff it with all whitespace stripped to discover which lines are actually "equal" when ignoring whitespace?
comment:5 by , 18 years ago
Milestone: | 1.0 → 0.11 |
---|
/me being lazy, can you post that diff so that I can test the above idea?
follow-up: 7 comment:6 by , 18 years ago
Essentially it boils down to this source text:
print "Hi!"
to
def x(): print "Hi!"
My scheme would take the tokens already generated:
('change', 0, 1, 0, 2)
…and rediff each change
token's data (in this case, src[0:1]
with dst[0:2]
) after stripping the whitespace, then replace the change
token with these (of course with the line numbers adjusted). This gives something like
('insert', 0, 0, 0, 1) ('equal', 0, 1, 1, 2)
if the diff opcodes in my head are working correctly.
comment:7 by , 18 years ago
Replying to thatch:
…and rediff each
change
token's data (in this case,src[0:1]
withdst[0:2]
) after stripping the whitespace, …
Ok, I see. This is far more complex than what I've thought, so thanks for the clarification. I was thinking about diffs having the same number of lines only, but now I see that this can also happen in the general situation.
Well, I don't know, the solution you propose should work but could be quite costly if firing up a diff is expensive.
Also, one shouldn't ignore whitespace changes when diffing python code ;)
comment:8 by , 18 years ago
Milestone: | 0.11 → 1.0 |
---|---|
Owner: | removed |
comment:9 by , 18 years ago
Keywords: | review added |
---|---|
Owner: | set to |
Status: | new → assigned |
See attachment:whitespace-diff.diff for a less smart method that works and is more readable. However it doesn't do the fancy (and presumably expensive) twiddling with rediffing that I originally considered, so I wouldn't be surprised if it's competitively fast.
comment:10 by , 18 years ago
Hmm, after driving back from the conference I had another thought — my quick method doesn't handle blank line changes, those will still be highlighted if they're within the context diff, regardless of settings.
follow-up: 12 comment:11 by , 18 years ago
Just a quick comment about this comment in the patch:
# We should perhaps do the same for capitalization.
I can't think of any situation where "Ignore case change" could be useful. I'd rather like to remove this option.
comment:12 by , 17 years ago
Replying to cboos:
I can't think of any situation where "Ignore case change" could be useful. I'd rather like to remove this option.
Consider languages where case does not matter. Case changes may not change the semantics of the code there, which is what the reader of the diff is after.
For someone used to Python, the sentence “I can't think of any situation where "Ignore white space change" could be useful.” may be true.
comment:14 by , 13 years ago
This is annoying for xml changes as well. Whenever one checks in formatted xml, it always shows many whitespace differences despite ignore whitespace is checked. We would really appreciate if this is fixed
comment:15 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Further details:
The problem only seems to occur if the whitespace changes are 'near' some real changes.
Adding a couple of lines in the middle of a block of code using tabs, then converting the tabs to spaces results in the whole block being flagged as a change.