[Git][reproducible-builds/diffoscope][master] 2 commits: Remove unnecessary return value from Difference.check_for_ordering_differences.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Fri Jan 17 14:37:11 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
f9aced5c by Chris Lamb at 2025-01-17T14:28:30+00:00
Remove unnecessary return value from Difference.check_for_ordering_differences.

- - - - -
72df2175 by Chris Lamb at 2025-01-17T14:36:59+00:00
Correct check for differences in line endings.

- - - - -


1 changed file:

- diffoscope/difference.py


Changes:

=====================================
diffoscope/difference.py
=====================================
@@ -409,9 +409,10 @@ class Difference:
         """
 
         if not self.unified_diff:
-            return False
+            return
 
-        diff_lines = self.unified_diff.splitlines()
+        # Split the diff, but retain the original line endings
+        diff_lines = self.unified_diff.splitlines(True)
 
         added_lines = [line[1:] for line in diff_lines if line.startswith("+")]
         removed_lines = [
@@ -422,10 +423,22 @@ class Difference:
         if len(added_lines) != len(removed_lines):
             return
 
-        if added_lines == removed_lines:
-            self.add_comment("Line-ending differences only")
-        elif sorted(added_lines) == sorted(removed_lines):
+        if added_lines == removed_lines or sorted(added_lines) == sorted(
+            removed_lines
+        ):
             self.add_comment("Ordering differences only")
+            return
+
+        # Now strip off any trailing newlines, thus effectively normalising
+        # "\r\n" and "\n"...
+        added_lines = [x.rstrip("\r\n") for x in added_lines]
+        removed_lines = [x.rstrip("\r\n") for x in removed_lines]
+
+        # ... and re-run the same checks.
+        if added_lines == removed_lines or sorted(added_lines) == sorted(
+            removed_lines
+        ):
+            self.add_comment("Line-ending differences only")
 
 
 class VisualDifference:



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/2236701a8c5e27513bfeec14e70ac1df5a78b86c...72df21753e3190c4d5c57cbf83025201eba4894c

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/2236701a8c5e27513bfeec14e70ac1df5a78b86c...72df21753e3190c4d5c57cbf83025201eba4894c
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/20250117/5d3e7596/attachment.htm>


More information about the rb-commits mailing list