diff mercurial/mdiff.py @ 9827:4fe9ca519637

mdiff: fix diff -b/B/w on mixed whitespace hunks (issue127) Previous code was computing hunks then checking if these hunks could be ignored when taking whitespace/blank-lines options in accounts. This approach is simple but fails with hunks containing both whitespace and non-whitespace changes, the whole hunk is emitted while it can be mostly made of whitespace. The new version normalize the whitespaces before hunk generation, and test for blank-lines afterwards.
author Patrick Mezard <pmezard@gmail.com>
date Wed, 11 Nov 2009 18:31:42 +0100
parents 9e055cfdd620
children 7637fe4f525d
line wrap: on
line diff
--- a/mercurial/mdiff.py	Wed Nov 11 17:02:00 2009 +0100
+++ b/mercurial/mdiff.py	Wed Nov 11 18:31:42 2009 +0100
@@ -57,13 +57,13 @@
 
 defaultopts = diffopts()
 
-def wsclean(opts, text):
+def wsclean(opts, text, blank=True):
     if opts.ignorews:
         text = re.sub('[ \t]+', '', text)
     elif opts.ignorewsamount:
         text = re.sub('[ \t]+', ' ', text)
         text = re.sub('[ \t]+\n', '\n', text)
-    if opts.ignoreblanklines:
+    if blank and opts.ignoreblanklines:
         text = re.sub('\n+', '', text)
     return text
 
@@ -183,6 +183,10 @@
     # below finds the spaces between those matching sequences and translates
     # them into diff output.
     #
+    if opts.ignorews or opts.ignorewsamount:
+        t1 = wsclean(opts, t1, False)
+        t2 = wsclean(opts, t2, False)
+
     diff = bdiff.blocks(t1, t2)
     hunk = None
     for i, s1 in enumerate(diff):
@@ -208,7 +212,7 @@
         if not old and not new:
             continue
 
-        if opts.ignorews or opts.ignorewsamount or opts.ignoreblanklines:
+        if opts.ignoreblanklines:
             if wsclean(opts, "".join(old)) == wsclean(opts, "".join(new)):
                 continue