
    6hvL                       S SK Jr  S SKrS SKrS SKrS SKJrJrJr  S SK	J
r
JrJrJrJr  SSKJr  \R"                  (       a  S SKJr  \R&                  rSr " S	 S
\R*                  5      r " S S\R.                  \5      rg)    )annotationsN)binhexnullrev)ancestorcontexterrorphasesutil   )shallowutil)Iteratorg      ?c                     ^  \ rS rSr     SU 4S jjrS r\S 5       rSS jrS r	\S 5       r
S rS	 rS
 rS rS rS rSS jrS rS rSSS jjrS rU 4S jrS rSrU =r$ )remotefilectx!   c                   > U[         :X  a  UR                  nU(       a  [        U5      S:X  a  [        U5      n[        TU ]  XX4XV5        Xpl        g )N(   )r   nullidlenr   super__init___ancestormap)	selfrepopathchangeidfileidfilelog	changectxancestormap	__class__s	           C/usr/lib/python3/dist-packages/hgext/remotefilelog/remotefilectx.pyr   remotefilectx.__init__"   sD     W[[Fc&kR'[FXwJ'    c                L    U R                   R                  U R                  5      $ N)_filelogsize	_filenoder   s    r"   r(   remotefilectx.size3   s    }}!!$..11r$   c                   SU R                   ;   a  U R                  $ SU R                   ;   a  U R                  R                  5       $ SU R                   ;   ao  U R	                  U R
                  U R                  U R                  U R                  5      nU R                  R                  5       R                  R                  U5      $ U R                  5       $ )N	_changeid
_changectx_descendantrev)__dict__r-   r.   rev_adjustlinknode_pathr'   r)   r/   _repo
unfiltered	changeloglinkrev)r   linknodes     r"   r-   remotefilectx._changeid6   s    $--'>>!T]]*??&&((. ++

DMM4>>4;N;NH ::((*4488BB<<>!r$   c                X    [        U R                  U R                  UU R                  US9$ )zEopens an arbitrary revision of the file without
opening a new filelog)r   r   r   )r   r4   r3   r'   )r   r   r   s      r"   filectxremotefilectx.filectxF   s,     JJJJMM
 	
r$   c                    U R                   $ r&   )_linkrevr*   s    r"   r7   remotefilectx.linkrevQ   s    }}r$   c                   U R                   U R                  R                  :X  a  [        $ U R	                  5       nXR                      u  p#pEU R                  R
                  R                  R                  U5      nUb  U$ U R                  nU R                   nU R                  R                  5       R
                  n	U R                  R                  n
[        [        U	5      S-
  SS5       H[  nU	R                  U5      nU	R                  U5      nX|S   ;   d  M/  XS      R                  SS9nXR!                  U5      :X  d  MY  Us  $    g )Nr   r      Fexact)r)   r4   r   r   r    r6   indexget_revr3   r5   manifestlogranger   nodereadread_delta_parentsget)r   r    p1p2r8   copyfromr1   r   r   clmflrI   datams                 r"   r>   remotefilectx._linkrevT   s   >>TZZ...N&&(%0%@"jj""((00:?J zzZZ""$..jj$$R1a,C773<D77D Aw QL33%3@UU4[(J -" r$   c                f   U R                  5       n[        U 5      nSU;   =(       d    SU;   (       + nU(       d  U R                  5       U:X  a  U$ U R                  U R                  U R
                  U R                  U R                  5       SS9nU R                  R                  R                  U5      $ )aO  return the rev of the changeset which introduced this file revision

This method is different from linkrev because it take into account the
changeset the filectx was created from. It ensures the returned
revision is one of its ancestors. This prevents bugs from
'linkrev-shadowing' when a file revision is used by multiple
changesets.
r-   r.   T	inclusive)	r7   varsr1   r2   r3   r'   r)   r4   r6   )r   lkrattrsnoctxr8   s        r"   introrevremotefilectx.introrevx   s     llnT
 E)C]e-CDDHHJ#%J''JJMMNNHHJ ( 
 zz##''11r$   c                   U R                  5       nXR                     u  p#pEU(       d  gXR4nU R                  5       U R                  5       :X  a  U$ U R	                  5       nU R                  nU R
                  R                  5        H  n	 XR                  U5      :X  a    gM     U$ ! [        R                   a     M7  f = f)a  check if file was actually renamed in this changeset revision

