changeset 39855:62a532045e71

lfs: access revlog directly LFS is monkeypatching filelog.filelog and is then accessing various filelog attributes in the monkeypatched function. This is all fine. But some of the attributes being accessed by LFS are revlog centric and shouldn't be exposed on the file storage interface. This commit changes the monkeypatched functions to access proxied attributes on self._revlog instead of self. This should be safe to do because non-revlog repositories should not be using filelog instances: instead they should have a separate class to represent file storage. So it is reasonable for LFS to assume the _revlog attribute exists and points to a revlog. Differential Revision: https://phab.mercurial-scm.org/D4714
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 20 Sep 2018 17:47:34 -0700
parents 823a580448d7
children 96838b620b9c
files hgext/lfs/wrapper.py mercurial/filelog.py tests/test-lfs.t
diffstat 3 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/wrapper.py	Thu Sep 20 15:30:00 2018 -0700
+++ b/hgext/lfs/wrapper.py	Thu Sep 20 17:47:34 2018 -0700
@@ -115,19 +115,19 @@
         if node is None:
             # both None - likely working copy content where node is not ready
             return False
-        rev = rlog.rev(node)
+        rev = rlog._revlog.rev(node)
     else:
-        node = rlog.node(rev)
+        node = rlog._revlog.node(rev)
     if node == nullid:
         return False
-    flags = rlog.flags(rev)
+    flags = rlog._revlog.flags(rev)
     return bool(flags & revlog.REVIDX_EXTSTORED)
 
 def filelogaddrevision(orig, self, text, transaction, link, p1, p2,
                        cachedelta=None, node=None,
                        flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds):
     # The matcher isn't available if reposetup() wasn't called.
-    lfstrack = self.opener.options.get('lfstrack')
+    lfstrack = self._revlog.opener.options.get('lfstrack')
 
     if lfstrack:
         textlen = len(text)
@@ -144,7 +144,7 @@
 
 def filelogrenamed(orig, self, node):
     if _islfs(self, node):
-        rawtext = self.revision(node, raw=True)
+        rawtext = self._revlog.revision(node, raw=True)
         if not rawtext:
             return False
         metadata = pointer.deserialize(rawtext)
@@ -157,7 +157,7 @@
 def filelogsize(orig, self, rev):
     if _islfs(self, rev=rev):
         # fast path: use lfs metadata to answer size
-        rawtext = self.revision(rev, raw=True)
+        rawtext = self._revlog.revision(rev, raw=True)
         metadata = pointer.deserialize(rawtext)
         return int(metadata['size'])
     return orig(self, rev)
--- a/mercurial/filelog.py	Thu Sep 20 15:30:00 2018 -0700
+++ b/mercurial/filelog.py	Thu Sep 20 17:47:34 2018 -0700
@@ -57,7 +57,7 @@
     def linkrev(self, rev):
         return self._revlog.linkrev(rev)
 
-    # Used by LFS, verify.
+    # Used by verify.
     def flags(self, rev):
         return self._revlog.flags(rev)
 
@@ -207,7 +207,7 @@
     def indexfile(self, value):
         self._revlog.indexfile = value
 
-    # Used by LFS, repo upgrade.
+    # Used by repo upgrade.
     @property
     def opener(self):
         return self._revlog.opener
--- a/tests/test-lfs.t	Thu Sep 20 15:30:00 2018 -0700
+++ b/tests/test-lfs.t	Thu Sep 20 17:47:34 2018 -0700
@@ -692,7 +692,7 @@
   >             continue
   >         sizes = [fl.rawsize(i) for i in fl]
   >         texts = [fl.revision(i, raw=True) for i in fl]
-  >         flags = [int(fl.flags(i)) for i in fl]
+  >         flags = [int(fl._revlog.flags(i)) for i in fl]
   >         hashes = [hash(t) for t in texts]
   >         print('  %s: rawsizes=%r flags=%r hashes=%r'
   >               % (name, sizes, flags, hashes))