GNOME Bugzilla – Bug 547743
Files whose only difference is line endings are shown as different
Last modified: 2015-02-10 19:45:09 UTC
I've got two files (different revisions of a program that should have been under revision control, but wasn't) that are marked in the Meld GUI as being different, but when I open them up there's no markings for different sections. Opening the two files up in vim shows me that the only difference is line endings, which was not apparent in Meld. Meld should either have an option to ignore this, or to fix this for otherwise unchanged files (as opposed to the current option which only triggers when a file has been edited) with possibly some icon/other marking denoting that these files differ in line endings.
I don't think that Meld can't realistically show files that differ in only line endings (or similar criteria) as the same in the directory or version control view; doing that would require doing a (possibly very) slow comparison of each file in the tree. Maybe some notification would be appropriate (maybe using something like gedit's message area?) that the files only differ in line endings. However, exposing all of the possibilities to fix that (make all DOS, make all unix, merge line endings left, merge line endings right, do nothing) might be a little excessive.
Dirdiff already does a full comparison of the files with regex substitution etc, so it's not too bad to check line endings too. Maybe dirdiff _files_same should try to open files with universal line endings by default? The hard part methinks is the UI. Meld needs a notification area + search bar etc for this to work. As Kai says, I don't think this is practical for version control as it involves a roundtrip.
I'd think it would make the most sense to simply use the same preferences as defined in "Text Filters". After all, if I want to ignore those inside the file, it makes sense that I'd like to ignore them at the directory level too. So, if this preference option is added, why not add it there. It would be great to have this, even if limited to local files. I use Meld almost exclusively on local files/directories, and it would be very useful to have the directory diffs correctly reflect what I'd see in the file diff (e.g. if I ignore extra lines in file contents, they're not flagged in the directory diffs).
*** Bug 570389 has been marked as a duplicate of this bug. ***
I second the comment #3. I thought that meld uses Text Filters in dirdiff and I think this would be the best approach - the most intuitive.
Just making notes for posterity. We already use text filters in dirdiff. There's limits to this, but basically all text filters get applied. This doesn't actually help this bug however, since filters that change newlines (such as the filter you'd need to normalise line endings) break file comparisons. Fixing this particular bug would have to look something like: * Sniff file for mime type * If it looks like text, try to open it as such using universal newlines * If it looks like binary, just treat it as bytes (this is what we currently do)
I used the instructions from http://rootfs.wordpress.com/2011/03/09/ubuntu-ignore-line-ending-differences-in-the-meld-tool/ to achieve this behavior, which seemed to work fine in my case. Quote from that site: Edit -> Preferences -> Text Filters -> New a patten with a name something like “line ending” and regex “\r+$” and check the Active check box. Refresh or restart the Meld.
Just to explain why that solution can't be in Meld by default... That will work fine in some cases, but break others badly. In particular, that will work if the line endings that differ are '\r\n' and '\n', and should have no noticeable effect in the actual file comparison either. However, if you're unlucky enough to have '\r' ending files, then you'll still get false positives in folder comparisons, *and* file comparisons will break badly (because the filter is changing the number of lines in the file, which we don't support).
*** Bug 743872 has been marked as a duplicate of this bug. ***
In current master, Meld now notifies in file comparisons if the files are identical, but have different line endings. This doesn't fix this bug, but at least it means that the user can see why the two views differ.
In current master, there is now a new (enabled by default) preference to apply text filters during folder comparisons. We've always done this; being able to turn it off is what's new. When this preference is enabled, we also normalise line endings, so files that are identical except for their line endings are shown in the same was as files that are identical once filters have been applied (normal weight and colour, with italics). This *does* fix the bug, and with the other change to filediff, it's also fairly obvious what happened at the per-file level.