# HG changeset patch # User Gregory Szorc # Date 1515987048 28800 # 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 -r 15cfd343d3a9 -r 40da2d7b4871 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 """