
    q&f/                         d dl Z d dlZd dlZd dlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZmZmZ d Zd Z e       Zd Zdd
Zd	ad Zd ZddZe j6                  d        ZddZy)    N   )_)demandimportencodingerror
extensionspycompatutil)procutilresourceutil
stringutilc           
          t        |      r |}|j                  dz   |j                  z   }nt        j                  |      }|j                  d      }|dk(  r6t        j                  t        d      |t        j                  |      fz        |d| }	t        j                  }
t        j                         rHt        j                  j!                  |	      \  }}|r$|r"t        j                  dd |gz   t        _        |}	t#        j$                         5  	 t'        t        j                  |	            }ddd       |
t        _        	 |j!                  d      dd D ]  }t5        |      } 	 t              s6t        j                  t        d      |t        j                  |      fz        | j9                  t        d      |t        j                  |      fz         t;        j<                         }	  |d| ||dt        j>                  |      }	 t;        j<                         |z
  }| jI                  dd|t        j                  |      |       |r@|r!t        jJ                  t        d      |z        | j1                  t        d      |z         |dfS # t(        t*        f$ r9 t        j,                         }	 t'        dt        j                  |	      z        }n# t(        t*        f$ r t        j,                         }| j.                  r| j1                  t        d             | j3                  |       | j.                  r| j1                  t        d             | j3                  |       | j.                  st        d      }nd}t        d	      }|t        j                  |      t        j                  |	      fz  }t        j                  ||
      w xY wY w xY w# 1 sw Y   xY w# t6        $ r7 t        j                  t        d      |t        j                  |      fz        w xY w# t@        $ r}tC        |t        jD                        r-| j1                  t        d      ||jF                  d   fz         n2| j1                  t        d      |t        j                  |      fz         |r | j.                  s| j1                  t        d             | j3                          Y d}~t;        j<                         |z
  }| jI                  dd|t        j                  |      |       yd}~ww xY w# t;        j<                         |z
  }| jI                  dd|t        j                  |      |       w xY w)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funcnamer3   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
pythonhookrJ      s    >>C'#,,6??8,NN37%%=>*11(;<=  2A,88""$!ww}}W5GW788A;'2!%%' &	G%G !9:&	GN 	^^C(, &c1o& }%%=>*11(;<= 
 GG	
"#uj.E.Eh.O&PP 

I
M2D5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&	G &	GV  	%%<=*11(;<= 	$  c5;;'GGA458LLMGG=>*11#678 GGAABC
::<)+
<##H-	
! ::<)+
<##H-	
s|   O%J%O2 4P5 $O">!K O" C;OO"O%!O""O%%O/2A P25	T9>B2T40T< 4T99T< <AU=c                 F   t        j                         }i }|L|j                         }	|j                  j	                  |	       |	r|	j                         r|j                  |d<   ||d<   ||d<   | j                  dd|z        dk(  r| j                         }
n| j                  dd|z        }
|
rd|d<   nd	|d<   |j                         D ]^  \  }}|d
k(  rt        |      r |       }t        |t        t        f      rt        j                   |      }||d|j#                         z   <   ` | j                  dd|z  d      r:|}t%        j&                  ||      }||k7  r| j)                  t+        d      |z         | j)                  t+        d      ||fz         |r|j                  }nt-        j.                         }| j1                  |||d|fz        }| |j3                         |j5                          | |j7                         |j9                          t        j                         |z
  }| j;                  dd|||       |rYt%        j<                  |      }|r#t?        j@                  t+        d      ||fz        | jC                  t+        d      ||fz         |S )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   r1   dictlistr   pprintupperr   shelltonativer-   r   r   getcwdsystemcurrentwlockinvalidatedirstatecurrentlock
invalidater4   explainexitr   r5   r)   )r   r   r6   namecmdr3   r9   rE   envtrrX   kvoldcmdrP   rF   rH   descs                     rI   _exthookro      sw   

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

 	$1 
?A;Aa$&!!!$A"#FQWWY	$ 
}}X~4e<$$S#.&=GGA9:TABGGA&'4+56iioo
		#s8O	PAD--/7!D,,.6zz|i'HFF5 	##A&//!M"2dD\"ABB
*+tTl:;HrN   c           
      B   t        |       }t        | d      }|j                         D ]9  \  }}|j                  |dd|t        f      }||k7  s&|\  }}}}	|||t        f||<   ; t	        |j                               D 
