mercurial/util.py
changeset 29394 6d96658a22b0
parent 29393 50269a4dce61
child 29431 80880ad3fccd
--- a/mercurial/util.py	Thu Jun 23 18:20:58 2016 +0100
+++ b/mercurial/util.py	Thu Jun 23 18:21:25 2016 +0100
@@ -1516,6 +1516,15 @@
         if safehasattr(self, '_fp'): # constructor actually did something
             self.discard()
 
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exctype, excvalue, traceback):
+        if exctype is not None:
+            self.discard()
+        else:
+            self.close()
+
 def makedirs(name, mode=None, notindexed=False):
     """recursive directory creation with parent mode inheritance