
    6hz                       S SK J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
  S SKJrJrJrJrJrJrJr  S SKJrJr  SSKJrJr  \R8                  S	 5       rSS
 jrS rS r \R8                  " \RB                  5      r"SS jr#S r$S r%\%" \RL                  5      r' " S S5      r(\(" 5       r& " S S5      r)S r* " S S5      r+\RX                  \&S4S j5       r-SS jr.g)    )annotationsN)_)binhexshort)errorlineloglockmdiffpycompatscmutilutil)hashutil
stringutil   )r   revmapc                $    U R                  U5      $ N)file)repopaths     </usr/lib/python3/dist-packages/hgext/fastannotate/context.py_getflogr   )   s    99T?    c                H   U R                     U R                  5       nU(       d5  U Vs/ s H(  o3R                  5       U R                  5       :X  d  M&  UPM*     nnU H>  nSUR                  ;  d  M  [	        U R
                  UR                  5       5      Ul        M@     U$ s  snf )N_filelog)	_changeidparentsr   __dict__r   _repor   )ffollowplps       r   _parentsr%   /   s|    
 KK	
B 4Avvx16683a4 QZZ'!!''16684AJ  I 5s   %BBc                    U R                  5       nUR                  S5      nU(       a  UR                  S5      (       d  US-  n[        U5       Vs/ s H  o0U4PM     snU4$ s  snf )N   
r   )datacountendswithrange)fctxtext	linecountis       r   	_decorater0   F   s[    99;D

5!IDMM%((Q	 %i 01 01AY 014881s   A#c                L    U H  u  u  p4pVnUS:X  d  M  U S   X4 US   XV& M     U$ )N   =r    )parentchildblocksa1a2b1b2ts           r   _pairr<   Q   s<    %! 9$Qi.E!HRO	  &
 Lr   Fc                r   U(       a$  [        U[        5      (       d  Ub  [        X5      nOX   nUc7  UR                  5       c  XR   nU$ U R	                  X%R                  5       S9n U$ XR   nUS:X  a  UR                  5       nOUR                  5       nXuR                  5       :w  a  Xvl        X   Ul        U$ )a  (repo, str, str) -> fctx

get the filectx object from repo, rev, path, in an efficient way.

if resolverev is True, "rev" is a revision specified by the revset
language, otherwise "rev" is a nodeid, or a revision number that can
be consumed by repo.__getitem__.

if adjustctx is not None, the returned fctx will point to a changeset
that introduces the change (last modified the file). if adjustctx
is 'linkrev', trust the linkrev and do not adjust it. this is noticeably
faster for big repos but is incorrect for some cases.
)changeid   linkrev)	
isinstanceint
_revsinglerevfilectxlinkrevintrorevr   
_changectx)r   rC   r   
resolverev	adjustctxctxr,   rF   s           r   resolvefctxrK   _   s     *S#..3?#i  7799D K <<wwy<9D K y
"||~H}}Hwwy %N"nDOKr   c                    U R                  SS5      R                  SS5      R                  SS5      R                  SS5      $ )	Ns   .hg/s   .hg.hg/s   .l/s   .l.hg/s   .m/s   .m.hg/s   .lock/s	   .lock.hg/)replacer   s    r   	encodedirrO      s9    Wj)		#		#	L	)	r   c                   ^  [         R                  " [        U 4S j[        R                  R
                   5       5      5      n[        [        R                  " U5      R                  5       5      S S $ )Nc              3  h   >#    U  H'  nU[        T[        R                  " U5      5      4v   M)     g 7fr   )getattrr   sysstr).0kdiffoptss     r   	<genexpr>hashdiffopts.<locals>.<genexpr>   s-      
, (//!"456,s   /2   )
r   pprintsortedr   rV   defaultsr   r   sha1digest)rV   
diffoptstrs   ` r   hashdiffoptsr`      sX    "" 
^^,,
 	
J x}}Z(//122A66r   c                  r    \ rS rSr% SrSSSS.rS\S'   S\S	'   S\S
'   S r\R                  SS j5       r
Srg)annotateopts   zlike mercurial.mdiff.diffopts, but is for annotate

