
    	^c-                         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 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 j        d             ZddZdS )    N   )_)getattr)demandimportencodingerror
extensionspycompatutil)procutilresourceutil
stringutilc           	      n
   t          |          r(|}t          j        |j        dz   |j        z             }n|                    d          }|dk    r&t          j        t          d          ||fz            |d|         }	t          j
        }
t          j                    rJt          j
                            |	          \  }}|r&|r$t          j
        dd         |gz   t          _
        |}	t          j                    5  	 t#          t          j        |	                    }n6# t&          t(          f$ r! t          j                    }	 t#          dt          j        |	          z            }n# t&          t(          f$ r t          j                    }| j        r"|                     t          d                     |                     |           | j        r"|                     t          d                     |                     |           | j        st          d	          }nd}t          j        t          d
          ||	fz  |          w xY wY nw xY wddd           n# 1 swxY w Y   |
t          _
        	 |                    d          dd         D ]}t3          ||          }n4# t4          $ r' t          j        t          d          ||fz            w xY wt          |          s&t          j        t          d          ||fz            |                     t          d          ||fz             t9          j                    }	  |d| ||dt          j        |          }n# t>          $ r }tA          |t          j!                  r3|                     t          d          ||j"        d         fz             n9|                     t          d          |tG          j$        |          fz             |r | j        s"|                     t          d                     |                                  Y d}~t9          j                    |z
  }| %                    dd|||           dS d}~ww xY w	 t9          j                    |z
  }| %                    dd|||           n4# t9          j                    |z
  }| %                    dd|||           w xY w|rK|r$t          j&        t          d          |z            |                     t          d          |z             |dfS )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 )'callabler
   sysbytes
__module____name__rfindr   HookLoadErrorr   syspathr   
mainfrozenossplitr   deactivated
__import__sysstrImportErrorSyntaxErrorexc_infotracebackflagwarn	tracebackr   AttributeErrornoter   timer	strkwargs	Exception
isinstanceAbortargsr   forcebytestrlog	HookAbort)r   r   htypehnamefuncnamer4   throwobjdmodnameoldpathsmodpathmodfilee1e2tracebackhintp	starttimerexcdurations                        0/usr/lib/python3/dist-packages/mercurial/hook.py
pythonhookrK      s     E$S^c%9CL%HIINN4  77%=>>(#$   2A2,8"$$ 	"!w}}W55GW "7 "8AAA;'2!%'' %	 %	$ !9!9::- " " "\^^ $Z(/'2J2J%JKKCC#[1   B' !.    LL$$$' !.    LL$$$+ -()C) ) )--FGG '*+*   3 C	"%	 %	 %	 %	 %	 %	 %	 %	 %	 %	 %	 %	 %	 %	 %	L 	^^D))!""- & &c1oo& 	 	 	%<==(#$  	
 }} 	%=>>(#$  
 GGA&''5(*;;<<<
I
CM2D5MMH4Ft4L4LMM   c5;'' 	GGA4558LLMMMMGG=>>*1#6678    	 	DGGAABBCCC
zzz:<<)+
<	
 	
 	
 	
 	
! 	
  :<<)+
<	
 	
 	
 	
 :<<)+
<	
 	
 	
 	
 	 9 	@/!$5"6"6">???
.//%7888e8Os   ?I&!D$"I&$%I
$E/.I/C"III&II&&I*-I*>0J/ /1K M3 1R2 3Q>>CQ9R2 9Q>>R2 21S#c                 >   t          j                    }i }|N|                                }	|j                            |	           |	r|	                                r
|j        |d<   ||d<   ||d<   |                     dd|z            dk    r|                                 }
n| 	                    dd|z            }
|
rd|d<   nd	|d<   |
                                D ]o\  }}|d
k    rt          |          r
 |            }t          |t          t          f          rt          j        |          }||d|                                z   <   p| 	                    dd|z  d          rB|}t%          j        ||          }||k    r%|                     t+          d          |z             |                     t+          d          ||fz             |r|j        }nt-          j                    }|                     |||d|fz            }t          j                    |z
  }|                     dd|||           |rct%          j        |          }|r&t7          j        t+          d          ||fz            |                     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   r2   dictlistr   pprintupperr   shelltonativer.   r   r   getcwdsystemr6   explainexitr   r7   r+   )r   r   r8   namecmdr4   r;   rF   envtrrY   kvoldcmdrQ   rG   rI   descs                     rJ   _exthookrl      s   
I
C $$&&B 	+"//## 	+!%CCC	yy/$6777BB

