comparison mercurial/chgserver.py @ 30741:fde9692a02c0

chg: remove getpager support We have enough bits to switch to the new chg pager code path in runcommand. So just remove the legacy getpager support. This is a red-only patch, and will break chg's pager support temporarily.
author Jun Wu <quark@fb.com>
date Tue, 10 Jan 2017 06:59:39 +0800
parents 493935e0327a
children 378686afca52
comparison
equal deleted inserted replaced
30740:493935e0327a 30741:fde9692a02c0
14 attach client's stdio passed by sendmsg() 14 attach client's stdio passed by sendmsg()
15 15
16 'chdir' command 16 'chdir' command
17 change current directory 17 change current directory
18 18
19 'getpager' command
20 checks if pager is enabled and which pager should be executed
21
22 'setenv' command 19 'setenv' command
23 replace os.environ completely 20 replace os.environ completely
24 21
25 'setumask' command 22 'setumask' command
26 set umask 23 set umask
43 import errno 40 import errno
44 import hashlib 41 import hashlib
45 import inspect 42 import inspect
46 import os 43 import os
47 import re 44 import re
48 import signal
49 import struct 45 import struct
50 import time 46 import time
51 47
52 from .i18n import _ 48 from .i18n import _
53 49
54 from . import ( 50 from . import (
55 cmdutil,
56 commandserver, 51 commandserver,
57 encoding, 52 encoding,
58 error, 53 error,
59 extensions, 54 extensions,
60 osutil, 55 osutil,
169 mtimepaths = _getmtimepaths(ui) 164 mtimepaths = _getmtimepaths(ui)
170 confighash = _confighash(ui) 165 confighash = _confighash(ui)
171 mtimehash = _mtimehash(mtimepaths) 166 mtimehash = _mtimehash(mtimepaths)
172 _log('confighash = %s mtimehash = %s\n' % (confighash, mtimehash)) 167 _log('confighash = %s mtimehash = %s\n' % (confighash, mtimehash))
173 return hashstate(confighash, mtimehash, mtimepaths) 168 return hashstate(confighash, mtimehash, mtimepaths)
174
175 # copied from hgext/pager.py:uisetup()
176 def _setuppagercmd(ui, options, cmd):
177 from . import commands # avoid cycle
178
179 if not ui.formatted():
180 return
181
182 p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
183 usepager = False
184 always = util.parsebool(options['pager'])
185 auto = options['pager'] == 'auto'
186
187 if not p:
188 pass
189 elif always:
190 usepager = True
191 elif not auto:
192 usepager = False
193 else:
194 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
195 attend = ui.configlist('pager', 'attend', attended)
196 ignore = ui.configlist('pager', 'ignore')
197 cmds, _ = cmdutil.findcmd(cmd, commands.table)
198
199 for cmd in cmds:
200 var = 'attend-%s' % cmd
201 if ui.config('pager', var):
202 usepager = ui.configbool('pager', var)
203 break
204 if (cmd in attend or
205 (cmd not in ignore and not attend)):
206 usepager = True
207 break
208
209 if usepager:
210 ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
211 ui.setconfig('ui', 'interactive', False, 'pager')
212 return p
213 169
214 def _newchgui(srcui, csystem, attachio): 170 def _newchgui(srcui, csystem, attachio):
215 class chgui(srcui.__class__): 171 class chgui(srcui.__class__):
216 def __init__(self, src=None): 172 def __init__(self, src=None):
217 super(chgui, self).__init__(src) 173 super(chgui, self).__init__(src)
482 """Change umask""" 438 """Change umask"""
483 mask = struct.unpack('>I', self._read(4))[0] 439 mask = struct.unpack('>I', self._read(4))[0]
484 _log('setumask %r\n' % mask) 440 _log('setumask %r\n' % mask)
485 os.umask(mask) 441 os.umask(mask)
486 442
487 def getpager(self):
488 """Read cmdargs and write pager command to r-channel if enabled
489
490 If pager isn't enabled, this writes '\0' because channeledoutput
491 does not allow to write empty data.
492 """
493 from . import dispatch # avoid cycle
494
495 args = self._readlist()
496 try:
497 cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui,
498 args)
499 except (error.Abort, error.AmbiguousCommand, error.CommandError,
500 error.UnknownCommand):
501 cmd = None
502 options = {}
503 if not cmd or 'pager' not in options:
504 self.cresult.write('\0')
505 return
506
507 pagercmd = _setuppagercmd(self.ui, options, cmd)
508 if pagercmd:
509 # Python's SIGPIPE is SIG_IGN by default. change to SIG_DFL so
510 # we can exit if the pipe to the pager is closed
511 if util.safehasattr(signal, 'SIGPIPE') and \
512 signal.getsignal(signal.SIGPIPE) == signal.SIG_IGN:
513 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
514 self.cresult.write(pagercmd)
515 else:
516 self.cresult.write('\0')
517
518 def runcommand(self): 443 def runcommand(self):
519 return super(chgcmdserver, self).runcommand() 444 return super(chgcmdserver, self).runcommand()
520 445
521 def setenv(self): 446 def setenv(self):
522 """Clear and update os.environ 447 """Clear and update os.environ
533 encoding.environ.update(newenv) 458 encoding.environ.update(newenv)
534 459
535 capabilities = commandserver.server.capabilities.copy() 460 capabilities = commandserver.server.capabilities.copy()
536 capabilities.update({'attachio': attachio, 461 capabilities.update({'attachio': attachio,
537 'chdir': chdir, 462 'chdir': chdir,
538 'getpager': getpager,
539 'runcommand': runcommand, 463 'runcommand': runcommand,
540 'setenv': setenv, 464 'setenv': setenv,
541 'setumask': setumask}) 465 'setumask': setumask})
542 466
543 def _tempaddress(address): 467 def _tempaddress(address):