filelog: declare that filelog implements a storage interface
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 05 Apr 2018 15:18:23 -0700
changeset 37441 a3202fa83aff
parent 37440 4335a75f0bd0
child 37442 0596d27457c6
filelog: declare that filelog implements a storage interface Now that we have a declared interface, let's declare that filelog implements it. Tests have been added that confirm the object conforms to the interface. The existing interface checks verify there are no extra public attributes outside the declared interface. filelog has several extra attributes. So we added a mechanism to suppress this check. The goal is to modify the filelog class so we can drop this check. Differential Revision: https://phab.mercurial-scm.org/D3149
mercurial/filelog.py
tests/simplestorerepo.py
tests/test-check-interfaces.py
--- a/mercurial/filelog.py	Thu Apr 05 15:09:41 2018 -0700
+++ b/mercurial/filelog.py	Thu Apr 05 15:18:23 2018 -0700
@@ -10,9 +10,13 @@
 import re
 import struct
 
+from .thirdparty.zope import (
+    interface as zi,
+)
 from . import (
     error,
     mdiff,
+    repository,
     revlog,
 )
 
@@ -39,6 +43,7 @@
     m, offs = parsemeta(text)
     return m and "censored" in m
 
+@zi.implementer(repository.ifilestorage)
 class filelog(revlog.revlog):
     def __init__(self, opener, path):
         super(filelog, self).__init__(opener,
--- a/tests/simplestorerepo.py	Thu Apr 05 15:09:41 2018 -0700
+++ b/tests/simplestorerepo.py	Thu Apr 05 15:18:23 2018 -0700
@@ -24,6 +24,9 @@
 from mercurial.thirdparty import (
     cbor,
 )
+from mercurial.thirdparty.zope import (
+    interface as zi,
+)
 from mercurial import (
     ancestor,
     bundlerepo,
@@ -33,6 +36,7 @@
     localrepo,
     mdiff,
     pycompat,
+    repository,
     revlog,
     store,
     verify,
@@ -57,6 +61,7 @@
     if not isinstance(rev, int):
         raise ValueError('expected int')
 
+@zi.implementer(repository.ifilestorage)
 class filestorage(object):
     """Implements storage for a tracked path.
 
--- a/tests/test-check-interfaces.py	Thu Apr 05 15:09:41 2018 -0700
+++ b/tests/test-check-interfaces.py	Thu Apr 05 15:18:23 2018 -0700
@@ -12,6 +12,7 @@
 )
 from mercurial import (
     bundlerepo,
+    filelog,
     httppeer,
     localrepo,
     repository,
@@ -19,13 +20,14 @@
     statichttprepo,
     ui as uimod,
     unionrepo,
+    vfs as vfsmod,
     wireprotoserver,
     wireprototypes,
 )
 
 rootdir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
 
-def checkzobject(o):
+def checkzobject(o, allowextra=False):
     """Verify an object with a zope interface."""
     ifaces = zi.providedBy(o)
     if not ifaces:
@@ -37,6 +39,9 @@
     for iface in ifaces:
         ziverify.verifyObject(iface, o)
 
+    if allowextra:
+        return
+
     # Now verify that the object provides no extra public attributes that
     # aren't declared as part of interfaces.
     allowed = set()
@@ -132,4 +137,10 @@
     httpv2 = wireprotoserver.httpv2protocolhandler(None, None)
     checkzobject(httpv2)
 
+    ziverify.verifyClass(repository.ifilestorage, filelog.filelog)
+
+    vfs = vfsmod.vfs('.')
+    fl = filelog.filelog(vfs, 'dummy.i')
+    checkzobject(fl, allowextra=True)
+
 main()