If rename logged in file revision, we report copy for changeset only
if file revisions linkrev points back to the changeset in question
or both changeset parents contain different file revisions.
N)
r    r)   r1   r7   r   r.   parentsfilenoder	   LookupError)
r   r    rM   rN   r8   rO   renamednamefnodeps
             r"   rb   remotefilectx.renamed   s     &&(%0%@".88:'Nyy{((*AJJt,, - +  $$ s   B''B?>B?c                >    U R                  5       nU=(       a    US   $ )Nr   )rb   )r   copys     r"   
copysourceremotefilectx.copysource   s    ||~Qr$   c                    U R                   (       d.  U R                  5       R                  U R                  5      U l         U R                   $ r&   )r   r   r    r)   r*   s    r"   r    remotefilectx.ancestormap   s4       $ : :4>> JD   r$   c                   U R                   nU R                  5       nX R                     u  p4pV/ nX1R                  :w  aW  U=(       d    U R                  nUR                  U5      n	[        XX9US9n
U R                  5       U
l        UR                  U
5        XAR                  :w  aN  U R                  nUR                  U5      n	[        XXIUS9nU R                  5       Ul        UR                  U5        U$ )N)r   r   r    )
r4   r    r)   r   r3   filer   r1   r/   append)r   r   r    rM   rN   r8   rO   resultsr   flogp1ctxp2ctxs               r"   r_   remotefilectx.parents   s    zz&&(%0%@")tzzD99T?D!2E $(88:E NN5!::D99T?D!2E $(88:E NN5!r$   c                    UR                  U5      nUS   US   pXH;   a6  X7   R                  SS9n	XYR                  U5      :X  a  UR                  U5      $ g)zBreturns the node for <path> in <ancrev> if content matches <fnode>r   rB   FrC   N)rJ   rK   rL   rI   )
r   ancrevrP   rQ   r   rd   ancctxmanifestnodefilesrS   s
             r"   _nodefromancrevremotefilectx._nodefromancrev   sZ    $Qie =!4454AAd#wwv&r$   c           
        U R                   nUR                  5       R                  nUR                  nU R	                  5       n	X   S   n
Uc=  U R                   S   R                  5        Vs/ s H  oR                  5       PM     nnSnOU/nU R                  X5      (       a  U
$ SR                  U Vs/ s H  n[        UR                  U5      5      PM     sn5      [        U5      U[        R                  " UR                  5      [        R                  " UR                  5      S.nUR                  R                  " S0 UD6  UR                   nSnUR#                  XS9nU Hl  nU R%                  UXxX5      nUb  Us  $ U(       a  M&  UR'                  UU5      [(        R*                  :X  d  ML  U R-                  XaX<U5      nU(       a  Us  $ SnMn     U
$ s  snf s  snf )	a  return the first ancestor of <srcrev> introducing <fnode>

If the linkrev of the file revision does not point to an ancestor of
srcrev, we'll walk down the ancestors until we find one introducing
this file revision.

:repo: a localrepository object (used to access changelog and manifest)
:path: the file path
:fnode: the nodeid of the file revision
:filelog: the filelog of this path
:srcrev: the changeset revision we search ancestors from
:inclusive: if true, the src revision will also be checked

Note: This is based on adjustlinkrev in core, but it's quite different.

adjustlinkrev depends on the fact that the linkrev is the bottom most
node, and uses that as a stopping point for the ancestor traversal. We
can't do that here because the linknode is not guaranteed to be the
bottom most one.

In our code here, we actually know what a bunch of potential ancestor
linknodes are, so instead of stopping the cheap-ancestor-traversal when
we get to a linkrev, we stop when we see any of the known linknodes.
   NT    )revsrd   filepathuserreponameFrV   )   linkrevfixups   adjusting linknode
)r4   r5   r6   rG   r    r_   r1   _verifylinknodejoinr   rI   r   getusernameuigetreponamelog_phasecache	ancestorsrz   phaser
   public_forceprefetch)r   r   r   rd   srcrevrW   r   rP   rQ   r    r8   re   r   r1   commonlogkwargspc
seenpubliciterancrv   lnodes                       r"   r2   remotefilectx._adjustlinknode   s   2 zz__((&&(%a(>%)ZZ%5%=%=%?@%?EEG%?D@I8D//O IIDADSs2773<0DABZ++DGG4#//8
 	PP
