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

login
register
mail settings
Submitter phabricator
Date March 11, 2020, 1:35 a.m.
Message ID <3e39a55b97579303b5ccda68a45a46d9@localhost.localdomain>
Download mbox | patch
Permalink /patch/45684/
State Not Applicable
Headers show

Comments

phabricator - March 11, 2020, 1:35 a.m.
marmoute added a comment.
marmoute updated this revision to Diff 20682.


  rebase above latest default up to landed-D8182

REPOSITORY
  rHG Mercurial

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

BRANCH
  default

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