[diffoscope] 01/02: Add a size_traverse method to Difference to only calculate the first few layers

Ximin Luo infinity0 at debian.org
Wed Jun 14 15:45:40 CEST 2017


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

infinity0 pushed a commit to branch WIP/humungous-diffs
in repository diffoscope.

commit 25a01716e8cee1bfd0bf33ebc3db78cac3f4a12e
Author: Ximin Luo <infinity0 at debian.org>
Date:   Wed Jun 14 15:14:11 2017 +0200

    Add a size_traverse method to Difference to only calculate the first few layers
---
 diffoscope/difference.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index ca45041..81d2ccd 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -113,13 +113,18 @@ class Difference(object):
 
     def size(self):
         if self._size_cache is None:
-            self._size_cache = (len(self.unified_diff) +
+            self._size_cache = self.size_traverse()
+        return self._size_cache
+
+    def size_traverse(self, depth=-1):
+        children = (0 if depth == 0 else
+                    sum(d.size_traverse(depth-1) for d in self._details))
+        return (len(self.unified_diff) +
                 len(self.source1) +
                 len(self.source2) +
                 sum(map(len, self.comments)) +
-                sum(d.size() for d in self._details) +
+                children +
                 sum(v.size() for v in self._visuals))
-        return self._size_cache
 
     def has_children(self):
         """Whether there are children.

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


More information about the diffoscope mailing list