[diffoscope] 01/01: Begin preparation for diff-loading logic

Ximin Luo infinity0 at debian.org
Mon May 29 20:10:47 CEST 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch experimental
in repository diffoscope.

commit 0853e0826e6bc35e13093e6f1c4163fda1211dc7
Author: Ximin Luo <infinity0 at debian.org>
Date:   Mon May 29 20:10:36 2017 +0200

    Begin preparation for diff-loading logic
---
 diffoscope/presenters/json.py | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/diffoscope/presenters/json.py b/diffoscope/presenters/json.py
index bf4d39e..bdedb5e 100644
--- a/diffoscope/presenters/json.py
+++ b/diffoscope/presenters/json.py
@@ -18,14 +18,18 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import json
+from collections import OrderedDict
 
 from .utils import Presenter
 
+JSON_FORMAT_VERSION = 1
+JSON_FORMAT_MAGIC = "diffoscope-json-version"
+
 
 class JSONPresenter(Presenter):
     def __init__(self, print_func):
-        self.root = []
-        self.current = self.root
+        self.stack = []
+        self.current = self.stack
         self.print_func = print_func
 
         super().__init__()
@@ -33,15 +37,18 @@ class JSONPresenter(Presenter):
     def start(self, difference):
         super().start(difference)
 
-        self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
+        self.stack[0][JSON_FORMAT_MAGIC] = DIFFOSCOPE_JSON_FORMAT_VERSION
+        self.stack[0].move_to_end(JSON_FORMAT_MAGIC, last=False)
+        self.print_func(json.dumps(self.stack[0], indent=2))
 
     def visit_difference(self, difference):
-        self.current.append({
-            'source1': difference.source1,
-            'source2': difference.source2,
-            'comments': [x for x in difference.comments],
-            'differences': [],
-            'unified_diff': difference.unified_diff,
-        })
-
-        self.current = self.current[-1]['differences']
+        child_differences = []
+        self.current.append(OrderedDict([
+            ('source1', difference.source1),
+            ('source2', difference.source2),
+            ('comments', [x for x in difference.comments]),
+            ('differences', child_differences),
+            ('unified_diff', difference.unified_diff),
+        ]))
+
+        self.current = child_differences

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list