[PATCH] repotreeitem: replace commonprefix() with commonpath(), due to a DeprecationWarning

6 views
Skip to first unread message

Antonio Muci

unread,
Apr 7, 2026, 11:41:32 AM (4 days ago) Apr 7
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1775574055 -7200
# Tue Apr 07 17:00:55 2026 +0200
# Branch stable
# Node ID 859b2f861a78ebda5687ac5f445feb59af7e72a2
# Parent c92cd00dbfe34302c6ea6824a2636b28c92adcbc
repotreeitem: replace commonprefix() with commonpath(), due to a DeprecationWarning

Found while running Tortoisehg under Python 3.15.0a7 in strict mode:

```
$ python3.15 -Wall -Werror thg
Traceback (most recent call last):
...
File "<BASE>/tortoisehg/hgqt/repotreemodel.py", line 412, in updateCommonPaths
grp.updateCommonPath()
~~~~~~~~~~~~~~~~~~~~^^
File "<BASE>/tortoisehg/hgqt/repotreeitem.py", line 699, in updateCommonPath
self._commonpath = os.path.dirname(os.path.commonprefix(childs))
~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "<frozen genericpath>", line 109, in commonprefix
DeprecationWarning: os.path.commonprefix() is deprecated. Use os.path.commonpath() for longest path prefix.
```

The context is the following: os.path.commonprefix() has been known to be buggy
since python 3.5 and has been deprecated since python 3.10. Link to the current
documentation:
https://docs.python.org/3.15/library/os.path.html#os.path.commonprefix

diff --git a/tortoisehg/hgqt/repotreeitem.py b/tortoisehg/hgqt/repotreeitem.py
--- a/tortoisehg/hgqt/repotreeitem.py
+++ b/tortoisehg/hgqt/repotreeitem.py
@@ -696,7 +696,7 @@ class RepoGroupItem(RepoTreeItem):
childs = [os.path.normcase(child.rootpath())
for child in self.childs
if not isinstance(child, RepoGroupItem)]
- self._commonpath = os.path.dirname(os.path.commonprefix(childs))
+ self._commonpath = os.path.dirname(os.path.commonpath(childs))

def getCommonPath(self) -> str:
return self._commonpath

Yuya Nishihara

unread,
Apr 8, 2026, 9:21:32 AM (3 days ago) Apr 8
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
Maybe we can/have to remove os.path.dirname()? commonprefix() would end with
"/<garbage>", but commonpath() wouldn't.

a....@inwind.it

unread,
Apr 8, 2026, 2:14:51 PM (3 days ago) Apr 8
to Yuya Nishihara, Antonio Muci' via TortoiseHg Developers
Please ignore this patch, it's not good enough.

Just getting rid of dirname() would not work (see below).

I think more testing is needed, otherwise we'd introduce a bug.



>>> paths=("/home/muxator/mercurial/thg", "/home/muxator/mercurial/tgarbage")
>>> commonprefix(paths)
'/home/muxator/mercurial/t'
>>> commonpath(paths)
'/home/muxator/mercurial'
>>> dirname(commonprefix(paths))
'/home/muxator/mercurial'
>>> dirname(commonpath(paths))
'/home/muxator' <-- different result

Yuya Nishihara

unread,
Apr 8, 2026, 9:13:46 PM (3 days ago) Apr 8
to a....@inwind.it, Antonio Muci' via TortoiseHg Developers
On Wed, 8 Apr 2026 20:14:48 +0200 (CEST), a....@inwind.it wrote:
> Please ignore this patch, it's not good enough.
>
> Just getting rid of dirname() would not work (see below).
>
> I think more testing is needed, otherwise we'd introduce a bug.
>
>
>
> >>> paths=("/home/muxator/mercurial/thg", "/home/muxator/mercurial/tgarbage")
> >>> commonprefix(paths)
> '/home/muxator/mercurial/t'
> >>> commonpath(paths)
> '/home/muxator/mercurial'
> >>> dirname(commonprefix(paths))
> '/home/muxator/mercurial'
> >>> dirname(commonpath(paths))
> '/home/muxator' <-- different result

Maybe I don't follow? dirname(commonprefix()) is identical to commonpath() in
the example above. dirname(commonprefix([unique_path])) is different, but I
suspect it would be an existing bug.
Reply all
Reply to author
Forward
0 new messages