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

login
register
mail settings
Submitter phabricator
Date March 10, 2020, 8:48 p.m.
Message ID <0f35af8c5d6e44c65b6b97c5255a9ee6@localhost.localdomain>
Download mbox | patch
Permalink /patch/45678/
State Not Applicable
Headers show

Comments

phabricator - March 10, 2020, 8:48 p.m.
Closed by commit rHG897f0ce4b484: changelog: change the implementation of `_divertopener` (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8185?vs=20388&id=20675

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8185/new/

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):