Mercurial > hg
changeset 51010:c690d2cc7f36
changelog: make the `_delayopener` a real proxy
We use the same approach as the `_divertopener`. This make it possible to use
other methods of the vfs and not just the `__call__` API.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 25 Sep 2023 11:59:38 +0200 |
parents | ffb393dd5999 |
children | 9461a0b74596 |
files | mercurial/changelog.py |
diffstat | 1 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Mon Sep 25 11:23:38 2023 +0200 +++ b/mercurial/changelog.py Mon Sep 25 11:59:38 2023 +0200 @@ -175,16 +175,22 @@ return getattr(self._opener, attr) -def _delayopener(opener, target, buf): +class _delayopener: """build an opener that stores chunks in 'buf' instead of 'target'""" - def _delay(name, mode=b'r', checkambig=False, **kwargs): - if name != target: - return opener(name, mode, **kwargs) + def __init__(self, opener, target, buf): + self._opener = opener + self._target = target + self._buf = buf + + def __call__(self, name, mode=b'r', checkambig=False, **kwargs): + if name != self._target: + return self._opener(name, mode, **kwargs) assert not kwargs - return appender(opener, name, mode, buf) + return appender(self._opener, name, mode, self._buf) - return _delay + def __getattr__(self, attr): + return getattr(self._opener, attr) @attr.s