changelog: implement context manager method for 'appender' object
authorBoris Feld <boris.feld@octobus.net>
Mon, 05 Feb 2018 20:36:51 +0100
changeset 36001 fa15a70f88de
parent 36000 0ff41ced4c12
child 36002 69aaad59dc02
changelog: implement context manager method for 'appender' object This object mimics a file and was missing the context manager API.
mercurial/changelog.py
--- a/mercurial/changelog.py	Sun Feb 04 00:29:22 2018 +0100
+++ b/mercurial/changelog.py	Mon Feb 05 20:36:51 2018 +0100
@@ -127,6 +127,13 @@
         self.offset += len(s)
         self._end += len(s)
 
+    def __enter__(self):
+        self.fp.__enter__()
+        return self
+
+    def __exit__(self, *args):
+        return self.fp.__exit__(*args)
+
 def _divertopener(opener, target):
     """build an opener that writes in 'target.a' instead of 'target'"""
     def _divert(name, mode='r', checkambig=False):