Patchwork [01,of,13] changelog: implement context manager method for 'appender' object

login
register
mail settings
Submitter Boris Feld
Date Feb. 6, 2018, 1:21 p.m.
Message ID <cc2e588940df0435bf0e.1517923282@FB>
Download mbox | patch
Permalink /patch/27353/
State New
Headers show

Comments

Boris Feld - Feb. 6, 2018, 1:21 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1517859411 -3600
#      Mon Feb 05 20:36:51 2018 +0100
# Node ID cc2e588940df0435bf0e3013ebd45013a22fa8fe
# Parent  1a31111e6239a2eb841a5dce5e1cf8212c54bf33
# EXP-Topic revlog-fp
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r cc2e588940df
changelog: implement context manager method for 'appender' object

This object mimics a file and was missing the context manager API.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -127,6 +127,13 @@  class appender(object):
         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):