,,t,9F(($FE 
 :"((4"8FMM"I ++_  L!
% ( S A Bs   ,G4$Gc                &   Sn[         R                   " 5       n UR                  R                  U[        U5      4/SS9  S U l        U R                  5       U   S   nU R                  XH5      (       aB  SnU[         R                   " 5       U-
  n	UR                  R                  " SUS-   4SU	S	-  0UD6  $ S
n [         R                   " 5       U-
  n	UR                  R                  " SUS-   4SU	S	-  0UD6  g ! [         aM  n
SU
-  n S n
A
[         R                   " 5       U-
  n	UR                  R                  " SUS-   4SU	S	-  0UD6  g S n
A
ff = f! [         R                   " 5       U-
  n	UR                  R                  " SUS-   4SU	S	-  0UD6  f = f)Nr$   T)forcer}   s#   remotefilelog prefetching succeededr      
elapsedi  s#   remotefilelog prefetching not founds%   remotefilelog prefetching failed (%s))
timefileserviceprefetchr   r   r    r   r   r   	Exception)r   r   r   rd   r   r   logmsgstartr8   r   es              r"   r   remotefilectx._forceprefetch&  s   T 			%%c%j'9&:$%G
 !%D'')%03H##D33? iikE)GGGKK  $ "	 <F
 iikE)GGGKK  $ "	  	=AFiikE)GGGKK  $ "		 iikE)GGGKK  $ "	s1   AC6 4C6 6
E EE EE A Fc                   ^^ U(       d  g U R                   R                  5       R                  m[        UU4S jU 5       5      $ ! [        R
                   a     gf = f)a  
Check if a linknode is correct one for the current history.

That is, return True if the linkrev is the ancestor of any of the
passed in revs, otherwise return False.

`revs` is a list that usually has one element -- usually the wdir parent
or the user-passed rev we're looking back from. It may contain two revs
when there is a merge going on, or zero revs when a root node with no
parents is being created.
Fc              3  f   >#    U  H&  nTR                  TTR                  U5      5      v   M(     g 7fr&   )
isancestorrI   ).0rrP   r8   s     r"   	<genexpr>0remotefilectx._verifylinknode.<locals>.<genexpr>|  s'     IDqr}}Xrwwqz::Ds   .1)r4   r5   r6   anyr	   ra   )r   r   r8   rP   s     `@r"   r   remotefilectx._verifylinknodek  sS     		&&(22BIDIII   	
 	s   9A AAc              #    #    / n[         R                  " U 45      n[        5       nU(       a  UR                  5       nUR	                  5       U;   a  M-  UR                  UR	                  5       5        UR                  U5        UR                  5       nSnU H$  nU(       d  U(       d  UR                  U5        SnM&     U(       a  M  UR                  S5        [        USS S9nU S h  vN   g  N7f)NTFr   c                "    U R                  5       $ r&   )r7   )xs    r"   <lambda>)remotefilectx.ancestors.<locals>.<lambda>  s
    !))+r$   )reversekey)	collectionsdequesetpopr`   addro   r_   sorted)	r   followfirstr   queueseencurrentr_   firstre   s	            r"   r   remotefilectx.ancestors  s     	!!4'*uiikG!T)HHW%%'(W%oo'GELLO  e  	a 9d8MN	s   CC2"C2*C0+C2c                  ^
^ UR                  5       U R                  5       :X  a&  U R                  5       U;   a  X R                  5          $ U R                  5       U;   a&  UR                  5       U;  a  X R                  5          $ UR                  5       U;   a&  U R                  5       U;  a  X!R                  5          $ U R                  5       m
UR                  5       mU
U4S jnU R                  5       U R                  5       4nUR                  5       UR                  5       4n[        R                  " XEU5      nU(       a  Uu  px[        U R                  XxT
S9n	U	$ g )Nc                   > U u  pTR                  U5      =(       d    TR                  U5      nU(       d  / $ US   =(       d    UUS   4XS   4/$ )NrB   r   r   )rL   )r   fnre   amapbmaps       r"   r_   'remotefilectx.ancestor.<locals>.parents  sN    DA*txx{A	qTYQ!%Q4y11r$   )r   r    )r   r    r`   r   genericancestorr   r4   )r   fc2actxr_   abresultr   r   r   r   r   s             @@r"   r   remotefilectx.ancestor  s   88:$)<		$$ 99;$388:T#9		$$88:$))+T"9
## ! 	2 YY[$--/*XXZ())!8DAdjj!4HAHr$   c           	     *  > U nUR                  SS 5      nU(       ad  U R                  5       nU R                  5       U:w  a@  [        U R                  U R
                  UU R                  U R                  U R                  S9n/ n[        5       n[        R                  " U45      nUR                  UR                  5       5        U(       a  UR                  5       n	U	R                  5       U R                  5       :w  a8  UR                  U	R!                  5       [#        U	R                  5       5      45        U(       a  X;   a  M  U	R%                  5        HI  n
U
R                  5       U;  d  M  UR                  U
R                  5       5        UR                  U
5        MK     U(       a  M  U R                  R&                  R)                  S[+        U5      -  5        U(       a%  U R                  R,                  R/                  U5        [0        TU ]d  " U0 UD6$ )Nprefetchskip)r   r   r   r    s1   remotefilelog: prefetching %d files for annotate
)r   r\   r1   r   r4   r3   r)   r'   r   r   r   r   r   rI   r`   ro   r   r   r_   r   debugr   r   r   r   annotate)r   argskwargsintroctxr   r\   fetchr   r   r   parentr!   s              r"   r   remotefilectx.annotate  s   zz.$7}}HxxzX%(JJJJ%>> MM $ 1 1 u!!8+.!iikG!T]]_4 gllnc'2B2B2D.EFG 7!//+;;=,HHV[[]+LL( , e 	

 #E
+	
 JJ""++E2w000r$   c                    / $ r&    r*   s    r"   childrenremotefilectx.children  s    	r$   r   )NNNNNr&   )F)returnzIterator[remotefilectx])__name__
__module____qualname____firstlineno__r   r(   propertycacher-   r;   r7   r>   r\   rb   ri   r    r_   rz   r2   r   r   r   r   r   r   __static_attributes____classcell__r!   s   @r"   r   r   !   s    
 ("2 " "	
 ! !F2.6 !4
JXCJ28 D)1X r$   r   c                  8   ^  \ rS rSrSU 4S jjrS rS rSrU =r$ )remoteworkingfilectxi  c                4   > S U l         [        TU ]	  XX45        g r&   )r   r   r   )r   r   r   r   
workingctxr!   s        r"   r   remoteworkingfilectx.__init__  s     W9r$   c                ,    [         R                  U 5      $ r&   )r   r_   r*   s    r"   r_   remoteworkingfilectx.parents  s    $$T**r$   c                   U R                   (       Gd  U R                  nU R                  R                  nU R	                  5       nU(       a  UnO3XS   R
                  R                  XR                  R                  5      4nXR                  R                  4n[        U5      S:  a3  XS   R
                  R                  XR                  R                  5      4n0 nUS   U R                  R                  :w  aQ  U R                  R                  US   US   S9nUR                  UR                  5       R                  US   5      5        US   U R                  R                  :w  aQ  U R                  R                  US   US   S9nUR                  UR                  5       R                  US   5      5        Sn	U(       a  US   n	US   US   U R                  R                  U	4US '   X`l         U R                   $ )Nr   r   )r   r$   )r   r3   r.   _parentsrb   	_manifestrL   r4   r   r   r;   updater   r    )
r   r   pclrb   rM   rN   rS   rr   rs   rO   s
             r"   r     remoteworkingfilectx.ancestormap  s      ::D//**CllnGF,,00zz7H7HIJ

))*B3x!|F,,00zz7H7HIJA!u

)))

**2a5A*?44RU;<!u

)))

**2a5A*?44RU;<H"1:!ubeTZZ%6%6AAdG !   r$   r   )NN)	r   r   r   r   r   r_   r    r   r   r   s   @r"   r   r     s    :+! !r$   r   )
__future__r   r   r   typingmercurial.noder   r   r   	mercurialr   r   r	   r
   r    r   TYPE_CHECKINGr   r   FASTLOG_TIMEOUT_IN_SECSr;   r   workingfilectxr   r   r$   r"   <module>r      sp    #    , ,  	 "" NGOO Nb&!711= &!r$   