mercurial/dirstateguard.py
changeset 33619 609606d21765
parent 33440 ec306bc6915b
child 33793 bbbbd3c30bfc
--- a/mercurial/dirstateguard.py	Tue Aug 01 10:14:25 2017 -0400
+++ b/mercurial/dirstateguard.py	Thu Jul 20 01:30:41 2017 -0700
@@ -43,6 +43,16 @@
             # ``release(tr, ....)``.
             self._abort()
 
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        try:
+            if exc_type is None:
+                self.close()
+        finally:
+            self.release()
+
     def close(self):
         if not self._active: # already inactivated
             msg = (_("can't close already inactivated backup: %s")