h(<t(CDD JJ

 	$ 	$1 
??A;; 	Aa$&& 	%!!$$A"#FQWWYY	}}X~4e<< C$S#..&==GGA9::TABBBGGA&''4+5666  io
		#s8O	PPAz||i'HFF5   	 <#A&& 	C/!M"2"2dD\"ABBB
*++tTl:;;;HrO   c                 @   t          |           }t          | d          }|                                D ]?\  }}|                    |dd|t          f          }||k    r|\  }}}}	|||t          f||<   @d t	          |                                          D             S )z8return a list of (hook-id, cmd) pairs sorted by priorityT)
_untrustedr   c                      g | ]\  }}}}||fS r   r   ).0rE   orh   ri   s        rJ   
<listcomp>z_allhooks.<locals>.<listcomp>   s$    <<<zq!QQF<<<rO   )
_hookitemsr[   get_fromuntrustedsortedvalues)
r   hooksuntrustedhooksrd   valuetrustedvaluelplolklvs
             rJ   	_allhooksr      s    rNNE  t444N%++-- 7 7eyyBn'EFFL  +RRr2~6E$K<<VELLNN%;%;<<<<rO   Fc                    i }|                      d|          D ]g\  }}|                    d          s|                    d          sd|v r4|                     dd|z  d          }| ft          |          f||f||<   h|S )z)return all hooks items ready to be sortedrM   )	untrusteds	   priority.s	   tonative.   :s   priority.%sr   )configitems
startswith	configintlen)r   rn   rx   rd   re   prioritys         rJ   rs   rs      s    E^^H
^CC 	? 	?	cOOL))	|,,	 t||<<.4*?CC!	|c%jj]D#>dLrO   c                 
    | a d S )N)	_redirect)states    rJ   redirectr      s    IIIrO   c                     | j         sdS t          |           D ])\  }}|                    d          d         |k    r|r dS *dS )z/return True if a hook is configured for 'htype'Fr   r   T)	callhooksr   r#   )r   r8   r9   re   s       rJ   hashookr      sX    < umm  
s;;tQ5((S(445rO   c                    | j         sdS g }t          |           D ]=\  }}|                    d          d         |k    r|r|                    ||f           >t	          | |||fd|i|}d}	|D ]\  }}||         d         p|	}	|	S )NFr   r   r;   )r   r   r#   appendrunhooks)
r   r   r8   r;   r4   rx   r9   re   resrG   s
             rJ   hookr     s    < uEmm ' '
s;;tQ5((S(LL%&&&
2tUE
?
?
?$
?
?CA  
sJqMQHrO   c               #     K   d} 	 t           r	 t          j                                        }t          j                                        }|dk    rM|dk    rGt          j                                         t          j        |          } t          j        ||           n# t          t          f$ r Y nw xY wdV  	 t          j                                         nU# t          $ rH}|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                                         nU# t          $ rH}|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        |            dS dS dS # 	 t          j                                         nU# t          $ rH}|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                                         nU# t          $ rH}|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)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       rJ   redirect_stdior     s*      I!  	
#?1133#?1133q==X]]O))+++ "x 0 0IGHh///^,    		,O!!#### 	, 	, 	,yei EEE&s+++ FEEEE	,  	 a0%%'''' 0 0 09U[%)U[$III*3/// JIIII0 GIx(((HY	  	 	,O!!#### 	, 	, 	,yei EEE&s+++ FEEEE	,  	 a0%%'''' 0 0 09U[%)U[$III*3/// JIIII0 GIx(((HY	 s   G BB G B2/G 1B22G :C 
D+#>D&&D+<E 
F-%>F((F-L!H ?L 
I
>ILIL#JL
K>K
LK/Lc                 2   t          j        |          }i }t                      5  |D ]\  }}|t          u r`|r3t	          j        t          d          |z  t          d                    |                     t          d          |z             d}	d}
n_t          |          rt          | ||||||          \  }	}
n6|
                    d          r	|                    d          d	k    r|d
d                              dd          \  }}t          j        |          }|r%t          j                            |j        |          }	 t'          j        |d|z            }n4# t*          $ r' |                     t          d          |z              w xY wt/          ||          }n|d
d                                          }t          | ||||||          \  }	}
nt3          | ||||||          }	d}
|	|
f||<   	 d d d            n# 1 swxY w Y   |S )Ns   untrusted hook %s not executeds   see 'hg help config.trusted'r   s(   warning: untrusted hook %s not executed
r   Fs   python:r         s	   hghook.%ss   loading %s hook failed:
)r
   byteskwargsr   ru   r   r7   r   r+   r   rK   r   countrsplitr   
expandpathr"   r    joinrW   r	   loadpathr1   rU   r   striprl   )r   r   r8   rx   r;   r4   r   r9   re   rG   raisedr    modhookfns                 rJ   r   r   A  s   %%D
C			 "# "# !	# !	#JE3n$$ /;<<uD>??    FGG%OPPP# &r4sD%PP	66
++ 99T??a'' #ABBtQ 7 7ID#?400D =!w||DIt<<(1$u8LMM$   #?!@!@5!HIII %S#..FF W]]__F&eUFD% 	66 RueS$FFFCJJC!	#"# "# "# "# "# "# "# "# "# "# "# "# "# "# "#H Js+   D&HE%$H%1FA)HHH)F)
contextlibr   r"   r   i18nr   r
   r    r   r   r   r	   r   utilsr   r   r   rK   rl   objectru   r   rs   r   r   r   r   contextmanagerr   r   r   rO   rJ   <module>r      s        				 



                                    q q qh< < <@ = = =      	  
       %  %  % P( ( ( ( ( (rO   