changeset 43027:3518da504303

vfs: give all vfs an options attribute by default Multiple code path assume vfs have an options attribute, including the vfs module itself. So for consistency we explicitly add one to all vfs. This will prevent various crash in the next changesets. Differential Revision: https://phab.mercurial-scm.org/D6935
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 27 Sep 2019 05:17:30 +0200
parents 188476e48f51
children 0b87eb2fba67
files contrib/dumprevlog mercurial/revlog.py mercurial/statichttprepo.py mercurial/vfs.py tests/test-parseindex.t
diffstat 5 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/dumprevlog	Fri Sep 27 06:24:42 2019 +0200
+++ b/contrib/dumprevlog	Fri Sep 27 05:17:30 2019 +0200
@@ -22,6 +22,7 @@
     if b'b' not in mode:
         mode = mode + b'b'
     return open(path, pycompat.sysstr(mode))
+binopen.options = {}
 
 def printb(data, end=b'\n'):
     sys.stdout.flush()
--- a/mercurial/revlog.py	Fri Sep 27 06:24:42 2019 +0200
+++ b/mercurial/revlog.py	Fri Sep 27 05:17:30 2019 +0200
@@ -355,7 +355,7 @@
 
     def _loadindex(self):
         mmapindexthreshold = None
-        opts = getattr(self.opener, 'options', {}) or {}
+        opts = self.opener.options
 
         if 'revlogv2' in opts:
             newversionflags = REVLOGV2 | FLAG_INLINE_DATA
@@ -363,7 +363,7 @@
             newversionflags = REVLOGV1 | FLAG_INLINE_DATA
             if 'generaldelta' in opts:
                 newversionflags |= FLAG_GENERALDELTA
-        elif 'revlogv0' in getattr(self.opener, 'options', {}):
+        elif 'revlogv0' in self.opener.options:
             newversionflags = REVLOGV0
         else:
             newversionflags = REVLOG_DEFAULT_VERSION
--- a/mercurial/statichttprepo.py	Fri Sep 27 06:24:42 2019 +0200
+++ b/mercurial/statichttprepo.py	Fri Sep 27 05:17:30 2019 +0200
@@ -115,6 +115,7 @@
     class statichttpvfs(vfsmod.abstractvfs):
         def __init__(self, base):
             self.base = base
+            self.options = {}
 
         def __call__(self, path, mode='r', *args, **kw):
             if mode not in ('r', 'rb'):
--- a/mercurial/vfs.py	Fri Sep 27 06:24:42 2019 +0200
+++ b/mercurial/vfs.py	Fri Sep 27 05:17:30 2019 +0200
@@ -327,6 +327,7 @@
             self.audit = (lambda path, mode=None: True)
         self.createmode = None
         self._trustnlink = None
+        self.options = {}
 
     @util.propertycache
     def _cansymlink(self):
--- a/tests/test-parseindex.t	Fri Sep 27 06:24:42 2019 +0200
+++ b/tests/test-parseindex.t	Fri Sep 27 05:17:30 2019 +0200
@@ -53,6 +53,7 @@
   >     def wrapper(*a, **kwargs):
   >         f = o(*a, **kwargs)
   >         return singlebyteread(f)
+  >     wrapper.options = o.options
   >     return wrapper
   > 
   > cl = changelog.changelog(opener(b'.hg/store'))