filelog: subclass the new `repository.ifilestorage` Protocol class
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 22 Oct 2024 23:36:48 -0400
changeset 52489 ba8f03ad8906
parent 52488 8c89e978375c
child 52490 ef119f914fc1
filelog: subclass the new `repository.ifilestorage` Protocol class This is the same transformation as 3a90a6fd710d did for dirstate, but the CamelCase naming was already cleaned up here. See 4ef6dbc27a99 for the benefits of explicit subclassing. One thing to mention is that pytype gets confused if Protocol classes preceed a regular class in the superclass list, so the interface goes last in the git extension. (I didn't bother to verify that it would have been an issue here, rather it was something I noticed when making `repository.ipeerbase` a Protocol class locally before dropping it entirely earlier in this series.) One other thing is that PyCharm starts flagging `__len__()` and `hasnode()` on `hgext.git.gitlog.baselog` with: "Type of 'hasnode' is incompatible with 'ifilestorage'" No clue why; it's happy with the other 3 implementations (at least with these methods- simplestorerepo.py looks badly broken otherwise).
hgext/git/gitlog.py
hgext/sqlitestore.py
mercurial/filelog.py
tests/simplestorerepo.py
--- a/hgext/git/gitlog.py	Wed Dec 11 00:33:49 2024 -0500
+++ b/hgext/git/gitlog.py	Tue Oct 22 23:36:48 2024 -0400
@@ -21,6 +21,9 @@
     manifest,
     pycompat,
 )
+from mercurial.interfaces import (
+    repository,
+)
 from mercurial.utils import stringutil
 from . import (
     gitutil,
@@ -471,8 +474,7 @@
         return gitmanifest.gittreemanifestctx(self.gitrepo, t)
 
 
-# @interfaceutil.implementer(repository.ifilestorage)
-class filelog(baselog):
+class filelog(baselog, repository.ifilestorage):
     def __init__(self, gr, db, path):
         super(filelog, self).__init__(gr, db)
         assert isinstance(path, bytes)
--- a/hgext/sqlitestore.py	Wed Dec 11 00:33:49 2024 -0500
+++ b/hgext/sqlitestore.py	Tue Oct 22 23:36:48 2024 -0400
@@ -312,8 +312,7 @@
     node = attr.ib(default=None, type=Optional[bytes])
 
 
-@interfaceutil.implementer(repository.ifilestorage)
-class sqlitefilestore:
+class sqlitefilestore(repository.ifilestorage):
     """Implements storage for an individual tracked path."""
 
     def __init__(self, db, path, compression):
--- a/mercurial/filelog.py	Wed Dec 11 00:33:49 2024 -0500
+++ b/mercurial/filelog.py	Tue Oct 22 23:36:48 2024 -0400
@@ -28,7 +28,7 @@
 )
 
 
-class filelog:  # (repository.ifilestorage)
+class filelog(repository.ifilestorage):
     _revlog: revlog.revlog
     nullid: bytes
     _fix_issue6528: bool
--- a/tests/simplestorerepo.py	Wed Dec 11 00:33:49 2024 -0500
+++ b/tests/simplestorerepo.py	Tue Oct 22 23:36:48 2024 -0400
@@ -40,7 +40,6 @@
 )
 from mercurial.interfaces import (
     repository,
-    util as interfaceutil,
 )
 from mercurial.utils import (
     cborutil,
@@ -96,8 +95,7 @@
     node = attr.ib(default=None, type=Optional[bytes])
 
 
-@interfaceutil.implementer(repository.ifilestorage)
-class filestorage:
+class filestorage(repository.ifilestorage):
     """Implements storage for a tracked path.
 
     Data is stored in the VFS in a directory corresponding to the tracked