Patchwork D8185: changelog: change the implementation of `_divertopenener`

login
register
mail settings
Submitter phabricator
Date Feb. 28, 2020, 6:54 p.m.
Message ID <differential-rev-PHID-DREV-2ot34kuwyvycjyzwavoh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45393/
State Superseded
Headers show

Comments

phabricator - Feb. 28, 2020, 6:54 p.m.
marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8185

AFFECTED FILES
  mercurial/changelog.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -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):