[Git][reproducible-builds/diffoscope][master] 2 commits: Show "ordering differences only" in strings(1) output. (Closes: reproducible-builds/diffoscope#216)

Chris Lamb gitlab at salsa.debian.org
Fri Sep 4 10:25:57 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
2d3308be by Chris Lamb at 2020-09-04T11:11:19+01:00
Show "ordering differences only" in strings(1) output. (Closes: reproducible-builds/diffoscope#216)

- - - - -
e4382dc8 by Chris Lamb at 2020-09-04T11:12:54+01:00
releasing package diffoscope version 159

- - - - -


5 changed files:

- debian/changelog
- diffoscope/__init__.py
- diffoscope/comparators/elf.py
- diffoscope/comparators/text.py
- diffoscope/difference.py


Changes:

=====================================
debian/changelog
=====================================
@@ -1,8 +1,16 @@
-diffoscope (159) UNRELEASED; urgency=medium
+diffoscope (159) unstable; urgency=medium
 
-  * WIP (generated upon release).
+  [ Chris Lamb ]
+  * Show "ordering differences only" in strings(1) output.
+    (Closes: reproducible-builds/diffoscope#216)
+  * Don't alias output from "os.path.splitext" to variables that we do not end
+    up using.
+  * Don't raise exceptions when cleaning up after a guestfs cleanup failure.
+
+  [ Jean-Romain Garnier ]
+  * Make "Command" subclass a new generic Operation class.
 
- -- Chris Lamb <lamby at debian.org>  Fri, 28 Aug 2020 12:05:23 +0100
+ -- Chris Lamb <lamby at debian.org>  Fri, 04 Sep 2020 11:12:52 +0100
 
 diffoscope (158) unstable; urgency=medium
 


=====================================
diffoscope/__init__.py
=====================================
@@ -18,4 +18,4 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-VERSION = "158"
+VERSION = "159"


=====================================
diffoscope/comparators/elf.py
=====================================
@@ -638,8 +638,9 @@ class ElfFile(File):
             for x in list(READELF_COMMANDS) + READELF_DEBUG_DUMP_COMMANDS
         ]
 
-        differences.append(
-            Difference.from_operation(Strings, self.path, other.path)
-        )
+        difference = Difference.from_operation(Strings, self.path, other.path)
+        if difference:
+            difference.check_for_ordering_differences()
+        differences.append(difference)
 
         return differences


=====================================
diffoscope/comparators/text.py
=====================================
@@ -26,19 +26,6 @@ from diffoscope.difference import Difference
 from .utils.file import File
 
 
-def order_only_difference(unified_diff):
-    diff_lines = unified_diff.splitlines()
-    added_lines = [line[1:] for line in diff_lines if line.startswith("+")]
-    removed_lines = [line[1:] for line in diff_lines if line.startswith("-")]
-    # Faster check: does number of lines match?
-    if len(added_lines) != len(removed_lines):
-        return False
-    return (
-        sorted(added_lines) == sorted(removed_lines)
-        and added_lines != removed_lines
-    )
-
-
 class TextFile(File):
     DESCRIPTION = "text files"
     FILE_TYPE_RE = re.compile(r"\btext\b")
@@ -61,11 +48,6 @@ class TextFile(File):
                 difference = Difference.from_text_readers(
                     my_content, other_content, self.name, other.name, source
                 )
-                # Check if difference is only in line order.
-                if difference and order_only_difference(
-                    difference.unified_diff
-                ):
-                    difference.add_comment("Ordering differences only")
                 if my_encoding != other_encoding:
                     if difference is None:
                         difference = Difference(
@@ -82,6 +64,10 @@ class TextFile(File):
                             )
                         ]
                     )
+
+                if difference:
+                    difference.check_for_ordering_differences()
+
                 return difference
         except (LookupError, UnicodeDecodeError):
             # unknown or misdetected encoding


=====================================
diffoscope/difference.py
=====================================
@@ -370,6 +370,34 @@ class Difference:
         self._visuals.extend(visuals)
         self._size_cache = None
 
+    def has_ordering_differences_only(self):
+        """
+        Check if difference is only in line ordering.
+        """
+
+        if not self.unified_diff:
+            return False
+
+        diff_lines = self.unified_diff.splitlines()
+
+        added_lines = [line[1:] for line in diff_lines if line.startswith("+")]
+        removed_lines = [
+            line[1:] for line in diff_lines if line.startswith("-")
+        ]
+
+        # Faster check: does number of lines match?
+        if len(added_lines) != len(removed_lines):
+            return False
+
+        if added_lines == removed_lines:
+            return False
+
+        return sorted(added_lines) == sorted(removed_lines)
+
+    def check_for_ordering_differences(self):
+        if self.has_ordering_differences_only():
+            self.add_comment("Ordering differences only")
+
 
 class VisualDifference:
     def __init__(self, data_type, content, source):



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/aca4221909b0b1244c5239b0f3087bdd176993a3...e4382dc88a8a26b0c8690cdf952c11153af57f30

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/aca4221909b0b1244c5239b0f3087bdd176993a3...e4382dc88a8a26b0c8690cdf952c11153af57f30
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200904/53f066d5/attachment.htm>


More information about the rb-commits mailing list