Patchwork D1859: commandserver: restore cwd in case of exception

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2018, 5 a.m.
Message ID <differential-rev-PHID-DREV-inuckohhfelzru6p7q7i-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26755/
State Superseded
Headers show

Comments

phabricator - Jan. 15, 2018, 5 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The order of the statements was also changed a bit. But it shouldn't
  matter.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/commandserver.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
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 """