[meld] dirdiff: Filter line endings when comparing file contents (bgo#547743)



commit 353a360db475e5d68d47e2c5d7074f0b5ea4513f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Feb 10 06:25:22 2015 +1000

    dirdiff: Filter line endings when comparing file contents (bgo#547743)
    
    This commit changes the behaviour of folder comparisons for text files
    where the only difference is the end-of-line characters. For symmetry
    with file comparisons, folder comparisons now treat these as being
    "Same, with filtering" files, indicated by italics in the file name.
    Along with the new notifications in file comparisons, this should get
    rid of a lot of the confusion users had when folder comparison told
    them that files were different, but file comparison said they were
    identical.
    
    With this change, we now *always* need to read in the whole file (if
    we think it's not binary) because we're effectively always applying a
    text filter.
    
    This commit also adds the final piece of handling for the new
    'apply-text-filters' preference, which was introduced precisely because
    users may want to opt out of the new, slow always-read-all-the-files
    behaviour.

 meld/dirdiff.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index ec52356..c0fc310 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -119,7 +119,7 @@ def _files_same(files, regexes, comparison_args):
     time_resolution_ns = comparison_args['time-resolution']
     ignore_blank_lines = comparison_args['ignore_blank_lines']
 
-    need_contents = regexes or ignore_blank_lines
+    need_contents = comparison_args['apply-text-filters']
 
     # If all entries are directories, they are considered to be the same
     if all([stat.S_ISDIR(s.mode) for s in stats]):
@@ -141,7 +141,7 @@ def _files_same(files, regexes, comparison_args):
         return Different
 
     # Check the cache before doing the expensive comparison
-    cache_key = (files, regexes, ignore_blank_lines)
+    cache_key = (files, need_contents, regexes, ignore_blank_lines)
     cache = _cache.get(cache_key)
     if cache and cache.stats == stats:
         return cache.result
@@ -190,6 +190,9 @@ def _files_same(files, regexes, comparison_args):
 
     if result == Different and need_contents:
         contents = ["".join(c) for c in contents]
+        # For probable text files, discard newline differences to match
+        # file comparisons.
+        contents = ["\n".join(c.splitlines()) for c in contents]
         for r in regexes:
             contents = [re.sub(r, "", c) for c in contents]
         if ignore_blank_lines:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]