\x89\x50\x4E\x47\x0D\x0A\x1A\x0A PNG  \x89\x50\x4E\x47\x0D\x0A\x1A\x0A  13\c@@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZmZmZddlmZejZdZd d d d gZd(gZejdejZdZdZ dZ!de"fdYZ#dZ$dZ%de"fdYZ&d)d*d+gZ'd!ej(fd"YZ)d#Z*d$Z+d%e"fd&YZ,d'Z-dS(,sRcommand server extension for cHg 'S' channel (read/write) propagate ui.system() request to client 'attachio' command attach client's stdio passed by sendmsg() 'chdir' command change current directory 'setenv' command replace os.environ completely 'setumask' command (DEPRECATED) 'setumask2' command set umask 'validate' command reload the config and check if the server is up to date Config ------ :: [chgserver] # how long (in seconds) should an idle chg server exit idletimeout = 3600 # whether to skip config or env change checks skiphash = False i(tabsolute_importNi(t_(t commandservertencodingterrort extensionstnodetpycompattutil(tprocutilcC@s"tjtjt|jS(s return sha1 hexdigest for a list(Rthexthashlibtsha1tstrtdigest(titems((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _hashlistGstaliasteoltextdiffRtcommandssshow.aliasprefixs~\A(?: CHGHG |HG(?:DEMANDIMPORT|EMITWARNINGS|MODULEPOLICY|PROF|RCPATH)? |HG(?:ENCODING|PLAIN).* |LANG(?:UAGE)? |LC_.* |LD_.* |PATH |PYTHON.* |TERM(?:INFO)? |TZ )\Zc C@sg}x$tD]}|j|j|q Wx-tD]%\}}|j|j||q4Wt|}dtjkrdh}n t}gtjj D]3\}}t j |r||kr||f^q}tt |} |d | d S(sreturn a quick hash for detecting config/env changes confighash is the hash of sensitive config items and environment variables. for chgserver, it is designed that once confighash changes, the server is not qualified to serve its client and should redirect the client to a new server. different from mtimehash, confighash change will not mark the server outdated and exit since the user can have different configs at the same time. tCHGHGtHGi( t_configsectionstappendt configitemst_configsectionitemstconfigRRtenvirontsett iteritemst_envretmatchtsorted( tuit sectionitemstsectiontitemt sectionhashtignoredtktvtenvitemstenvhash((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _confighashes     -cC@sgtj|D]\}}|^q}y!ddlm}|j|Wntk r\nXtjg}x<|D]4}y|jtj|Wqpt k rqpXqpWt t |S(sget a list of paths that should be checked to detect change The list will include: - extensions (will not cover all files for complex extensions) - mercurial/__version__.py - python binary i(t __version__( RtR-Rt ImportErrorRt sysexecutabletinspectt getabsfilet TypeErrorR!R(R"tntmtmodulesR-tfiles((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt_getmtimepathss(    cC@s d}tt||d S(sWreturn a quick hash for detecting file changes mtimehash calls stat on given paths and calculate a hash based on size and mtime of each file. mtimehash does not read file content because reading is expensive. therefore it's not 100% reliable for detecting content changes. it's possible to return different hashes for same file contents. it's also possible to return a same hash for different file contents for some carefully crafted situation. for chgserver, it is designed that once mtimehash changes, the server is considered outdated immediately and should no longer provide service. mtimehash is not included in confighash because we only know the paths of extensions after importing them (there is imp.find_module but that faces race conditions). We need to calculate confighash without importing. cS@s?y'tj|}|tj|jfSWntk r:nXdS(N(toststattST_MTIMEtst_sizetOSError(tpathtst((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyttrystats  i (Rtmap(tpathsR@((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _mtimehashs t hashstatecB@s)eZdZdZeddZRS(sCa structure storing confighash, mtimehash, paths used for mtimehashcC@s||_||_||_dS(N(t confighasht mtimehasht mtimepaths(tselfRERFRG((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt__init__s  cC@sW|dkrt|}nt|}t|}td||ft|||S(Nsconfighash = %s mtimehash = %s (tNoneR8R,RCt_logRD(R"RGRERF((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pytfromuis    N(t__name__t __module__t__doc__RIt staticmethodRJRL(((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRDs c@s/d|jffdY|S(Ntchguic@s8eZdfdZdZdfdZRS(c@sAt|j||r4t|d|_n |_dS(Nt_csystem(tsuperRItgetattrRR(RHtsrc(RQtcsystem(s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRIscS@s||jk sLtj|jd sL|jjtjjksL|jrktj|d|d|d|S|j|j |tj ||S(NtfilenoRtcwdtout( tfoutRt safehasattrRWR tstdoutt_finoutredirectedtsystemtflushRRt shellenviron(RHtcmdRRXRY((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _runsystems  c @s0|j|tj|dddid6tS(Nttypetpagertcmdtabletattachio(RRR R`tTrue(RHRatenv(Rf(s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _runpagersN(RMRNRJRIRbRi((RfRQRV(s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRQs (t __class__(tsrcuiRVRf((RfRQRVs9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _newchguis%cC@skddlm}|jj}x3ddddgD]}t||t||q2Wtj|drv|j|_n|j ||}|j ||dxr|j D]d\}}}|j ||} d | ks| d ks| j d rqn|j|||| qW|d } | r3tjj| p6d} |d } |j|| d| \} } || fS(Ni(tdispatchtfinRZtferrRRRRt:s--configt$RXt repositorytwd(R.RmRjtloadtsetattrRTRR[RRt_earlyparseoptst _parseconfigt walkconfigt configsourcet startswitht setconfigR9R>trealpathRJt _getlocal(RktargsRmtnewuitatoptionsR$tnametvaluetsourceRXtrpathR>tnewlui((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _loadnewuis$'  tchanneledsystemcB@s)eZdZdZddddZRS(sPropagate ui.system() request in the following format: payload length (unsigned int), type, '', cmd, '', cwd, '', envkey, '=', val, '', ... envkey, '=', val if type == 'system', waits for: exitcode length (unsigned int), exitcode (int) if type == 'pager', repetitively waits for a command name ending with ' ' and executes it defined by cmdtable, or exits the loop if the command name is empty. cC@s||_||_||_dS(N(tin_RYtchannel(RHRRYR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRIs  R^c C@s|tj|tjj|p!dg}|jd|jDdj|}|jj t j d|j t ||jj ||jj|dkr|jjd}t jd|\}|dkrtjtdnt jd |jjd\} | S|d krxtr|jjd }|sIPn|rw||krwtd |||q&tjtd |q&Wntjd|dS(Nt.cs@s%|]\}}d||fVqdS(s%s=%sN((t.0R(R)((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pys sss>cIR^is>Isinvalid responses>iRdispager subcommand: %ssunexpected command: %ssinvalid S channel type: %s(R t quotecommandR9R>tabspathtextendRtjoinRYtwritetstructtpackRtlenR_RtreadtunpackRtAbortRRgtreadlineRKtProgrammingError( RHRaRRXRcReR~tdatatlengthtrc((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt__call__s.*(   !   N(RMRNRORIRJR(((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs tcinRntrbtcoutRZtwbtcerrRot chgcmdservercB@seZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z ejjjZejied 6ed 6e d6e d6e d6e d6ejedrdZeedcItIisreceived fds: %r Rois>iN(RtsendallRRRtrecvfdsRWRKR"R_t_saveiotzipt _iochannelsRTR9tdup2tcloseRtisattytfdopenRuRgtcresultRR( RHt clientfdsR"tfdtcntfntmodetfptnewfptbufsize((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRfMs,   %       cC@s|jr dS|j}xctD][\}}}t||}t||}tj|j}|jj|||fqWdS(N(RR"RRTR9tdupRWR(RHR"RRt_modetchRR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRus  c C@s|j}xt|jtD]\\}}}\}}}t||}||k rb|jntj||jtj|t |||t |||qW|j2dS(N( R"RRRRTRR9RRWRu( RHR"RRRRRRR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs 1   cC@sddlm}|j}yt|j|\|_}Wntjk r}|j|jj||jj |j j ddStj k r}|jjt d||jr|jjt d|jn|jj |j j ddSXtj||jj}g}|j|jjkryt|j|jj}|jd||jjry|jdqyn|j|jjkrt|j|j}|jd |ntd ||j j d j|pd dS( sReload the config and check if the server is up to date Read a list of '' separated arguments. Write a non-empty list of '' separated instruction strings or '' if the list is empty. An instruction string could be either: - "unlink $path", the client should unlink the path to stop the outdated server. - "redirect $path", the client should attempt to connect to $path first. If it does not work, start a new server. It implies "reconnect". - "exit $n", the client should exit directly with code n. This may happen if we cannot parse the config. - "reconnect", the client should close the connection and reconnect. If neither "reconnect" nor "redirect" is included in the instruction list, the client can continue with this server after completing all the instructions. i(Rmsexit 255Ns abort: %s s(%s) s unlink %st reconnects redirect %ss validate: %s s(R.Rmt _readlistRR"Rt ParseErrort _formatparsetwarnR_RRRRthintRDRLRGRFt _hashaddressRRERRKR(RHRmR~tluitinsttnewhashtinststaddr((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs8      cC@s5|j}|sdStd|tj|dS(sChange current directory Note that the behavior of --cwd option is bit different from this. It does not affect --config parameter. Ns chdir to %r (t_readstrRKR9tchdir(RHR>((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs  cC@s|j|jddS(sChange umask (DEPRECATED)iN(t _setumaskt_read(RH((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pytsetumaskscC@s>|j}t|dkr-tdn|j|dS(s Change umaskis(invalid mask length in setumask2 requestN(RRt ValueErrorR(RHR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt setumask2s cC@s5tjd|d}td|tj|dS(Ns>Iis setumask %r (RRRKR9tumask(RHRtmask((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRscC@sD|j}g|_ztt|jSWd|j||_XdS(N(RRSRt runcommandR(RHt globaloldios((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs    cC@s|j}ytd|D}Wntk rEtdnXtdt|jtjjtjj |dS(stClear and update os.environ Note that not all variables can make an effect on the running process. cs@s!|]}|jddVqdS(t=iN(tsplit(Rts((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pys ss"unexpected value in setenv requests setenv: %r N( RtdictRRKR!tkeysRRtcleartupdate(RHtltnewenv((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pytsetenvs   RfRRRRRt setprocnamecC@s+|j}td|tj|dS(sChange process titlessetprocname: %r N(RRKR R(RHR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs (RMRNRIRRfRRRRRRRRRRtserverRRRRR[R R(((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyR7s,  (  4      cC@sd|tjfS(Ns %s.%d.tmp(R9tgetpid(taddress((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt _tempaddress scC@sKtjj|\}}|jddd}dtjj|||fS(NRiis%s-%s(R9R>RR(Rthashstrtdirnametbasename((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyR stchgunixservicehandlercB@sweZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d ZRS( s"Set of operations for chg servicesicC@s1||_|jdd|_tj|_dS(Nt chgservert idletimeout(R"t configintt _idletimeoutttimet _lastactive(RHR"((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRIs cC@s2|j||j|j||jdS(N(t_inithashstatet_checkextensionst_bindt_createsymlink(RHRR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt bindsockets   cC@se||_|jjddr4d|_||_dStj|j|_t||jj |_dS(NRtskiphash( t _baseaddressR"t configboolRJt _hashstatet _realaddressRDRLRRE(RHR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyR&s   cC@s,|js dStjr(d|j_ndS(NR.(RRt notloadedRF(RH((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyR/s  cC@sXt|j}tj||tj||_|jtj tj ||jdS(N( RRRtbindunixsocketR9R:t _socketstattlistentsockett SOMAXCONNtrename(RHRt tempaddress((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyR8s cC@s[|j|jkrdSt|j}tjtjj|j|tj||jdS(N( RRRR9tsymlinkR>RRR(RHR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRCs cC@s_yFtj|j}|j|jjkoD|tj|jtjkSWntk rZtSXdS(N(R9R:Rtst_inoRR;R=R(RHR?((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt_issocketownerJs  cC@s$|jsdStj|jdS(N(R Rt tryunlinkR(RHR((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt unlinksocketRs cC@s[|js'|jjd|jtStj|j|jkrW|jjdtStS(Ns%s is not owned, exiting. sbeing idle too long. exiting. ( R R"tdebugRRgRRRR(RH((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt shouldexit[s cC@stj|_dS(N(RR(RH((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt newconnectiondscC@s%t|j|||||j|jS(N(RR"RR(RHRtconnRnRZ((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pytcreatecmdservergs(RMRNROt pollintervalRIRRRRRR R RRR(((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyRs     cC@sfdtjkrtjd=n|r;|jddddnt|}tj|ddd|d|S(NtCHGINTERNALMARKtbundlet mainreporootR.Rtoptsthandler(RRR{RRtunixforkingserviceRJ(R"RRth((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pytchgunixserviceks   (Rsshow.aliasprefix(RRnR(RRZR(RRoR(.ROt __future__RR R1R9treRR:RRti18nRR.RRRRRRRtutilsR tlogRKRRRtcompiletXRR,R8RCtobjectRDRlRRRRRRRRR(((s9/usr/lib64/python2.7/site-packages/mercurial/chgserver.pyt(sH        4           7   V