changeset 35652:40da2d7b4871

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 14 Jan 2018 19:30:48 -0800
parents 15cfd343d3a9
children 48fe4f56a3b4
files mercurial/commandserver.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 """