[PATCH] patch: move part of tabsplitter logic in _inlinediff

matthieu.laneuville at octobus.net matthieu.laneuville at octobus.net
Fri Dec 8 13:54:12 UTC 2017


# HG changeset patch
# User Matthieu Laneuville <matthieu.laneuville at octobus.net>
# Date 1512721211 -32400
#      Fri Dec 08 17:20:11 2017 +0900
# Node ID 06f6f388daf0d5177aa9d92bf92e9e8edf190a9f
# Parent  a1215935559d6e2afa49be0a1601b6ba8eaa7dbf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 06f6f388daf0
# EXP-Topic inline-diff
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).

diff -r a1215935559d -r 06f6f388daf0 mercurial/patch.py
--- a/mercurial/patch.py	Fri Dec 08 16:54:59 2017 +0900
+++ b/mercurial/patch.py	Fri Dec 08 17:20:11 2017 +0900
@@ -2510,16 +2510,15 @@ def difflabel(func, *args, **kw):
             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 @@ def _inlinediff(s1, s2, operation):
 
     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
diff -r a1215935559d -r 06f6f388daf0 tests/test-diff-color.t
--- a/tests/test-diff-color.t	Fri Dec 08 16:54:59 2017 +0900
+++ b/tests/test-diff-color.t	Fri Dec 08 17:20:11 2017 +0900
@@ -269,6 +269,9 @@ test inline color diff
   > this is the second line
   >     third line starts with space
   > + starts with a plus sign
+  > 	this one with one tab
+  > 		now with full two tabs
+  > 	now tabs		everywhere, much fun
   > 
   > this line won't change
   > 
@@ -281,11 +284,15 @@ test inline color diff
   > EOF
   $ hg add file1
   $ hg ci -m 'commit'
+
   $ cat > file1 << EOF
   > that is the first paragraph
   >     this is the second line
   > third line starts with space
   > - starts with a minus sign
+  > 	this one with two tab
+  > 			now with full three tabs
+  > 	now there are tabs		everywhere, much fun
   > 
   > this line won't change
   > 
@@ -301,15 +308,21 @@ test inline color diff
   [diff.diffline|diff --git a/file1 b/file1]
   [diff.file_a|--- a/file1]
   [diff.file_b|+++ b/file1]
-  [diff.hunk|@@ -1,13 +1,14 @@]
+  [diff.hunk|@@ -1,16 +1,17 @@]
   [diff.deleted|-this is the first line]
   [diff.deleted|-this is the second line]
   [diff.deleted|-    third line starts with space]
   [diff.deleted|-+ starts with a plus sign]
+  [diff.deleted|-][diff.tab|	][diff.deleted|this one with one tab]
+  [diff.deleted|-][diff.tab|		][diff.deleted|now with full two tabs]
+  [diff.deleted|-][diff.tab|	][diff.deleted|now tabs][diff.tab|		][diff.deleted|everywhere, much fun]
   [diff.inserted|+that is the first paragraph]
   [diff.inserted|+    this is the second line]
   [diff.inserted|+third line starts with space]
   [diff.inserted|+- starts with a minus sign]
+  [diff.inserted|+][diff.tab|	][diff.inserted|this one with two tab]
+  [diff.inserted|+][diff.tab|			][diff.inserted|now with full three tabs]
+  [diff.inserted|+][diff.tab|	][diff.inserted|now there are tabs][diff.tab|		][diff.inserted|everywhere, much fun]
    
    this line won't change
    
@@ -328,15 +341,21 @@ test inline color diff
   [diff.diffline|diff --git a/file1 b/file1]
   [diff.file_a|--- a/file1]
   [diff.file_b|+++ b/file1]
-  [diff.hunk|@@ -1,13 +1,14 @@]
+  [diff.hunk|@@ -1,16 +1,17 @@]
   [diff.deleted|-this is the ][diff.deleted.highlight|first][diff.deleted| line]
   [diff.deleted|-this is the second line]
   [diff.deleted|-][diff.deleted.highlight|    ][diff.deleted|third line starts with space]
   [diff.deleted|-][diff.deleted.highlight|+][diff.deleted| starts with a ][diff.deleted.highlight|plus][diff.deleted| sign]
+  [diff.deleted|-][diff.tab|	][diff.deleted|this one with ][diff.deleted.highlight|one][diff.deleted| tab]
+  [diff.deleted|-][diff.tab|		][diff.deleted|now with full ][diff.deleted.highlight|two][diff.deleted| tabs]
+  [diff.deleted|-][diff.tab|	][diff.deleted|now tabs][diff.tab|		][diff.deleted|everywhere, much fun]
   [diff.inserted|+that is the first paragraph]
   [diff.inserted|+][diff.inserted.highlight|    ][diff.inserted|this is the ][diff.inserted.highlight|second][diff.inserted| line]
   [diff.inserted|+third line starts with space]
   [diff.inserted|+][diff.inserted.highlight|-][diff.inserted| starts with a ][diff.inserted.highlight|minus][diff.inserted| sign]
+  [diff.inserted|+][diff.tab|	][diff.inserted|this one with ][diff.inserted.highlight|two][diff.inserted| tab]
+  [diff.inserted|+][diff.tab|			][diff.inserted|now with full ][diff.inserted.highlight|three][diff.inserted| tabs]
+  [diff.inserted|+][diff.tab|	][diff.inserted|now][diff.inserted.highlight| there are][diff.inserted| tabs][diff.tab|		][diff.inserted|everywhere, much fun]
    
    this line won't change
    


More information about the Mercurial-devel mailing list