diff mercurial/patch.py @ 35328:4937db58b663

patch: move part of tabsplitter logic in _inlinediff It cannot be entirely moved within _inlinediff as long as worddiff is experimental (when turned off, matches is always an empty dict).
author Matthieu Laneuville <matthieu.laneuville@octobus.net>
date Fri, 08 Dec 2017 17:20:11 +0900
parents 12ce62c72c24
children dce761558329
line wrap: on
line diff
--- a/mercurial/patch.py	Thu Dec 07 16:07:06 2017 -0800
+++ b/mercurial/patch.py	Fri Dec 08 17:20:11 2017 +0900
@@ -2510,16 +2510,15 @@
             for prefix, label in prefixes:
                 if stripline.startswith(prefix):
                     if diffline:
-                        for token in tabsplitter.findall(stripline):
-                            if '\t' == token[0]:
-                                yield (token, 'diff.tab')
-                            else:
-                                if i in matches:
-                                    for t, l in _inlinediff(
-                                                  lines[i].rstrip(),
-                                                  lines[matches[i]].rstrip(),
-                                                  label):
-                                        yield (t, l)
+                        if i in matches:
+                            for t, l in _inlinediff(lines[i].rstrip(),
+                                                    lines[matches[i]].rstrip(),
+                                                    label):
+                                yield (t, l)
+                        else:
+                            for token in tabsplitter.findall(stripline):
+                                if '\t' == token[0]:
+                                    yield (token, 'diff.tab')
                                 else:
                                     yield (token, label)
                     else:
@@ -2581,11 +2580,13 @@
 
     s = difflib.ndiff(re.split(br'(\W)', s2), re.split(br'(\W)', s1))
     for part in s:
-        if part[0] in operation_skip:
+        if part[0] in operation_skip or len(part) == 2:
             continue
         l = operation + '.highlight'
         if part[0] in ' ':
             l = operation
+        if part[2:] == '\t':
+            l = 'diff.tab'
         if l == label: # contiguous token with same label
             token += part[2:]
             continue