
    6h/                        S SK J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	J
r
JrJrJrJr  SSKJrJrJr  S rS r\" 5       rS	 rSS jrS
qS rS rSS jr\R:                  S 5       rSS jrg)    )annotationsN   )_)demandimportencodingerror
extensionspycompatutil)procutilresourceutil
stringutilc           
        [        U5      (       a   UnUR                  S-   UR                  -   nGO[        R                  " U5      nUR                  S5      nUS:X  a8  [        R                  " [        S5      U[        R                  " U5      4-  5      eUSU n	[        R                  n
[        R                  " 5       (       aQ  [        R                  R!                  U	5      u  pU(       a)  U(       a"  [        R                  SS U/-   [        l        Un	["        R$                  " 5           ['        [        R                  " U	5      5      nSSS5        U
[        l         UR!                  S5      SS  H  n[5        WU5      nM     [        W5      (       d8  [        R                  " [        S5      U[        R                  " U5      4-  5      eU R9                  [        S5      U[        R                  " U5      4-  5        [:        R<                  " 5       n U" SXUS.[        R>                  " U5      D6n [:        R<                  " 5       U-
  nU RI                  SSU[        R                  " U5      U5        U(       aF  U(       a"  [        RJ                  " [        S5      U-  5      eU R1                  [        S5      U-  5        US4$ ! [(        [*        4 GaK    [        R,                  " 5       n ['        S[        R                  " U	5      -  5      n GN! [(        [*        4 a    [        R,                  " 5       nU R.                  (       a  U R1                  [        S5      5        U R3                  U5        U R.                  (       a  U R1                  [        S5      5        U R3                  U5        U R.                  (       d  [        S5      nOSn[        S	5      nU[        R                  " U5      [        R                  " U	5      4-  n[        R                  " UUS
9ef = ff = f! , (       d  f       GN= f! [6         a9    [        R                  " [        S5      U[        R                  " U5      4-  5      ef = f! [@         Ga  n[C        U[        RD                  5      (       a-  U R1                  [        S5      UURF                  S   4-  5        O3U R1                  [        S5      U[        R                  " U5      4-  5        U(       a  e U R.                  (       d  U R1                  [        S5      5        U R3                  5          SnA[:        R<                  " 5       U-
  nU RI                  SSU[        R                  " U5      U5        gSnAff = f! [:        R<                  " 5       U-
  nU RI                  SSU[        R                  " U5      U5        f = f)a  call python hook. hook is callable object, looked up as
name in python module. if callable returns "true", hook
fails, else passes. if hook raises exception, treated as
hook failure. exception propagates if throw is "true".

reason for "true" meaning "hook failed" is so that
unmodified commands (e.g. mercurial.commands.update) can
be run as hooks without wrappers to convert return values..s(   %s hook is invalid: "%s" not in a moduleNzhgext_%ss,   exception from first failed import attempt:
s-   exception from second failed import attempt:
s$   run with --traceback for stack traces)   %s hook is invalid: import of "%s" failedhintr   s'   %s hook is invalid: "%s" is not defineds(   %s hook is invalid: "%s" is not callables   calling hook %s: %s
)uirepohooktypes   error: %s hook failed: %s
r   s'   error: %s hook raised an exception: %s
s'   (run with --traceback for stack trace)
s
   pythonhooks,   pythonhook-%s: %s finished in %0.2f seconds
)TTs   %s hook faileds   warning: %s hook failed
F )&callable
__module____name__r
   sysstrrfindr   HookLoadErrorr   r   forcebytestrsyspathr   
mainfrozenossplitr   deactivated
__import__ImportErrorSyntaxErrorexc_infotracebackflagwarn	tracebackgetattrAttributeErrornoter   timer	strkwargs	Exception
isinstanceAbortargslog	HookAbort)r   r   htypehnamefuncnamer4   throwobjdmodnameoldpathsmodpathmodfilee1e2tracebackhintmsgp	starttimerexcdurations                         0/usr/lib/python3/dist-packages/mercurial/hook.py
pythonhookrK      s    >>C'#,,6??8,NN37%%=>*11(;<=  2A,88""$$!ww}}W5G788A;'2!%%'%G !9: (N 	^^C(,c1o - }}%%=>*11(;<= 
 GG	
"#uj.E.Eh.O&PP 

I
M25MH4F4Ft4LM  ::<)+
<##H-	
 	//!$5"6">??
./%78e8Ok  - #G\\^!G$Z(//'2J%JKC#[1 GB''!. LL$''!. LL$++()C) )-HIC"//6"//8 C  --cFF=G#G ('V  	%%<=*11(;<= 	$  c5;;''GGA458LLMGG=>*11#678 GGAABC
::<)+
<##H-	
! ::<)+
<##H-	
sp   +P)-K
 'P; R 
&P&1"LP)DP""P&&P))
P8;AQ>VCVV VV AWc                   [         R                  " 5       n0 nUbV  UR                  5       n	UR                  R	                  U	5        U	(       a$  U	R                  5       (       a  UR                  US'   X(S'   X8S'   U R                  SSU-  5      S:X  a  U R                  5       n
OU R                  SSU-  5      n
U
(       a  SUS'   OS	US'   UR                  5        Hj  u  pUS
:X  a  M  [        U5      (       a  U" 5       n[        U[        [        45      (       a  [        R                   " U5      nXSUR#                  5       -   '   Ml     U R                  SSU-  S5      (       a:  Un[$        R&                  " XH5      nXM:w  a  U R)                  [+        S5      U-  5        U R)                  [+        S5      X44-  5        U(       a  UR                  nO[,        R.                  " 5       nU R1                  XHUSU4-  S9nUb!  UR3                  5       c  UR5                  5         Ub!  UR7                  5       c  UR9                  5         [         R                  " 5       U-
  nU R;                  SSUUU5        U(       a`  [$        R<                  " U5      nU(       a$  [>        R@                  " [+        S5      UU4-  5      eU RC                  [+        S5      UU4-  5        U$ )Ns
   HG_PENDINGs   HG_HOOKTYPEs   HG_HOOKNAME   hookss   %s:run-with-plains   auto   1s   HGPLAIN    s   changess   HG_s   tonative.%sFs   converting hook "%s" to native
s   running hook %s: %s
s
   exthook-%s)environcwd
blockedtags   exthooks)   exthook-%s: %s finished in %0.2f seconds
s
   %s hook %ss   warning: %s hook %s
)"r   r/   currenttransactiondirstatewritewritependingrootconfigplain
configboolitemsr   r2   dictlistr   pprintupperr   shelltonativer.   r   r   getcwdsystemcurrentwlockinvalidatedirstatecurrentlock
invalidater5   explainexitr   r6   r*   )r   r   r7   namecmdr4   r:   rF   envtrrY   kvoldcmdrQ   rG   rI   descs                     rJ   _exthookrp      sm   

I
C $$&B"//##!%C	yy/$677B
h(<t(CDJJ

 
?A;;Aa$&&!!!$A"#FQWWY  
}}X~4e<<$$S.=GGA9:TABGGA&'4+56iioo
		#8O	PAD--/7!D,,.6zz|i'HFF5 	##A&//!M"2dD\"ABB
*+tTl:;HrO   c           
     8   [        U 5      n[        U SS9nUR                  5        H6  u  p4UR                  USSU[        45      nXE:w  d  M&  Uu  pgpXgU[        4X'   M8     [	        UR                  5       5       V
VVVs/ s H	  u  ppX4PM     snnnn
$ s  snnnn
f )z8return a list of (hook-id, cmd) pairs sorted by priorityT)
_untrustedr   )
_hookitemsr[   get_fromuntrustedsortedvalues)r   hooksuntrustedhooksrh   valuetrustedvaluelplolklvrE   orl   rm   s                 rJ   	_allhooksr      s    rNE  t4N%++-yyBn'EF +RR2~6EK	 . &,ELLN%;<%;zqQQF%;<<<s   >B
Fc                    0 nU R                  SUS9 Hb  u  p4UR                  S5      (       d  UR                  S5      (       d  SU;   a  M9  U R                  SSU-  S5      nU* 4[        U5      4X44X#'   Md     U$ )z)return all hooks items ready to be sortedrM   )	untrusteds	   priority.s	   tonative.   :s   priority.%sr   )configitems
startswith	configintlen)r   rr   rx   rh   ri   prioritys         rJ   rs   rs      s    E^^H
^C	OOL))|,,t|<<.4*?C!	|c%j]D> D LrO   c                    U q g )N)	_redirect)states    rJ   redirectr     s    IrO   c                    U R                   (       d  g[        U 5       H(  u  p#UR                  S5      S   U:X  d  M  U(       d  M(    g   g)z/return True if a hook is configured for 'htype'F   .r   T)	callhooksr   r#   )r   r7   r8   ri   s       rJ   hashookr     s>    <<m
;;tQ5(SS $ rO   c                   U R                   (       d  g/ n[        U 5       H:  u  pgUR                  S5      S   U:X  d  M  U(       d  M(  UR                  Xg45        M<     [	        XX%4SU0UD6nSn	U H  u  pgX   S   =(       d    U	n	M     U	$ )NFr   r   r:   )r   r   r#   appendrunhooks)
r   r   r7   r:   r4   rx   r8   ri   resrG   s
             rJ   hookr     s    <<Em
;;tQ5(SSLL%& $ 2U
?
?$
?CA
JqMQ HrO   c               #    #    Sn  [         (       a   [        R                  R                  5       n[        R                  R                  5       nUS:  aP  US:  aJ  [        R                  R                  5         [        R                  " U5      n [        R                  " X!5        Sv    [        R                  R                  5         [         (       aT  U S:  aM   [        R                  R                  5         [        R                  " U W5        [        R"                  " U 5        ggg! [        [        4 a     Nf = f! [         a]  nUR                  [        R                  [        R                  [        R                  4;  a  [        R                   " U5      e SnANSnAff = f! [         a^  nUR                  [        R                  [        R                  [        R                  4;  a  [        R                   " U5      e SnAGNSnAff = f!  [        R                  R                  5         Oj! [         a]  nUR                  [        R                  [        R                  [        R                  4;  a  [        R                   " U5      e SnAOSnAff = f[         (       a  U S:  a   [        R                  R                  5         Oj! [         a]  nUR                  [        R                  [        R                  [        R                  4;  a  [        R                   " U5      e SnAOSnAff = f[        R                  " U W5        [        R"                  " U 5        f f f = f7f)z(Redirects stdout to stderr, if possible.r   r   N)r   r   stdoutfilenostderrflushr"   dupdup2OSErrorr-   errnoEPIPEEIOEBADFr   
StdioErrorclose)	oldstdoutstdoutnostderrnoerrs       rJ   redirect_stdior   !  sb     I! 9
#??113#??113q=X]OO))+ "x 0IGGH/
 		,OO!!#
 9a0%%' GGIx(HHY (9! ^,   	,yyeii EE&&s++ F	,  099U[[%))U[[$II**3// J0	,OO!!# 	,yyeii EE&&s++ F	, 9a0%%' 099U[[%))U[[$II**3// J0 GGIx(HHY (9s   M+H BD' $H )D= M+F' 70M+'D:7H 9D::H =
F$AFM+F$$M+'
H1AH
M+
HM+M(H32M(3
J=AJM(JM(/KM(
L5AL0+M(0L553M((M+c                   [         R                  " U5      n0 n[        5          U GH  u  pxU[        L aT  U(       a*  [        R
                  " [        S5      U-  [        S5      S9eU R                  [        S5      U-  5        Sn	Sn
GO0[        U5      (       a  [        XX'XU5      u  pGOUR                  S5      (       a  UR                  S5      S	:  a  US
S  R                  SS5      u  p[        R                  " U5      nU(       a*  [        R                   R#                  UR$                  U5      n S[         R&                  " U5      -  n[(        R*                  " X5      n[1        U[         R&                  " U5      5      nOUS
S  R3                  5       n[        XX'XU5      u  pO[5        XX'XU5      n	Sn
X4Xg'   GM     S S S 5        U$ ! [,         a    U R/                  [        S5      U-  5        e f = f! , (       d  f       U$ = f)Ns   untrusted hook %s not executeds   see 'hg help config.trusted'r   s(   warning: untrusted hook %s not executed
r   Fs   python:r         z	hghook.%ss   loading %s hook failed:
)r
   byteskwargsr   ru   r   r6   r   r*   r   rK   r   countrsplitr   
expandpathr"   r    joinrW   r   r	   loadpathr1   rU   r,   striprp   )r   r   r7   rx   r:   r4   r   r8   ri   rG   raisedr    mod_namemodhookfns                  rJ   r   r   J  s   %D
C		JEn$//;<uD>?  FG%OP#&rs%P	6
++99T?a' #ABtQ 7ID??40D!ww||DIIt<#.1G#G(11$A %S(//#*>?F W]]_F&eF%	6 RuSFCJE   
J J % #?!@5!HI- 
	J Js%   DG95/G$AG9)G66G99
H)F) 
__future__r   
contextlibr   r"   r   i18nr    r   r   r   r	   r
   r   utilsr   r   r   rK   rp   objectru   r   rs   r   r   r   r   contextmanagerr   r   r   rO   rJ   <module>r      s    #   	 
   upAJ =   	
  %  % P)rO   