followrename: follow renames, like "hg annotate -f"
followmerge: follow p2 of a merge changeset, otherwise p2 is ignored
NT)rV   followrenamefollowmergezmdiff.diffoptsrV   boolrd   re   c           	         U R                   R                  5        H   u  p#[        XUR                  X#5      5        M"     g r   )r\   itemssetattrget)selfoptsrU   vs       r   __init__annotateopts.__init__   s-    MM'')DADTXXa^, *r   c                2   SnU R                   (       d  US-  nU R                  (       d  US-  nU R                  bR  [        U R                  [        R                  5      (       d   e[        U R                  5      nU[        :w  a  USU-   -  nU=(       d    S$ )z?represent opts in a short string, suitable for a directory namer   s   r0s   m0   is   default)rd   re   rV   r@   r   r`   _defaultdiffopthash)rk   resultdiffopthashs      r   shortstrannotateopts.shortstr   s       eOFeOF==$dmmU^^<<<<&t}}5K11$,,##r   r3   )returnbytes)__name__
__module____qualname____firstlineno____doc__r\   __annotations__rn   r   propertycacheru   __static_attributes__r3   r   r   rb   rb      sL     H - 
$ $r   rb   c                     \ rS rSrSrS r\S 5       r\S 5       rS r	\	r
S r\S 5       rSS	 jrSS jrS rSS jrS rS rS rSS jrS r\SS j5       rSS jrS r\R6                  S 5       r\R6                  S 5       rSS jrSrg
)_annotatecontext   zsdo not use this class directly as it does not use lock to protect
writes. use "with annotatecontext(...)" instead.
c                    Xl         UR                  U l        X l        XPl        X0l        X@l        S U l        S U l        0 U l        g r   )	r   uir   rl   linelogpath
revmappath_linelog_revmap
_node2path)rk   r   r   r   r   rl   s         r   rn   _annotatecontext.__init__   s<    	''		&$r   c                    U R                   c  [        R                  R                  U R                  5      (       a^  [        U R                  S5       n [        R                  R                  UR                  5       5      U l         S S S 5        U R                   $ [        R                  " 5       U l         U R                   $ ! [        R                   a    [        R                  " 5       U l          Njf = f! , (       d  f       U R                   $ = f)Nrb)r   osr   existsr   open
linelogmodr	   fromdatareadLineLogErrorrk   r!   s     r   r	   _annotatecontext.linelog   s    == ww~~d..//$**D1Q=(2(:(:(C(CAFFH(M 2 }} !+ 2 2 4}}	 &22 =(2(:(:(<= 21 }}s*   C42C  .C1.C40C11C44
Dc                ~    U R                   c%  [        R                  " U R                  5      U l         U R                   $ r   )r   	revmapmodr   r   rk   s    r   r   _annotatecontext.revmap   s,    <<$++DOO<DL||r   c                <   U R                   b!  U R                   R                  5         S U l         U R                  bP  [        U R                  S5       nUR                  U R                  R                  5       5        S S S 5        S U l        g g ! , (       d  f       N= f)Nwb)r   flushr   r   r   writeencoder   s     r   close_annotatecontext.close   sp    <<#LL DL==$d&&-,,./ . DM %--s   *B
Bc                    U R                  5         U R                  R                  5         [        U R                  U R
                  /5        g)z0delete linelog and revmap, useful for rebuildingN)r   r   clear_unlinkpathsr   r   r   s    r   rebuild_annotatecontext.rebuild   s2    

doot'7'789r   c                    U R                   c   [        R                  " U R                  5      $ U R                   R	                  U R                   R
                  5      $ )z6return last node in revmap, or None if revmap is empty)r   r   getlastnoder   rev2hshmaxrevr   s    r   lastnode_annotatecontext.lastnode   sB     <<((99<<''(;(;<<r   c                *   U R                   n U R                  USS9nU R                  R                  R	                  UR                  5       5      nU(       d)  U(       a"  XS:w  a  U R                  R                  U5      SL$ XS:H  $ ! [         a     gf = f)a  return True if the revmap / linelog is up-to-date, or the file
does not exist in the master revision. False otherwise.

it tries to be fast and could return false negatives, because of the
use of linkrev instead of introrev.

useful for both server and client to decide whether to update
fastannotate cache or not.

if strict is True, even if fctx exists in the revmap, but is not the
last node, isuptodate will return False. it's good for performance - no
expensive check was done.

if strict is False, if fctx exists in the revmap, this function may
return True. this is useful for the client to skip downloading the
cache if the client's master is behind the server's.
T)rH   N)	r   _resolvefctxr   	changelognoderE   r   hsh2revLookupError)rk   masterstrictr   r!   linknodes         r   
isuptodate_annotatecontext.isuptodate  s    $ ==	!!&T!:A yy**//		<Hh8+? {{**84D@@ '' 		s   A2B B 
BBNc           
        [        U[        5      (       a.  [        U R                  R                  R                  U5      5      nU R                  U5      u  pVU(       au  U R                  R                  (       aH  U R                  R                  SU R                  [        R                  " [        US5      5      4-  5        U R                  XcU5      $ SnU(       a#   U R                  USSS9nXpR                   ;   a  SnU/nU(       aI  UR%                  5       c'  [&        R(                  " [+        S5      [+        S5      S9eUR-                  U5        USS n	0 n
US	0n0 nU	(       a  U	R/                  5       nX;   d  X;   a  M#  XR                   ;   ao  U R                   R1                  UR                  5       5      nU R2                  R5                  U5        U R2                  R6                  nXR9                  5       4X'   M  U R;                  U5      nUX'   U H4  nUR=                  US
5      S	-   UU'   UU
;  d  M#  U	R-                  U5        M6     U	(       a  M  [?        5       nUnU(       aL  XR                   ;  a=  URA                  U5        X   nU(       a  US
   nOSnOU(       a  XR                   ;  a  M=  Ub  U RC                  U5        U R                  R                  (       aj  U(       a4  U R                  R                  SU R                  [E        U5      4-  5        O/U(       d(  U R                  R                  SU R                  -  5        U R2                  R5                  U R2                  RF                  5        USS n	U R                  RI                  S[E        U5      S9nU	(       Ga  U	S   nX;   a  U	R/                  5         M$  SnX   nU H  nUU;  d  M  SnU	R-                  U5        M      U(       d  MW  U	R/                  5         SnUU;   nX;  d   e[K        U5      n[M        U5       Hg  u  nn[O        U RQ                  UU   S	   US	   5      5      nUS
:X  a	  U(       a  Un[S        UU   UU5      nUU   S	:X  a  UU	 UU	 MZ  UU==   S	-  ss'   Mi     UX'   X	 U(       av  URU                  5         Sn[E        U5      S:X  a   U RV                  RX                  (       a  US
   nUc  [O        U RQ                  SUS	   5      5      nU R[                  UUU5        O2U(       a+  UR                  5       U R\                  UR                  5       '   U	(       a  GM  UR_                  5         X   S
    VVs/ s HH  u  nn[        U[        5      (       a  U R                   Ra                  U5      OUR                  5       U4PMJ     nnnU Rc                  XX45      $ ! ["         a     GNf = fs  snnf )a  incrementally update the cache so it includes revisions in the main
branch till 'master'. and run annotate on 'rev', which may or may not be
included in the main branch.

if master is None, do not update linelog.

the first value returned is the annotate result, it is [(node, linenum)]
by default. [(node, linenum, path)] if showpath is True.

if showlines is True, a second value will be returned, it is a list of
corresponding line contents.
s6   fastannotate: %s: using fast path (resolved fctx: %s)
r   NTrH   rI   s   cannot update linelog to wdir()s   set fastannotate.mainbranch)hintr   r   s7   fastannotate: %s: %d new changesets in the main branch
sB   fastannotate: %s: linelog cannot help in annotating this revision
s   building cache)totalF   r   )2r@   rA   r   r   r   r   canannotatedirectlyr   	debugflagdebugr   r   rZ   hasattrannotatedirectlyr   r   r   rC   r   Abortr   appendpopr   r	   annotateannotateresultr(   _parentfuncrj   setadd_checklastmasterheadlenr   makeprogressr0   	enumeratelist_diffblocksr<   	incrementrl   re   
_appendrevr   completer   _refineannotateresult)rk   rC   r   showpath	showlinesdirectlyrevfctx
masterfctx	initvisitvisitpcacheneededhistr!   llrevrs   r#   r$   newmainbranchprogressreadyr6   ismainbranchcurrr/   bs
bannotatedfrls                                r   r   _annotatecontext.annotate*  sK   $ c3dii))..s34C !44S9ww  - 		"))''6*BC ((IFF 
&!..tt / 
 ,!%J0 I	~~'kk899:  Z(!1		A{aiKK++AFFH5%%e,44!668,!!!$BFI"JJq!,q0q	F?LLO  e& A[[(a BqE A[[( !%%a(77!$(IIs=/A#BC 248II> 	dll112 !77''S%7 ( 
 b	Ay		EBD=!ELLO  IIKF-L = =Q<D!"1$**471:tAw?@6lFT!WdB/!9>Qq	1INI & DG	""$!
r7a<DII$9$9!%aJ>!$"2"23Q"@AF6:6,-FFH)] e` 	 q)
)A *4B)<)<dkk!!"%"'')aP) 	 
 ))&8OOm  d
s   W 6AW+
W('W(c                   SnSn[        U[        5      (       dP  UbM  [        [        S.R	                  [        U5      S 5      " U5      nUb  X@R                  4U R                  ;   a  UnUc\  U R                  (       a  SOSnU R                  XSS9nX0R                  ;   nU(       d"  U R                  (       a  U R                  USSS9nX#4$ )z(str) -> bool, fctx or node.
return (True, f) if we can annotate without updating the linelog, pass
f to annotatedirectly.
return (False, f) if we need extra calculation. f is the fctx resolved
from rev.
TN)   (   c                    g r   r3   )xs    r   <lambda>6_annotatecontext.canannotatedirectly.<locals>.<lambda>  s    tr   r?   )rI   rH   )
r@   rA   rx   r   rj   r   r   r   	_perfhackr   )rk   rC   rs   r!   hshrI   s         r   r   $_annotatecontext.canannotatedirectly  s     #s###&**3s8^DSICC#3t{{#B9&*nn
$I!!#t!LA++%Fdnn %%cTd%Kyr   c                   U R                  USSS9nX@R                  ;  Ga-  U/nSn US   nU R                  U5      nU(       d  O=US   U R                  ;   a  US   R                  5       nOUR	                  US   5        M[  [
        R                  " 5       n	U	R                  U R                  5        U	R                  U	R                  5        [        R                  " 5       n
U
R                  U R                  5        [        U5       HA  nUR                  5       n[        U R                  Xk5      5      nU R                  XX|5        UnMC     OU R                  n	U R                  n
U	R                  5       nUR!                  5       nU
R#                  U5      nU VVs/ s H!  u  nnUU::  d  M  U
R%                  U5      U4PM#     nnnU(       a  U R'                  UU
5      nU(       a  U R)                  UX5      nUU4nU$ s  snnf )z(rev : str) -> [(node : str, linenum : int, path : str)]

the result has the same format with annotate, but include all (including
deleted) lines up to rev. call this after calling annotate(rev, ...) for
better performance and accuracy.
Tr   r   r   r   )r   r   r   r(   r   r   r	   copyfromr   r   r   reversedr   r   _doappendrevgetalllinesr   r   r   _addpathtoresult_resolvelines)rk   rC   r   r   r   chainar!   r#   r	   r   br6   linesr   r   rr   rs   linecontentss                       r   annotatealllines!_annotatecontext.annotatealllines  s    ##CDD#I ++%IEA"I%%a(a5DKK'1

ARU#  !((*GT\\*W^^,%%'FOODKK(e_FFHd..q45!!'1=	 % llG[[F##%llns#5:IUTQa5j(6>>!$a(UI **66:F--ffFLl+F Js   H .H c                   U Vs/ s H  oBR                  US   5      PM     nnS/[        U5      -  n[        R                  " [        5      n[        [        U5      5       H   nXuU   X   S   4   R                  U5        M"     U(       Ga3  Sn	 UR                  5        H;  u  u  pnUR                  U
5      [        R                  -  (       a  M1  XS      S   n	  O    U	c  0 nUR                  5        H  u  u  pnX;  a  XS      S   n	U R                  R                  (       a)  U R                  R                  S[        U	5      X4-  5        U R!                  XR#                  U
5      5      n[$        R&                  " UR)                  5       5      nUX'   U H  nX   U   UU'   M     M     [+        S U 5       5      (       d   eU$ U R                  R                  S[        U	5      -  5        UR-                  W
5        U R!                  XR#                  U
5      5      nUR.                  n[$        R&                  " UR)                  5       5      n[        U5      [        U5      :w  a  [0        R2                  " S5      e[5        U5       H'  u  nnUU   nUU;   d  M  UU    H  nUUU'   M
     UU	 M)     U(       a  GM3  U$ s  snf ! [         a    Us $ f = f)a@  (annotateresult) -> [line]. designed for annotatealllines.
this is probably the most inefficient code in the whole fastannotate
directory. but we have made a decision that the linelog does not
store line contents. so getting them requires random accesses to
the revlog data, since they can be many, it can be very slow.
r   Nr   s6   fastannotate: reading %s line #%d to resolve lines %r
c              3  (   #    U  H  oS Lv   M
     g 7fr   r3   )rT   r   s     r   rW   1_annotatecontext._resolvelines.<locals>.<genexpr>f  s     9&QD=&s   s+   fastannotate: annotate %s to resolve lines
s   unexpected annotated lines)r   r   collectionsdefaultdictr   r+   r   rh   rev2flagr   sidebranchflagStopIterationr   r   r   r   r   rev2pathr   splitnewlinesr(   allr   r   faerrorCorruptedFileErrorr   )rk   r   r   r	   r   revsrs   key2idxsr/   r   rC   _linenumidxsrevlineslinenumr,   r   idx	annotatedlinerU   s                        r   r   _annotatecontext._resolvelines;  s    /==nqt$n=#n--**40s6{#A1g~0345<<Q? $C-5^^-=)OSTs+i.F.FF (a1!4C	 .> { ,4NN,<(NSD*,!W5a877,, GGMM!9#(:w"=!>
  $00ooc6JK % 3 3DIIK @(-#&.mG&<s  $ -= 9&99999 GGMM?%*L S!$$S//#*>?D..I''		4E5zS^+001NOO$U+4aL='{&*s  +  ,W hb o > ! s   KAK K KKc                n   [        U[        5      (       a  UnOUR                  5       nU R                  R	                  U5      nU(       d"  [
        R                  " S[        U5      -  5      eU R                  R                  U5      [        R                  -  S:w  a"  [
        R                  " S[        U5      -  5      eU R                  R                  U5        U R                  R                   VVs/ s H"  u  pgU R                  R                  U5      U4PM$     nnnU R                  XX#5      $ s  snnf )zlike annotate, but when we know that f is in linelog.
f can be either a 20-char str (node) or a fctx. this is for perf - in
the best case, the user provides a node and we don't need to read the
filelog or construct any filecontext.
s   %s is not in revmapr   s   %s is not in revmap mainbranch)r@   rx   r   r   r   r  r  r   r  r   r	  r	   r   r   r   r   )	rk   r!   r   r   r   r   r   r   rs   s	            r   r   !_annotatecontext.annotatedirectly|  s     aC&&(C##C(,,-Cc#h-NOOKK  ')*B*BBqH,,1CH<  	e$48LL4O4O
4ODAT[[  #Q'4O 	 
 ))&XII
s   3)D1c                   U(       a  U R                  U5      nU(       a  [        U[        5      (       aF  U R                  R	                  U5      nU R                  X R                  R                  U5      5      nOUn[        R                  " UR                  5       5      n[        U5      [        U5      :w  a  [        R                  " 5       eX4nU$ )z^add the missing path or line contents, they can be expensive.
f could be either node or fctx.
)r   r@   rx   r   r   r   r  r   r  r(   r   r  r  )rk   rs   r!   r   r   r   r,   r   s           r   r   &_annotatecontext._refineannotateresult  s     **62F!U##++A.((KK,@,@,GH''		4E5zS[(0022_Fr   c                T    U R                  U R                  U R                  XU5        g r   )r   r	   r   )rk   r,   r6   r   s       r   r   _annotatecontext._appendrev  s    $,,T:Nr   c                X    [         R                  " XU R                  R                  5      $ r   )r   	allblocksrl   rV   )rk   r   r   s      r   r   _annotatecontext._diffblocks  s    qTYY%7%788r   c           
       ^ U4S jn/ n0 nUbJ  U HD  u  u  ppnUS:w  d  M  UXJU  VVs/ s H  u  p[        U[        5      (       a  M  UPM      snn-  nMF     [        U5      nX&;   a  UR                  U5        U H  nU" U5      X}'   M     TR	                  UR                  5       UR                  5       S9nXU'   [        U5       Hq  u  u  ppnUS:X  a  M  Uc  U R                  XXU5        M)  XJU  VVs/ s H$  u  nn[        U[        5      (       a  UOUU   U4PM&     nnnU R                  XU	U5        Ms     gs  snnf s  snnf )z'append a revision to linelog and revmapc                   > [        U [        5      (       a  [        R                  " S5      eU R	                  5       nTR                  U5      nUc  TR                  USU R                  5       S9nU$ )z(fctx) -> ints   f should not be an intT)
sidebranchr   )r@   rA   r   ProgrammingErrorr   r   r   r   )r!   r   rC   r   s      r   getllrev/_annotatecontext._doappendrev.<locals>.getllrev  sa     !S!!,,-FGG&&(C..%C{mmCDqvvxmHJr   Nr2   rN   )
r@   rA   r   remover   r   r   r   replacelinesreplacelines_vec)r	   r   r,   r6   r   r'  siderevs
siderevmapr7   r8   r9   r:   opr!   r   r   r   bliness    `                r   r   _annotatecontext._doappendrev  s`   
	 
!(.$ ":$."$5!$5DA)!S1 $5! H )/ x=OOD!A$QKJM  diik		< 4$,V$4 RRbTz!$$U; !+b 1 11 &a--a:a=1E 1   ((B? %5!*s   D>
	D>
8+Ec           	     |   ^ ^ Tc  T R                   mUU 4S jnU VVs/ s H  u  pEXEU" U5      4PM     snn$ s  snnf )z6(revmap, [(node, linenum)]) -> [(node, linenum, path)]c                   > TR                   R                  U 5      nUc/  TR                  TR                  U 5      5      nUTR                   U '   U$ r   )r   rj   r  r   )nodeidr   r   rk   s     r   _getpath3_annotatecontext._addpathtoresult.<locals>._getpath  sF    ??&&v.D|v~~f'=>*.'Kr   )r   )rk   r   r   r4  nr   s   ` `   r   r   !_annotatecontext._addpathtoresult  s;    >[[F	 1??x{#???s   8c                    Uc  SnOEU R                   R                  UR                  5       5      nU(       d  [        R                  " 5       eU R
                  R                  U:w  a  [        R                  " 5       eg)z:check if fctx is the master's head last time, raise if notNr   )r   r   r   r  CannotReuseErrorr	   r   )rk   r,   r   s      r   r   %_annotatecontext._checklastmasterhead  s^    <EKK''		4E..00<<%'**,, (r   c                p   ^^ U R                   R                  mU R                   R                  mUU4S jnU$ )z-> (fctx) -> [fctx]c                4   > [        U TS9nT(       d  US S nU$ )N)r"   r   )r%   )r!   r#   re   rd   s     r   r   -_annotatecontext._parentfunc.<locals>.parents  s"    !L1BVIr   )rl   rd   re   )rk   r   re   rd   s     @@r   r   _annotatecontext._parentfunc  s/     yy--ii++	 r   c                :    U R                   R                  SS5      $ )N   fastannotates   perfhack)r   
configboolr   s    r   r   _annotatecontext._perfhack  s    ww!!/;??r   c                V    [        U R                  X=(       d    U R                  40 UD6$ r   )rK   r   r   )rk   rC   r   kwdss       r   r   _annotatecontext._resolvefctx  s!    499c,=DIIG$GGr   )	r   r   r   r   rl   r   r   r   r   T)NFF)FFr   ) ry   rz   r{   r|   r}   rn   propertyr	   r   r   __del__r   r   r   r   r   r  r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r3   r   r   r   r      s    	 
 
  
! G: = =!F@PD.6p?BJ.$O9 /@ /@b@	- 
  
@ @Hr   r   c                f    U  H  n [         R                  " U5        M     g! [         a     M,  f = f)zsilent, best-effort unlinkN)r   unlinkOSError)pathsr   s     r   r   r     s1    	KK   		s   "
00c                  Z    \ rS rSrSr\4S jr\S 5       r\S 5       r	S r
\S 5       rSrg	)

pathhelperi  z9helper for getting paths for lockfile, linelog and revmapc                    [         R                  R                  SUR                  [	        U5      5      U l        Xl        g )Nr@  )r   r   joinru   rO   _vfspathr    )rk   r   r   rl   s       r   rn   pathhelper.__init__  s,    T]]IdO
 
r   c                    [         R                  R                  U R                  R                  R                  U R                  5      5      $ r   )r   r   dirnamer    vfsrQ  rR  r   s    r   rU  pathhelper.dirname  s,    wwtzz~~224==ABBr   c                f    U R                   R                  R                  U R                  S-   5      $ )Ns   .lr    rV  rQ  rR  r   s    r   r   pathhelper.linelogpath#  $    zz~~""4==5#899r   c                r    [         R                  " U R                  R                  U R                  S-   5      $ )Ns   .lock)lockmodr
   r    rV  rR  r   s    r   r
   pathhelper.lock'  s$    ||DJJNNDMMH,DEEr   c                f    U R                   R                  R                  U R                  S-   5      $ )Ns   .mrY  r   s    r   r   pathhelper.revmappath*  r[  r   )r    rR  N)ry   rz   r{   r|   r}   defaultoptsrn   rG  rU  r   r
   r   r   r3   r   r   rO  rO    sQ    C(3  C C : :F : :r   rO  c              #    #    [        XU5      n[        R                  " UR                  5        UR                  nUR
                  nSn UR                  5          [        XXeU5      nU(       a  UR                  5         Uv   SSS5        Ub  UR                  5         gg! , (       d  f       N#= f! [         a3    Ub  UR                  5         U R                  R                  SU-  5        e f = f! Ub  UR                  5         f f = f7f)a  context needed to perform (fast) annotate on a file

an annotatecontext of a single file consists of two structures: the
linelog and the revmap. this function takes care of locking. only 1
process is allowed to write that file's linelog and revmap at a time.

when something goes wrong, this function will assume the linelog and the
revmap are in a bad state, and remove them from disk.

use this function in the following way:

    with annotatecontext(...) as actx:
        actx. ....
Ns+   fastannotate: %s: cache broken and deleted
)rO  r   makedirsrU  r   r   r
   r   r   	Exceptionr   r   r   )r   r   rl   r   helperr   r   actxs           r   annotatecontextrg  /  s       D)FMM&..!""J$$KD[[]#DNDJ	  JJL  ]
  LLNELM	 JJL sN   AD

B1 )B B1 D
 
B.*B1 -C1 .B1 1=C..C1 1DD
c                    U R                   nU R                  nUR                  R                  SSS5      (       a  Sn[	        X!S9n[        XEXc5      $ )z\like annotatecontext but get the context from a fctx. convenient when
used in fctx.annotate
r@  s   forcefollowT)rV   rd   )r    _pathr   rA  rb   rg  )r,   r"   rV   r   r   r   aoptss          r   fctxannotatecontextrk  T  sK     ::D::Dww/>4@@(@E4u66r   rF  )FN)TNF)/
__future__r   r  
contextlibr   mercurial.i18nr   mercurial.noder   r   r   	mercurialr   r	   r   r
   r]  r   r   r   r   mercurial.utilsr   r    r  r   r   lrucachefuncr   r%   r0   r<   	revsinglerB   rK   rO   r`   ra  rr   rb   r   r   rO  contextmanagerrg  rk  r3   r   r   <module>rv     s    #   	  
  
  
.9 w001
)Z7 #5#4#45 "$ "$J nH HD: :4 %0% ! !H	7r   