
    q&f                         d dl mZmZmZmZmZmZ ddlmZm	Z	  G d d      Z
d Zd Zdd	Zd
 Z	 ddZddZd Zd Zy)    )contextdagop
extensionshgwebpatchutil   )r   revmapc                   L    e Zd ZdZd Zd Zd Zej                  d        Z	d Z
y)	_lazyfctxz<delegates to fctx but do not construct fctx when unnecessaryc                 .    || _         || _        || _        y N)_node_path_repo)selfreponodepaths       </usr/lib/python3/dist-packages/hgext/fastannotate/support.py__init__z_lazyfctx.__init__   s    


    c                     | j                   S r   )r   r   s    r   r   z_lazyfctx.node        zzr   c                     | j                   S r   )r   r   s    r   r   z_lazyfctx.path#   r   r   c                 l    t        j                  | j                  | j                  | j                        S r   )r   resolvefctxr   r   r   r   s    r   _fctxz_lazyfctx._fctx&   s#    ""4::tzz4::FFr   c                 .    t        | j                  |      S r   )getattrr   )r   names     r   __getattr__z_lazyfctx.__getattr__*   s    tzz4((r   N)__name__
__module____qualname____doc__r   r   r   r   propertycacher   r#    r   r   r   r      s5    F
 
G G)r   r   c                     g }i }t         j                  }t        |      D ]L  \  }\  }}}	||	f|vrt        | ||	      |||	f<   |dz   }
|||	f   }||   }|j	                   |||
|             N |S )z7convert fastannotate outputs to vanilla annotate formatr	   )fctxlinenotext)r   annotateline	enumerater   append)r   	annotatedcontentsresultsfctxmapr.   ihshlinenumr   r,   r+   lines                r   _convertoutputsr9   .   s     GG%%L#,Y#7 JC$;g%#,T3#=GS$K 1T{#{|f4HIJ Nr   c                 V    | j                   j                  j                  dd      xs dS )z(fctx) -> strs   fastannotates
   mainbranchs   default)r   uiconfig)r+   s    r   
_getmasterr=   @   s"    ::==?M:Mr   Nc                    t        |       }t        j                  | ||      5 }	 |j                  | j	                         |dd      \  }}ddd       rsJ t        | j                  ||      S # t
        $ r{ |j                          | j                  j                  j                  d| j                  z         	 |j                  | j	                         |dd      \  }}n# t
        $ r  w xY wY w xY w# 1 sw Y   xY w)zlike the vanilla fctx.annotate, but do it via fastannotate, and make
    the output format compatible with the vanilla fctx.annotate.
    may raise Exception, and always return line numbers.
    T)mastershowpath	showliness*   fastannotate: %s: rebuilding broken cache
N)r=   r   fctxannotatecontextannotaterev	Exceptionrebuildr   r;   debugr   r9   )r+   followdiffoptsr?   acr1   r2   s          r   _doannotaterK   E   s   
 F		$	$T68	< 	"$++
6DD #. #Ix" !!4::y(;;  
	JJLJJMM>K&(kkHHJv '2 '#	8   $
	 sA   C7&A00AC4<&C#"C4#C..C41C73C44C77D c                 N    t        j                  |ddd      }t        ||      S )NTs   annotate)	untrustedsection
whitespace)rI   )r   difffeatureoptsrK   )origr+   r;   rI   s       r   _hgwebannotaterR   a   s*    $$
dKDH th//r   c                     |r | |||||      S 	 t        |||      S # t        $ r>}|j                  j                  j	                  d|z          | ||||      cY d }~S d }~ww xY w)N)skiprevsrI   s7   fastannotate: falling back to the vanilla annotate: %r
)rH   rT   rI   )rK   rE   r   r;   rG   )rQ   r   rH   
linenumberrT   rI   exs          r   _fctxannotaterW   h   sw     &*x(
 	
O422 O

G"L	
 D(XNN	Os    	A%3A A% A%c                     t        j                  |||      5 }t        j                  |j                        }d d d         | ||||      S # 1 sw Y   xY w)N)rT   rI   prefetchskip)r   rB   r
   
revmappath)rQ   r   rH   rT   rI   rJ   skipsets          r   _remotefctxannotater\   y   sU    		$	$T68	< /--./fx( / /s    AAc                  V    t        j                  t        j                  dt               y NrC   )r   wrapfunctionr   webutilrR   r)   r   r   replacehgwebannotatera      s    EMM:~Fr   c                  V    t        j                  t        j                  dt               y r^   )r   r_   	hgcontextbasefilectxrW   r)   r   r   replacefctxannotatere      s    I11:}Mr   )TN)FFNN)FNN)	mercurialr   rc   r   r   r   r   r    r
   r   r9   r=   rK   rR   rW   r\   ra   re   r)   r   r   <module>rh      sQ    ) ),$N
<80 IMO"GNr   