[Git][reproducible-builds/diffoscope][master] Add open-coded version of deprecated os.path.commonprefix

Chris Lamb (@lamby) gitlab at salsa.debian.org
Mon Jun 22 20:31:32 UTC 2026



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
2af9e134 by Zbigniew Jędrzejewski-Szmek at 2026-06-21T16:49:52+02:00
Add open-coded version of deprecated os.path.commonprefix

https://github.com/python/cpython/pull/144436 deprecated it.
Add a slightly simplified version as a local function to avoid
the deprecation warning.

- - - - -


1 changed file:

- diffoscope/diff.py


Changes:

=====================================
diffoscope/diff.py
=====================================
@@ -414,13 +414,23 @@ def diffinput_truncate(s, sz):
     return s
 
 
+def _commonprefix(s, t):
+    # calculate the common prefix of two strings
+    s1 = min(s, t)
+    s2 = max(s, t)
+    for i, c in enumerate(s1):
+        if c != s2[i]:
+            return s1[:i]
+    return s1
+
+
 def linediff(s, t, diffon, diffoff):
     # calculate common prefix/suffix, easy optimisation for Wagner-Fischer
-    prefix = os.path.commonprefix((s, t))
+    prefix = _commonprefix(s, t)
     if prefix:
         s = s[len(prefix) :]
         t = t[len(prefix) :]
-    suffix = os.path.commonprefix((s[::-1], t[::-1]))[::-1]
+    suffix = _commonprefix(s[::-1], t[::-1])[::-1]
     if suffix:
         s = s[: -len(suffix)]
         t = t[: -len(suffix)]



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/2af9e134cbeaa36de0c92d540e8e865ffb5450ad

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/2af9e134cbeaa36de0c92d540e8e865ffb5450ad
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


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


More information about the rb-commits mailing list