# HG changeset patch # User Pierre-Yves David # Date 1582850703 -3600 # Node ID 897f0ce4b484a28d5e3f91bcdf2294c6b16aaaff # Parent 1376cb1c8e34aa3ce0422892bc342365de29f52d 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 diff -r 1376cb1c8e34 -r 897f0ce4b484 mercurial/changelog.py --- 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):