Patchwork D1859: commandserver: restore cwd in case of exception

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2018, 1:25 p.m.
Message ID <a7d5e7c38126c35fffeddce8e8a8a33a@localhost.localdomain>
Download mbox | patch
Permalink /patch/26760/
State Not Applicable
Headers show

Comments

phabricator - Jan. 15, 2018, 1:25 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG40da2d7b4871: commandserver: restore cwd in case of exception (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1859?vs=4827&id=4830

REVISION DETAIL
  https://phab.mercurial-scm.org/D1859

AFFECTED FILES
  mercurial/commandserver.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -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 """