commandserver: restore cwd in case of exception
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 14 Jan 2018 19:30:48 -0800
changeset 35652 40da2d7b4871
parent 35651 15cfd343d3a9
child 35653 48fe4f56a3b4
commandserver: restore cwd in case of exception The order of the statements was also changed a bit. But it shouldn't matter. Differential Revision: https://phab.mercurial-scm.org/D1859
mercurial/commandserver.py
--- a/mercurial/commandserver.py	Wed Jan 10 20:02:35 2018 -0800
+++ b/mercurial/commandserver.py	Sun Jan 14 19:30:48 2018 -0800
@@ -247,13 +247,13 @@
         req = dispatch.request(args[:], copiedui, self.repo, self.cin,
                                self.cout, self.cerr)
 
-        ret = (dispatch.dispatch(req) or 0) & 255 # might return None
-
-        # restore old cwd
-        if '--cwd' in args:
-            os.chdir(self.cwd)
-
-        self.cresult.write(struct.pack('>i', int(ret)))
+        try:
+            ret = (dispatch.dispatch(req) or 0) & 255 # might return None
+            self.cresult.write(struct.pack('>i', int(ret)))
+        finally:
+            # restore old cwd
+            if '--cwd' in args:
+                os.chdir(self.cwd)
 
     def getencoding(self):
         """ writes the current encoding to the result channel """