# HG changeset patch # User Gregory Szorc # Date 2018-01-15 03:30:48 # Node ID 40da2d7b487175735bc304211da09f6f7497fd2d # Parent 15cfd343d3a9327da92526f20b8885f3506cfcd5 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 diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -247,13 +247,13 @@ class server(object): 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 """