
    6hY                    ^   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJr  SSKJr  SSKJrJrJrJrJr  SSKJr  \R.                  " S5      r\R2                  (       a  SS	KJr  OSS
KJr  S r " S S\R<                  5      r " S S5      r \RB                  RE                  \ 5        S r#S r$ " S S\RJ                  5      r&\RN                  RE                  \&5        S r(\RR                  c  \" 5       r)O\RR                  RT                  r)\RV                  c  \" 5       r+O\(" \RV                  RT                  5      r+\RX                  c  \" 5       r,O\(" \RX                  RT                  5      r,\R2                  (       a$  \RZ                  " \+5      r+\RZ                  " \,5      r,\" \+5      (       a  \R\                  S:w  a  \#" \+5      r+\R^                  r/\R`                  r1\Rd                  r2\Rf                  r3\Rh                  r4\Rj                  r5\Rl                  r6\Rn                  r7\Rp                  r8\Rr                  r9\Rt                  r:\Rv                  r;\Rx                  r< \Rz                  r= \R~                  r?\R                  =(       a    \R\                  S:g  rAS rB " S S5      rCS7S jrDS rES rFS8S jrGS8S jrHS9S jrIS rJS  rK\K\JS!.rLS" rMSqNS# rOS$ rPS% rQS& rRS' rSS( rTS) rUS8S* jrV\R2                  (       a  S+ rW\R                  rYOS, rW\R                  rYS- r[S:S. jr\Sq]S/ r^S0 r_S1 r`S;S2 jra\R                  S3 5       rc\R2                  (       a  S4rd\d\R                  -  rf      S<S5 jrgg      S<S6 jrgg! \> a     GNf = f! \> a     GNf = f)=    )annotationsN)BinaryIO   _)encodingerrorpolicypycompattypelib)resourceutilosutil)windows)posixc                D     U R                  5       $ ! [         a     gf = f)NF)isattyAttributeError)fps    :/usr/lib/python3/dist-packages/mercurial/utils/procutil.pyr   r   /   s%    yy{ s    
c                  $    \ rS rSrSrS rS rSrg)BadFile6   z3Dummy file object to simulate closed stdio behaviorc                6    [        [        R                  S5      eNzBad file descriptorOSErrorerrnoEBADFselfbs     r   readintoBadFile.readinto9       ekk#899    c                6    [        [        R                  S5      er   r   r   s     r   writeBadFile.write<   r$   r%    N)__name__
__module____qualname____firstlineno____doc__r"   r'   __static_attributes__r)   r%   r   r   r   6   s    =::r%   r   c                  &    \ rS rSrS rS rS rSrg)LineBufferedWrapper@   c                    Xl         g Norigr    r6   s     r   __init__LineBufferedWrapper.__init__A       	r%   c                .    [        U R                  U5      $ r4   getattrr6   r    attrs     r   __getattr__LineBufferedWrapper.__getattr__D       tyy$''r%   c                    U R                   nUR                  U5      nUR                  S5      (       a  UR                  5         U$ )N   
)r6   r'   endswithflush)r    sr6   ress       r   r'   LineBufferedWrapper.writeG   s5    yyjjm::eJJL
r%   r5   Nr*   r+   r,   r-   r8   r@   r'   r/   r)   r%   r   r1   r1   @   s    (r%   r1   c                   U n [        U[        5      (       a  UR                  nOB[        R                  (       a,  [        U[
        R                  5      (       a  UR                  nOOMf  [        U[        R                  5      (       a  U $ [        U[        R                  5      (       a  O[        S5      e[        U [        5      (       a  U $ [        U 5      $ )Nz1can't determine whether stream is buffered or not)
isinstanceWriteAllWrapperr6   r   	iswindowsplatform	winstdoutr   io	RawIOBaseBufferedIOBaseNotImplementedErrorr1   )streamcheck_streams     r   make_line_bufferedrW   T   s    L
lO44',,LJ%
 %
 (??L  ,--	L""3"3	4	4 	!?
 	
 &-..v&&r%   c                    [        U [        5      (       a-  [        U R                  [        5      (       a   eU R                  $ U $ r4   )rL   r1   r6   rU   s    r   unwrap_line_bufferedrZ   t   s7    &-..fkk+>????{{Mr%   c                  *    \ rS rSrSS jrS rS rSrg)rM   {   c                    Xl         g r4   r5   r7   s     r   r8   WriteAllWrapper.__init__|   r:   r%   c                .    [        U R                  U5      $ r4   r<   r>   s     r   r@   WriteAllWrapper.__getattr__   rB   r%   c                    U R                   R                  n[        U5      n[        U5      nSnXT:  a  U" X5S  5      nU(       a  XV-  nXT:  a  M  U$ )Nr   )r6   r'   
memoryviewlen)r    rG   write1mtotal_to_writetotal_writtencs          r   r'   WriteAllWrapper.write   sV    qMQ,q()A" , r%   r5   N)r6   r   rJ   r)   r%   r   rM   rM   {   s    (	r%   rM   c                    [        U [        5      (       a  U $ [        U [        R                  5      (       a  U $ [        U 5      $ r4   )rL   rM   rQ   rS   rY   s    r   _make_write_allrk      s;    &/**&"++,,  6""r%      OpenVMSc                H    U S:  a  [        S5      U -  $ [        S5      U * -  $ )zlreturn a message describing a subprocess status
(codes from kill are negative - not os.system/wait encoding)r   s   exited with status %ds   killed by signal %dr   )codes    r   explainexitro      s/     qy)*T11#$u,,r%   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)_pfile   z;File-like wrapper for a stream opened by subprocess.Popen()c                    Xl         X l        g r4   )_proc_fp)r    procr   s      r   r8   _pfile.__init__   s    
r%   c                j    U R                   R                  5         U R                  R                  5       $ r4   )ru   closert   waitr    s    r   ry   _pfile.close   s!    zz  r%   c                ,    [        U R                  5      $ r4   )iterru   r{   s    r   __iter___pfile.__iter__   s    DHH~r%   c                .    [        U R                  U5      $ r4   )r=   ru   r>   s     r   r@   _pfile.__getattr__   s    txx&&r%   c                    U $ r4   r)   r{   s    r   	__enter___pfile.__enter__   s    r%   c                $    U R                  5         g r4   )ry   )r    exc_type	exc_valueexc_tbs       r   __exit___pfile.__exit__   s    

r%   )ru   rt   N)r*   r+   r,   r-   r.   r8   ry   r   r@   r   r   r/   r)   r%   r   rq   rq      s#    E!
'r%   rq   c                x    US:X  a  [        X5      $ US:X  a  [        X5      $ [        R                  " SU-  5      e)N   rbs   wbs   unsupported mode: %r)_popenreader_popenwriterr	   ProgrammingError)cmdmodebufsizes      r   popenr      s=    u}C))	C))

 
 !84!?
@@r%   c                    [         R                  " [        U 5      SU[        [         R                  S9n[        X"R                  5      $ )NT)shellr   	close_fdsstdout)
subprocessPopentonativestrclosefdsPIPErq   r   r   r   ps      r   r   r      s;    C	A !XXr%   c                    [         R                  " [        U 5      SU[        [         R                  S9n[        X"R                  5      $ )NT)r   r   r   stdin)r   r   r   r   r   rq   r   r   s      r   r   r     s;    Coo	A !WWr%   c                    [         R                  " [        U 5      SS[        [         R                  [         R                  [        U5      S9nUR                  UR                  4$ )NT)r   r   r   r   r   env)r   r   r   r   r   tonativeenvr   r   )r   r   r   s      r   popen2r     sP     	Coo	A 77AHHr%   c                &    [        X5      u  p#pEX#U4$ r4   )popen4)r   r   r   r   stderrr   s         r   popen3r   #  s    %c/E6&  r%   c                    [         R                  " [        U 5      SU[        [         R                  [         R                  [         R                  [        U5      S9nUR                  UR                  UR                  U4$ )NT)r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   )r   r   r   r   s       r   r   r   (  s]    Coo		A 77AHHahh))r%   c                    [         R                  " [        U5      S[        [         R                  [         R                  S9nUR                  U 5      u  p4U$ )z9filter string S through command CMD, returning its outputT)r   r   r   r   )r   r   r   r   r   communicate)rG   r   r   poutperrs        r   
pipefilterr   6  sE    Coo	A q!JDKr%   c                   Su  p# [         R                  " SS9u  pB[        R                  " US5       nUR	                  U 5        SSS5        [         R                  " SS9u  pc[        R
                  " U5        UR                  SU5      nUR                  SU5      n[        U5      nU(       a-  [        R                  " [        S	5      U[        U5      4-  5      e[        US
5       nUR                  5       sSSS5         U(       a  [        R                  " U5         U(       a  [        R                  " U5        $ $ ! , (       d  f       GN= f! [         a     N>f = f! [         a     $ f = f! , (       d  f       O= f  U(       a  [        R                  " U5        O! [         a     Of = f U(       a  [        R                  " U5        gg! [         a     gf = f!  U(       a  [        R                  " U5        O! [         a     Of = f U(       a  [        R                  " U5        f f ! [         a     f f = f= f)zfilter string S through a pair of temporary files with CMD.
CMD is used as a template to create the real command to be run,
with the strings INFILE and OUTFILE replaced by the real names of
the temporary files generated.)NNs   hg-filter-in-)prefixwbNs   hg-filter-out-s   INFILEs   OUTFILEs   command '%s' failed: %srb)r   mkstemposfdopenr'   ry   replacesystemr	   Abortr   ro   openreadunlinkr   )rG   r   innameoutnameinfdr   outfdrn   s           r   
tempfilterr   C  s   
 !OF''/?@YYtT"bHHQK # "))1BC
kk)V,kk*g.c{++,-k$6G0HH  '4 B779 ! 			&!			'" + #"$  		
  		 !  			&! 					'"  					&! 					'"  		s   -G" D?B#G" (E18	G" E E!?
E	G" 
EE!
E.-E.1
E?;G" F" "
F/.F/3G 
GG"I$HI
HIHIH20I2
H?<I>H??I)s	   tempfile:s   pipe:c                    [         R                  5        H?  u  p#UR                  U5      (       d  M  U" X[        U5      S R	                  5       5      s  $    [        X5      $ )zIfilter a string through a command that transforms its input to its
outputN)_filtertableitems
startswithrc   lstripr   )rG   r   namefns       r   filterr   m  sT     !&&(>>$aSY[)00233 ) ar%   c                 Z   [         Gc  [        R                  R                  SS5      n [        R
                  S   n[        R                  S:X  a  U SS S:X  a  S	U SS -   n U (       a  [        U 5        [         $ [        R                  " 5       (       aW  [        [        S
S5      S:X  a"  [        [        R                  S   5        [         $ [        [        R                  5         [         $ [        R                  (       d]  [        R                  R!                  [        USS5      5      S:X  a/  [        [        R"                  " UR$                  5      5        [         $ [        ['        S5      =(       d0    [        R                  R!                  [        R(                  S   5      5        [         $ )zUreturn location of the 'hg' executable.

Defaults to $HG or 'hg' in the search path.
N   HG __main__rl   r      $zmcr frozen
macosx_app   EXECUTABLEPATH__file__hgs   hg)_hgexecutabler   environgetsysmodulesr   sysplatform_sethgexecutabler   
mainfrozenr=   sysexecutablerN   r   pathbasenamefsencoder   findexesysargv)r   mainmods     r   hgexecutabler   y  sF   
 !!%,++j):-"Qq'S."QR&BR    $$&&sHd+|; !1!12C!DE  !!7!78  ""  *b!ABdJX..w/?/?@A
  G"''"2"283C3CA3F"G r%   c                    U q g)z#set location of the 'hg' executableN)r   )r   s    r   r   r     s	     Mr%   c                    [        U SS 5      n U=(       a    U" 5       UR                  5       :H  $ ! [        R                   a     gf = f)NfilenoF)r=   r   rQ   UnsupportedOperation)fstdfr   s      r   _testfilenor     sE    Q$'F3&(dkkm33"" s    0 AAc                6    [        U [        R                  5      $ r4   )r   r   	__stdin__r   s    r   isstdinr     s    q#--((r%   c                6    [        U [        R                  5      $ r4   )r   r   
__stdout__r   s    r   isstdoutr     s    q#..))r%   c                   UR                  5         Xp2[        U [        5      (       a  [        R                  " U R                  5       5      n[        R                  " [        R                  [        R                  5      n[        R                  " XPR                  5       5        [        R                  " U5        [        R                  " US5      n[        U[        5      (       ar  [        R                  " UR                  5       5      n[        R                  " [        R                  5       UR                  5       5        [        R                  " US5      nX#4$ )a  Duplicate streams and redirect original if (uin, uout) are stdio

If uin is stdin, it's redirected to /dev/null. If uout is stdout, it's
redirected to stderr so the output is still readable.

Returns (fin, fout) which point to the original (uin, uout) fds, but
may be copy of (uin, uout). The returned streams can be considered
"owned" in that print(), exec(), etc. never reach to them.
r   r   )rF   r   r   r   dupr   r   devnullO_RDONLYdup2ry   r   r   r   )uinuoutfinfoutnewfdnullfds         r   protectstdior     s     	JJL3szz|$R[[1


%
iit$4  t{{}%
/yy%9r%   c                    UR                  5         X 4X144 HN  u  pEXELd  M  [        R                  " UR                  5       UR                  5       5        UR	                  5         MP     g)z@Restore (uin, uout) streams from possibly duplicated (fin, fout)N)rF   r   r   r   ry   )r   r   r   r   r   uifs         r   restorestdior    sH    JJL:|,<GGAHHJ

-GGI -r%   c                   ^ S m[        [        R                  5      nU (       a)  UR                  U4S jU R	                  5        5       5        [        5       US'   U$ )z>return environ with optional override, useful for shelling outc                L    U b  U SL a  gU SL a  g[         R                  " U 5      $ )z9convert python object into string that is useful to shellF   0T   1)r   bytestr)vals    r   py2shellshellenviron.<locals>.py2shell  s+    ;#,$;$$r%   c              3  <   >#    U  H  u  pUT" U5      4v   M     g 7fr4   r)   ).0kvr	  s      r   	<genexpr>shellenviron.<locals>.<genexpr>  s     @Ax{#s   r   )dictr   r   updater   r   )r   r   r	  s     @r   shellenvironr    sE    % x
 C

@@@CJJr%   c                B    [         R                  " U [        U5      5      $ r4   )rO   shelltocmdexer  r   r   s     r   shelltonativer    s    %%c"
 	
r%   c                    U $ r4   r)   r  s     r   r  r    s    
r%   c                8    [         R                  " [        U 5      $ )zHconvert the environment from bytes to strings suitable for Popen(), etc.)r   rapplyr   )r   s    r   r   r     s    ??;,,r%   c           
         [         R                  5         [        U5      nUb  [	        U5      (       aI  [
        R                  " [        U 5      S[        [        U5      [        R                  " [        U5      S9nU$ [
        R                  " [        U 5      S[        [        U5      [        R                  " [        U5      [
        R                  [
        R                  S9n[        UR                   R                   S5       H  nUR#                  U5        M     UR%                  5         UR&                  nU$ ! [         a     GN/f = f)zenhanced shell command execution.
run with environment maybe modified, maybe in different dir.

if out is specified, it is assumed to be a file-like object that has a
write() method. stdout and stderr will be redirected to out.T)r   r   r   cwd)r   r   r   r  r   r   r%   )r   rF   	Exceptionr  r   r   callr   r   r   r   r  r   r   STDOUTr~   readliner'   rz   
returncode)r   r   r  outr   rcrv   lines           r   r   r     s     w
C
{hsmm__C S1
* I C S1??$$
 --s3DIIdO 4		__I3  s   D8 8
EEc                 d   [         R                  (       a@  S[        R                  ;   a  g[	        [
        SS5      (       a  [
        R                  5       $ g[         R                  =(       dE    [        R                  R                  S5      =(       d    [        R                  R                  S5      $ )zAre we running in a GUI?s   SSH_CONNECTIONFisguiNTs   DISPLAYs   WAYLAND_DISPLAY)	r   isdarwinr   r   r=   r   r&  rN   r   r)   r%   r   _guir(    s     0 00VWd++<<>!   8##J/8##$67	
r%   c                 0    [         c
  [        5       q [         $ r4   )_is_guir(  r)   r%   r   guir+  1  s    &Nr%   c                     [         R                  " 5       (       a:  [        [        SS5      S:X  a  [        R
                  S   /$ [        R                  /$ [        5       $ )zReturn the command used to execute current hg

This is different from hgexecutable() because on Windows we want
to avoid things opening new shell windows like batch files, so we
get either the python call or current executable.
r   Nr   r   )	r   r   r=   r   r   r   r   r   	_gethgcmdr)   r%   r   hgcmdr.  8  sP       3$'<7$$%6788**++;r%   c                :  ^ [        5       mU4S jnSn[        [        SS5      nUb  [        R                  " XB5      n [        U 5      nU" 5       (       dp  UT;   d  [	        U5      (       d6  U" 5       (       d*   Ub%  [        R                  " [        R
                  U5        g[        R                  " S5        U" 5       (       d  Mp  UUb%  [        R                  " [        R
                  U5        $ ! Ub%  [        R                  " [        R
                  U5        f = f)aG  Execute the argument list in a detached process.

condfn is a callable which is called repeatedly and should return
True once the child process is known to have started successfully.
At this point, the child process PID is returned. If the child
process fails to start or finishes before condfn() evaluates to
True, return -1.
c                N   > TR                  [        R                  " 5       5        g r4   )addr   rz   )signumframe
terminateds     r   handlerrundetached.<locals>.handlerZ  s    rwwy!r%   NSIGCHLDr   g?)setr=   signalspawndetachedtestpidr7  timesleep)argscondfnr5  prevhandlerr7  pidr4  s         @r   rundetachedrB  H  s      J" Kfi.GmmG5D!((z!vxx "MM&..+6 	 JJsO (( "MM&..+6 	 "MM&..+6 	s   9C0 ""C0 C0 0*Dc              #    ^ ^^#    [         R                  " [         R                  5      /m/ mUUU 4S jn  [         R                   " [         R                  U5        Sv   T(       a(  [         R                   " [         R                  TS   5        T(       a  [        eg! [         a    TS	  NPf = f! T(       a(  [         R                   " [         R                  TS   5        T(       a  [        ef = f7f)zInhibit SIGINT handling on a region of code.

Note that if this is called in a non-main thread, it turns into a no-op.

Args:
  warn: A callable which takes no arguments, and returns True if the
        previous signal handling should be restored.
c                    > T" 5       (       a+  [         R                   " [         R                  TS   5        TS	 TR                  S5        g )Nr   T)r9  SIGINTappend)r>  oldsiginthandler
shouldbailwarns    r   disabledsiginthandler.uninterruptible.<locals>.disabledsiginthandler  s8    66MM&--)9!)<= #$r%   r   N)r9  	getsignalrE  
ValueErrorKeyboardInterrupt)rI  rJ  rG  rH  s   ` @@r   uninterruptiblerO  s  s      ((78J $	$MM&--)>? 	MM&--)9!)<=##   	$ #	$
 MM&--)9!)<=## s:   0C1%B B0  =C1B-*B0 ,B--B0 0>C..C1   c                   Sn UbG  [         R                  " 5       nUR                  U5        UR                  5         UR	                  S5        [
        R                  " [         R                  " [        U 5      U[        U5      S[        UUUS9n	Ub  U" U	R                  5        Ub  UR                  5         gg! Ub  UR                  5         f f = f)z1Spawn a command without waiting for it to finish.Nr   T)r   r   r   creationflagsr   r   r   )r   unnamedtempfiler'   rF   seekr   r   r  r   r   _creationflagsrz   ry   )
scriptr   r   r   r   ensurestartrecord_waitstdin_bytesr   r   s
             r   runbgcommandrZ    s     	& 002K(

1  V4$,	A &AFF#  !u  !s   B B9 9Cc                  ^ [         R                  (       a
  [        5         U(       a  U nO0[        U [        5      (       a  U /n SR                  S U  5       5      nUc  SU-  nSn	OSn	SnSn
 Uc  [        R                  n
OG[         R                  " 5       n
U
R                  U5        U
R                  5         U
R                  S5        Uc  [        R                  nUc  [        R                  n[        R                  " USUSU
UUU	S9m Ub*  U
b'  [        U
[        5      (       a   eU
R                  5         U(       d0  [         R"                  " U4S
 jS9nSUl        UR'                  5         gTR(                  nUb	  U" U5        gg! [         a    Ub  U" S	5        e f = f! Ub,  U
b(  [        U
[        5      (       a   eU
R                  5         f f f = f)at  Spawn a command without waiting for it to finish.


When `record_wait` is not None, the spawned process will not be fully
detached and the `record_wait` argument will be called with a the
`Subprocess.wait` function for the spawned process.  This is mostly
useful for developers that need to make sure the spawned process
finished before a certain point. (eg: writing test)    c              3  8   #    U  H  n[        U5      v   M     g 7fr4   )
shellquote)r  xs     r   r  runbgcommand.<locals>.<genexpr>  s     :cz!}}cs   Ns   ( ( %s ) <&3 3<&- &) 3<&0TFr   )r   r   r   r   r   r   start_new_session   c                    > T R                   $ r4   )rz   )r   s   r   <lambda>runbgcommand.<locals>.<lambda>  s	    r%   )target)r   r'  r+  rL   bytesjoinr   DEVNULLrS  r'   rF   rT  r   r  intry   	threadingThreaddaemonstartrz   )r   r   r   r   r   rW  rX  rY  rV  ra  r   tr!  r   s                @r   rZ  rZ    s   $  EF#u%%eYY:c::F1F:F $ %K	""** 002K(

1~#++~#++  "3	A &5+<%eS1111   7AAHGGIJ&J' ''  	&C 	
 &5+<%eS1111 ,=&s   -BF FF! !1G)r   r   r4   )Nr   )NNN)returnrj  )FNNTNN)h
__future__r   
contextlibr   rQ   r   r9  r   r   rk  r<  typingr   i18nr   r   r   r	   r
   r   r   utilsr   	importmodr   rN   r   rO   r   r   rR   r   r1   rS   registerrW   rZ   BinaryIO_ProxyrM   IOBaserk   r   bufferr   r   rP   r   r   gethgcmdr-  getusergetpid
hidewindowreadpipe	setbinarysetsignalhandlerr^  
shellsplitr:  sshargsr;  setprocnamer   unblocksignalisposixr   ro   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  strfromlocalr   identityr   r   r*  r(  r+  r.  rB  contextmanagerrO  DETACHED_PROCESSCREATE_NEW_PROCESS_GROUPrU  rZ  r)   r%   r   <module>r     s   #   	 	   
     !			(	#&$:bll :       . /'@g,, ( 		  ? #	#$ 99IEIIE::YFSZZ../F::YFSZZ../F'F'F	&>>h**j8'F


	


	  
	,,   
  
&&





	$$K	((M B 4 4
 B- 2A !
*
!J  <)*2$ 

 ''K ##K-
!H 
( (V $ $B  "
 	

-
-	.  %X R(C  		  		s$   5N N" NN"N,+N,