cg c]  \  }
}}}||f c}}}}
S c c}}}}
w )z8return a list of (hook-id, cmd) pairs sorted by priorityT)
_untrustedr   )
_hookitemsrZ   get_fromuntrustedsortedvalues)r   hooksuntrustedhooksrg   valuetrustedvaluelplolklvrD   ork   rl   s                 rI   	_allhooksr      s    rNE  t4N%++- 7eyyBn'EFL +RRr2~6E$K	7 &,ELLN%;<<zq!QQF<<<s   B
Fc                     i }| j                  d|      D ]W  \  }}|j                  d      s|j                  d      sd|v r-| j                  dd|z  d      }| ft        |      f||f||<   Y |S )z)return all hooks items ready to be sortedrL   )	untrusteds	   priority.s	   tonative.   :s   priority.%sr   )configitems
startswith	configintlen)r   rq   rw   rg   rh   prioritys         rI   rr   rr      s    E^^H
^C 	?	cOOL)|,t|<<.4*?C!	|c%j]D#>d	? LrN   c                     | a y )N)	_redirect)states    rI   redirectr     s    IrN   c                 |    | j                   syt        |       D ]!  \  }}|j                  d      d   |k(  s|s! y y)z/return True if a hook is configured for 'htype'F   .r   T)	callhooksr   r"   )r   r6   r7   rh   s       rI   hashookr     sC    <<m 
s;;tQ5(S rN   c                     | j                   syg }t        |       D ]3  \  }}|j                  d      d   |k(  s|s!|j                  ||f       5 t	        | |||fd|i|}d}	|D ]  \  }}||   d   xs |	}	 |	S )NFr   r   r9   )r   r   r"   appendrunhooks)
r   r   r6   r9   r3   rw   r7   rh   resrF   s
             rI   hookr     s    <<Em '
s;;tQ5(SLL%&' 2tUE
?
?$
?CA 
sJqMQHrN   c               #     K   d} 	 t         r	 t        j                  j                         }t        j                  j                         }|dk\  rN|dk\  rIt        j                  j                          t        j                  |      } t        j                  ||       d 	 t        j                  j                          t         rQ| dk\  rK	 t        j                  j                          t        j                  |        t        j$                  |        yyy# t        t        f$ r Y w xY w# t        $ rZ}|j                  t        j                  t        j                  t        j                  fvrt!        j"                  |      Y d}~d}~ww xY w# t        $ r[}|j                  t        j                  t        j                  t        j                  fvrt!        j"                  |      Y d}~d}~ww xY w# 	 t        j                  j                          nf# t        $ rZ}|j                  t        j                  t        j                  t        j                  fvrt!        j"                  |      Y d}~nd}~ww xY wt         r| dk\  r	 t        j                  j                          nf# t        $ rZ}|j                  t        j                  t        j                  t        j                  fvrt!        j"                  |      Y d}~nd}~ww xY wt        j                  |        t        j$                  |        w w w xY ww)z(Redirects stdout to stderr, if possible.r   r   N)r   r   stdoutfilenostderrflushr!   dupdup2OSErrorr,   IOErrorerrnoEPIPEEIOEBADFr   
StdioErrorclose)	oldstdoutstdoutnostderrnoerrs       rI   redirect_stdior      s_     I! 
#??113#??113q=X]OO))+ "x 0IGGHh/
 		,OO!!#
 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	, a0%%' 099U[[%))U[[$II**3// J0 GGIx(HHY (9s   MG9 BD G9 !D, ?MF ).MD)&G9 (D))G9 ,	F5AF
M
FM	G6AG1+M1G66M9L?;HL?	I=#AI83L?8I==L?J+*L?+	L4AL	L?	L1L??Mc                    t        j                  |      }i }t               5  |D ]  \  }}|t        u rQ|r,t	        j
                  t        d      |z  t        d            | j                  t        d      |z         d}	d}
n)t        |      rt        | ||||||      \  }	}
n|j                  d      r|j                  d      d	k\  r|d
d  j                  dd      \  }}t        j                  |      }|r*t        j                   j#                  |j$                  |      }	 dt        j&                  |      z  }t)        j*                  ||      }t1        |t        j&                  |            }n|d
d  j3                         }t        | ||||||      \  }	}
nt5        | ||||||      }	d}
|	|
f||<    	 d d d        |S # t,        $ r | j/                  t        d      |z          w xY w# 1 sw Y   |S xY w)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   rt   r   r5   r   r)   r   rJ   r   countrsplitr
   
expandpathr!   r   joinrV   r   r   loadpathr0   rT   r+   stripro   )r   r   r6   rw   r9   r3   r   r7   rh   rF   raisedr   mod_namemodhookfns                  rI   r   r   I  s   %D
C		 ## "	#JE3n$//;<uD>?  FG%OP#&r4sD%P	6
+99T?a' #ABtQ 7ID#??40D!ww||DIIt<#.1G#G(11$A %S(//#*>?F W]]_F&eUFD%	6 RueS$FFCJE"	###J J % #?!@5!HI-##J Js%   DG.%.GA%G.(G++G..G8)F)
contextlibr   r!   r   i18nr    r   r   r   r   r	   r
   utilsr   r   r   rJ   ro   objectrt   r   rr   r   r   r   r   contextmanagerr   r   r   rN   rI   <module>r      s      	 
   upAJ =   	
  %  % P)rN   