Mercurial > hg
comparison mercurial/changelog.py @ 44496:897f0ce4b484
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
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 28 Feb 2020 01:45:03 +0100 |
parents | 5962fd0d1045 |
children | e147748f750b |
comparison
equal
deleted
inserted
replaced
44495:1376cb1c8e34 | 44496:897f0ce4b484 |
---|---|
162 | 162 |
163 def __exit__(self, *args): | 163 def __exit__(self, *args): |
164 return self.fp.__exit__(*args) | 164 return self.fp.__exit__(*args) |
165 | 165 |
166 | 166 |
167 def _divertopener(opener, target): | 167 class _divertopener(object): |
168 """build an opener that writes in 'target.a' instead of 'target'""" | 168 def __init__(self, opener, target): |
169 | 169 self._opener = opener |
170 def _divert(name, mode=b'r', checkambig=False, **kwargs): | 170 self._target = target |
171 if name != target: | 171 |
172 return opener(name, mode, **kwargs) | 172 def __call__(self, name, mode=b'r', checkambig=False, **kwargs): |
173 return opener(name + b".a", mode, **kwargs) | 173 if name != self._target: |
174 | 174 return self._opener(name, mode, **kwargs) |
175 return _divert | 175 return self._opener(name + b".a", mode, **kwargs) |
176 | |
177 def __getattr__(self, attr): | |
178 return getattr(self._opener, attr) | |
176 | 179 |
177 | 180 |
178 def _delayopener(opener, target, buf): | 181 def _delayopener(opener, target, buf): |
179 """build an opener that stores chunks in 'buf' instead of 'target'""" | 182 """build an opener that stores chunks in 'buf' instead of 'target'""" |
180 | 183 |