
    6h+                    d    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J	r	J
r
   " S S5      rS rS rg)	    )annotationsN   )errorhgobsoletescmutilutilc                  B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)
repoloader   zLoad repositories in background thread

This is designed for a forking server. A cached repo cannot be obtained
until the server fork()s a worker and the loader thread stops.
c                    UR                  5       U l        [        R                  " US9U l        [
        R                  " US9U l        SU l        [        R                  " 5       U l        S U l        g )N)max)maxlenF)copy_uir	   lrucachedict_cachecollectionsdeque_inqueue
_accepting	threadingEvent	_newentry_thread)selfuir   s      5/usr/lib/python3/dist-packages/mercurial/repocache.py__init__repoloader.__init__   sQ    779''F3 $))8"*    c                    U R                   (       a   eU R                  R                  S:X  a  g SU l        [        R
                  " U R                  S9U l         U R                   R                  5         g )Nr   T)target)r   r   r   r   r   Thread	_mainloopstartr   s    r   r&   repoloader.start(   sQ    <<==1$ ''t~~>r!   c                   U R                   (       d  g SU l        U R                  R                  5         U R                   R	                  5         S U l         U R
                  R                  5         U R                  R                  5         g )NF)r   r   r   setjoinr   clearr   r'   s    r   stoprepoloader.stop1   sZ    ||r!   c                n    U R                   R                  U5        U R                  R                  5         g)z6Request to load the specified repository in backgroundN)r   appendr   r*   r   paths     r   loadrepoloader.load;   s$    T"r!   c                    U R                   (       a5  U R                   R                  5       (       a  [        R                  " S5      eU R                  R                  US5      $ )zReturn a cached repo if available

This function must be called after fork(), where the loader thread
is stopped. Otherwise, the returned repo might be updated by the
loader thread.
s0   cannot obtain cached repo while loader is activeN)r   is_aliver   ProgrammingErrorr   peekr1   s     r   getrepoloader.get@   sL     <<DLL1133((C  {{d++r!   c                  ^ ^ T R                   (       a  [        R                  " 5         T R                  R	                  5         T R                   (       an  T R                  R                  5          T R                  R                  5       m[        R                  " T R                  UU 4S j5        T R                   (       a  Mn  T R                   (       a  M  g g ! [         a     M"  f = f)Nc                 &   > TR                  T 5      $ N)_load)r2   r   s   r   <lambda>&repoloader._mainloop.<locals>.<lambda>]   s    DJJt4Dr!   )r   gccollectr   waitr,   r   popleft
IndexErrorr   	callcatchr   r1   s   `@r   r%   repoloader._mainloopM   s    oo JJLNN!//$$&==002D !!$((,DE /// ooo " s   /C 
C%$C%c                   [         R                  " 5       n U R                  R                  U5      n[        U5        UR                  R                  SSU[         R                  " 5       U-
  5        U R                  R                  X5        g ! [         a2    [
        R                  " U R                  U5      R                  5       n Nf = f)Ns	   repocaches&   loaded repo into cache: %s (in %.3fs)
)r	   timerr   popKeyErrorr   
repositoryr   
unfiltered_warmupcacher   loginsert)r   r2   r&   repos       r   r>   repoloader._load_   s    

	>;;??4(D 	T6JJL5 		
 	4&  	>==40;;=D	>s   B 9C	C	)r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r&   r-   r3   r9   r%   r>   __static_attributes__ r!   r   r   r      s+    
,F$'r!   r   c                   U R                  5         U R                    U R                  R                    U R                  R                    U R                  R
                    U R                  R                    [        R                   H  n[        R                  " X5        M     U R                  R                  X R                  R                  5       5        g r=   )invalidateall	changelogobsstore_all
successorspredecessorschildrenr   
cachefuncsgetrevs_phasecachephasetiprev)rQ   names     r   rN   rN   r   s    NNMMMMMMMM##$ $ 	4!6!6!89r!   c                n   UR                   nU R                   nSU;   a@  US   =US'   nUR                  =UR                  l        UR                  R                  l        SU;   a%  US   =US'   nUR                  UR                  l        SU;   a&  US   =US'   nUR                  UR                  l        gg)z/Copy cached attributes from srcrepo to destrepos	   changelogs   obsstores   _phasecacheN)
_filecachesvfsobjopener_inner)srcrepodestrepodestfilecachesrcfilecacheces        r   	copycachers      s    ''M%%L|#+7+EEl#b/7}}<,l"*6{*CCk"Rmm%-9.-IIn%  &r!   )
__future__r   r   rA   r    r   r   r   r   r	   r   rN   rs   rY   r!   r   <module>rv      s4    #  	  W' W'v
:&r!   