summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2013-06-21 11:08:56 +0100
committerJosé Fonseca <[email protected]>2013-06-21 14:30:20 +0100
commitc14f516e589a16dead466dcfcd4bcb078e5b69dd (patch)
treee14a22e3225cead39ab7e0d9527d526feb552d99
parent9b7d21f8f5a175ac2db4b4d2d1fb14cdbb77adaa (diff)
tools/trace: Do a better job at comparing multi line strings.
For TGSI diffing. Reviewed-by: Brian Paul <[email protected]>
-rwxr-xr-xsrc/gallium/tools/trace/diff_state.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/gallium/tools/trace/diff_state.py b/src/gallium/tools/trace/diff_state.py
index 470aeda059b..00853bacbf7 100755
--- a/src/gallium/tools/trace/diff_state.py
+++ b/src/gallium/tools/trace/diff_state.py
@@ -28,6 +28,7 @@
import json
import optparse
import re
+import difflib
import sys
@@ -131,7 +132,7 @@ class Dumper(Visitor):
self._write(']')
def visitValue(self, node):
- self._write(json.dumps(node))
+ self._write(json.dumps(node, allow_nan=True))
@@ -246,6 +247,38 @@ class Differ(Visitor):
self.replace(a, b)
def replace(self, a, b):
+ if isinstance(a, basestring) and isinstance(b, basestring):
+ if '\n' in a or '\n' in b:
+ a = a.splitlines()
+ b = b.splitlines()
+ differ = difflib.Differ()
+ result = differ.compare(a, b)
+ self.dumper.level += 1
+ for entry in result:
+ self.dumper._newline()
+ self.dumper._indent()
+ tag = entry[:2]
+ text = entry[2:]
+ if tag == '? ':
+ tag = ' '
+ prefix = ' '
+ text = text.rstrip()
+ suffix = ''
+ else:
+ prefix = '"'
+ suffix = '\\n"'
+ line = tag + prefix + text + suffix
+ self.dumper._write(line)
+ self.dumper.level -= 1
+ return
+ self.dumper.visit(a)
+ self.dumper._write(' -> ')
+ self.dumper.visit(b)
+
+ def isMultilineString(self, value):
+ return isinstance(value, basestring) and '\n' in value
+
+ def replaceMultilineString(self, a, b):
self.dumper.visit(a)
self.dumper._write(' -> ')
self.dumper.visit(b)