[diffoscope] 09/12: Skip computation of differences excluded via --hide option, rather then just masking them.

Maria Glukhova siamezzze-guest at moszumanska.debian.org
Wed Mar 8 15:59:09 CET 2017


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

siamezzze-guest pushed a commit to branch siamezzze/hide-profiles-experiment
in repository diffoscope.

commit 207ca751505dffa1be43746ed2f3c7a75b55ab17
Author: Maria Glukhova <siamezzze at gmail.com>
Date:   Sat Feb 25 11:35:47 2017 +0200

    Skip computation of differences excluded via --hide option, rather then just masking them.
---
 diffoscope/comparators/gzip.py            |  4 +++
 diffoscope/config.py                      |  2 +-
 diffoscope/main.py                        |  7 ++---
 diffoscope/presenters/html/html.py        |  4 ---
 diffoscope/presenters/json.py             |  3 ---
 diffoscope/presenters/markdown.py         |  3 ---
 diffoscope/presenters/restructuredtext.py |  3 ---
 diffoscope/presenters/text.py             |  3 ---
 tests/test_hide_profile.py                | 45 +++++++++++++++++++++++++++++++
 9 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index f81bac5..2d4f4f8 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -25,6 +25,7 @@ import collections
 
 from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
+from diffoscope.config import Config
 
 
 from .utils.file import File
@@ -63,4 +64,7 @@ class GzipFile(File):
     RE_FILE_TYPE = re.compile(r'^gzip compressed data\b')
 
     def compare_details(self, other, source=None):
+        if Config().hide_timestamp and Config().hide_timestamp == "gzip-metadata":
+            logger.debug("Skipping gzip-metadata")
+            return []
         return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
diff --git a/diffoscope/config.py b/diffoscope/config.py
index 0be2e39..67039c3 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -34,7 +34,7 @@ class Config(object):
     fuzzy_threshold = 60
     enforce_constraints = True
     excludes = ()
-    hide_profile = None
+    hide_timestamp = None
 
     _singleton = {}
 
diff --git a/diffoscope/main.py b/diffoscope/main.py
index b8aec68..7ef6d26 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -154,8 +154,6 @@ def create_parser():
                         'trying to emit it in a report. This also affects --text '
                         'output. (0 to disable, default: 0)',
                         default=0).completer=RangeCompleter(0, 0, 200)
-    group2.add_argument('--hide', dest='hide_profile', action='store',
-                        choices=['metadata'], help='hide certain differences')
 
     group3 = parser.add_argument_group('diff calculation')
     group3.add_argument('--new-file', dest='new_file', action='store_true',
@@ -163,6 +161,9 @@ def create_parser():
     group3.add_argument('--exclude', dest='excludes', nargs='?',
                         metavar='PATTERN', action='append', default=[],
                         help='Exclude files that match %(metavar)s')
+    group3.add_argument('--hide-timestamp', dest='hide_timestamp',
+                        action='store', choices=['gzip-metadata'],
+                        help='hide certain timestamp differences')
     group3.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int,
                         help='Threshold for fuzzy-matching '
                         '(0 to disable, %(default)s is default, 400 is high fuzziness)',
@@ -254,7 +255,7 @@ def run_diffoscope(parsed_args):
     Config().fuzzy_threshold = parsed_args.fuzzy_threshold
     Config().new_file = parsed_args.new_file
     Config().excludes = parsed_args.excludes
-    Config().hide_profile = parsed_args.hide_profile
+    Config().hide_timestamp = parsed_args.hide_timestamp
     set_locale()
     logger.debug('Starting comparison')
     ProgressManager().setup(parsed_args)
diff --git a/diffoscope/presenters/html/html.py b/diffoscope/presenters/html/html.py
index f54daa6..bf8e049 100644
--- a/diffoscope/presenters/html/html.py
+++ b/diffoscope/presenters/html/html.py
@@ -439,10 +439,6 @@ def escape_anchor(val):
     return val
 
 def output_difference(difference, print_func, css_url, directory, parents):
-    if Config().hide_profile is not None:
-        if difference.source1 == Config().hide_profile:
-            logger.debug('output for %s is hidden', difference.source1)
-            return
     logger.debug('html output for %s', difference.source1)
     sources = parents + [difference.source1]
     print_func(u'<div class="difference">')
diff --git a/diffoscope/presenters/json.py b/diffoscope/presenters/json.py
index 1df4e30..f6ba3a5 100644
--- a/diffoscope/presenters/json.py
+++ b/diffoscope/presenters/json.py
@@ -38,9 +38,6 @@ class JSONPresenter(Presenter):
         self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
 
     def visit_difference(self, difference):
-        if Config().hide_profile is not None and \
-                        difference.source1 == Config().hide_profile:
-            return
         self.current.append({
             'source1': difference.source1,
             'source2': difference.source2,
diff --git a/diffoscope/presenters/markdown.py b/diffoscope/presenters/markdown.py
index 6c6ad2c..40f4363 100644
--- a/diffoscope/presenters/markdown.py
+++ b/diffoscope/presenters/markdown.py
@@ -28,9 +28,6 @@ class MarkdownTextPresenter(Presenter):
         super().__init__()
 
     def visit_difference(self, difference):
-        if Config().hide_profile is not None and \
-                        difference.source1 == Config().hide_profile:
-            return
         if difference.source1 == difference.source2:
             self.title(difference.source1)
         else:
diff --git a/diffoscope/presenters/restructuredtext.py b/diffoscope/presenters/restructuredtext.py
index e83cec7..fc2c8e3 100644
--- a/diffoscope/presenters/restructuredtext.py
+++ b/diffoscope/presenters/restructuredtext.py
@@ -30,9 +30,6 @@ class RestructuredTextPresenter(Presenter):
         super().__init__()
 
     def visit_difference(self, difference):
-        if Config().hide_profile is not None and \
-                        difference.source1 == Config().hide_profile:
-            return
         if difference.source1 == difference.source2:
             self.title(difference.source1)
         else:
diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index 6ec878d..0e2558b 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -45,9 +45,6 @@ class TextPresenter(Presenter):
             self.print_func("Max output size reached.", force=True)
 
     def visit_difference(self, difference):
-        if Config().hide_profile is not None and \
-                        difference.source1 == Config().hide_profile:
-            return
         if self.depth == 0:
             self.output("--- {}".format(difference.source1))
             self.output("+++ {}".format(difference.source2))
diff --git a/tests/test_hide_profile.py b/tests/test_hide_profile.py
new file mode 100644
index 0000000..e3ee2ef
--- /dev/null
+++ b/tests/test_hide_profile.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 Maria Glukhova <siamezzze at gmail.com>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import os
+import pytest
+
+from diffoscope.main import main
+
+
+def run(capsys, filenames, *args):
+    with pytest.raises(SystemExit) as exc:
+        main(args + tuple(
+            os.path.join(os.path.dirname(__file__), 'data', x)
+            for x in filenames
+        ))
+
+    out, err = capsys.readouterr()
+
+    assert err == ''
+
+    return exc.value.code, out
+
+def test_hide_gzip_metadata(capsys):
+    ret, out = run(capsys, ('test1.gz', 'test2.gz'),
+                   '--hide-timestamp=gzip-metadata')
+
+    assert ret == 1
+    assert '── metadata' not in out
+    assert '│   --- test1\n├── +++ test2' in out

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


More information about the diffoscope mailing list