changelog: change the implementation of `_divertopener`
During a transaction, new data to the changelog index are "diverted". The
previous implementat ways pretty basic, we need something better to be able to
use the changelog vfs fully during transaction. (eg: accessing the vfs options).
Differential Revision: https://phab.mercurial-scm.org/D8185
--- a/mercurial/changelog.py Thu Feb 27 17:08:59 2020 +0100
+++ b/mercurial/changelog.py Fri Feb 28 01:45:03 2020 +0100
@@ -164,15 +164,18 @@
return self.fp.__exit__(*args)
-def _divertopener(opener, target):
- """build an opener that writes in 'target.a' instead of 'target'"""
+class _divertopener(object):
+ def __init__(self, opener, target):
+ self._opener = opener
+ self._target = target
- def _divert(name, mode=b'r', checkambig=False, **kwargs):
- if name != target:
- return opener(name, mode, **kwargs)
- return opener(name + b".a", mode, **kwargs)
+ def __call__(self, name, mode=b'r', checkambig=False, **kwargs):
+ if name != self._target:
+ return self._opener(name, mode, **kwargs)
+ return self._opener(name + b".a", mode, **kwargs)
- return _divert
+ def __getattr__(self, attr):
+ return getattr(self._opener, attr)
def _delayopener(opener, target, buf):