mercurial/commandserver.py
branchstable
changeset 14864 1b872599f39f
parent 14751 712954a67be3
child 14882 bb2cffe81a94
equal deleted inserted replaced
14863:1c148e935244 14864:1b872599f39f
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import struct
     9 import struct
    10 import sys
    10 import sys, os
    11 import dispatch, encoding, util
    11 import dispatch, encoding, util
    12 
    12 
    13 logfile = None
    13 logfile = None
    14 
    14 
    15 def log(*args):
    15 def log(*args):
   129     """
   129     """
   130     Listens for commands on stdin, runs them and writes the output on a channel
   130     Listens for commands on stdin, runs them and writes the output on a channel
   131     based stream to stdout.
   131     based stream to stdout.
   132     """
   132     """
   133     def __init__(self, ui, repo, mode):
   133     def __init__(self, ui, repo, mode):
       
   134         self.cwd = os.getcwd()
   134         self.ui = ui
   135         self.ui = ui
   135 
   136 
   136         logpath = ui.config("cmdserver", "log", None)
   137         logpath = ui.config("cmdserver", "log", None)
   137         if logpath:
   138         if logpath:
   138             global logfile
   139             global logfile
   181         # persist between requests
   182         # persist between requests
   182         copiedui = self.ui.copy()
   183         copiedui = self.ui.copy()
   183         self.repo.baseui = copiedui
   184         self.repo.baseui = copiedui
   184         self.repo.ui = self.repo.dirstate._ui = self.repoui.copy()
   185         self.repo.ui = self.repo.dirstate._ui = self.repoui.copy()
   185 
   186 
   186         req = dispatch.request(args, copiedui, self.repo, self.cin,
   187         req = dispatch.request(args[:], copiedui, self.repo, self.cin,
   187                                self.cout, self.cerr)
   188                                self.cout, self.cerr)
   188 
   189 
   189         ret = dispatch.dispatch(req) or 0 # might return None
   190         ret = dispatch.dispatch(req) or 0 # might return None
       
   191 
       
   192         # restore old cwd
       
   193         if '--cwd' in args:
       
   194             os.chdir(self.cwd)
   190 
   195 
   191         self.cresult.write(struct.pack('>i', int(ret)))
   196         self.cresult.write(struct.pack('>i', int(ret)))
   192 
   197 
   193     def getencoding(self):
   198     def getencoding(self):
   194         """ writes the current encoding to the result channel """
   199         """ writes the current encoding to the result channel """