
    q&f                     X    d dl Z d dlZd dlZddlmZmZmZmZmZ  G d d      Z	d Z
d Zy)    N   )errorhgobsoletescmutilutilc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)

repoloaderzLoad 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                     |j                         | _        t        j                  |      | _        t        j                  |      | _        d| _        t        j                         | _        d | _        y )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__zrepoloader.__init__   sQ    779''F3 $))8"*    c                     | j                   rJ | j                  j                  dk(  ry d| _        t	        j
                  | j                        | _         | j                   j                          y )Nr   T)target)r   r   r   r   r   Thread	_mainloopstartr   s    r   r#   zrepoloader.start'   sQ    <<==1$ ''t~~>r   c                 
   | j                   sy d| _        | j                  j                          | j                   j	                          d | _         | j
                  j                          | j                  j                          y )NF)r   r   r   setjoinr   clearr   r$   s    r   stopzrepoloader.stop0   sZ    ||r   c                 n    | j                   j                  |       | j                  j                          y)z6Request to load the specified repository in backgroundN)r   appendr   r&   r   paths     r   loadzrepoloader.load:   s$    T"r   c                     | j                   r/| j                   j                         rt        j                  d      | j                  j                  |d      S )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   peekr,   s     r   getzrepoloader.get?   sI     <<DLL113((C  {{d++r   c                      j                   rt        j                           j                  j	                           j                   rf j                  j                          	  j                  j                         t        j                   j                   fd        j                   rf j                   ry y # t        $ r Y w xY w)Nc                  &    j                         S N)_load)r-   r   s   r   <lambda>z&repoloader._mainloop.<locals>.<lambda>\   s    DJJt4D r   )r   gccollectr   waitr(   r   popleft
IndexErrorr   	callcatchr   r,   s   `@r   r"   zrepoloader._mainloopL   s    oo JJLNN!//$$&==002D !!$((,DE // oo " s   $B> >	C
	C
c                    t        j                         }	 | j                  j                  |      }t        |       |j                  j                  dd|t        j                         |z
         | j                  j                  ||       y # t        $ r1 t        j                  | j                  |      j                         }Y w xY w)Ns	   repocaches&   loaded repo into cache: %s (in %.3fs)
)r   timerr   popKeyErrorr   
repositoryr   
unfiltered_warmupcacher   loginsert)r   r-   r#   repos       r   r7   zrepoloader._load^   s    

	>;;??4(D 	T6JJL5 		
 	4&  	>==40;;=D	>s   B 7CCN)__name__
__module____qualname____doc__r   r#   r)   r.   r3   r"   r7    r   r   r
   r
      s+    
,F$'r   r
   c                    | j                          | j                   | j                  j                   | j                  j                   | j                  j
                   | j                  j                   t        j                  D ]  }t        j                  | |        | j                  j                  | | j                  j                                y r6   )invalidateall	changelogobsstore_all
successorspredecessorschildrenr   
cachefuncsgetrevs_phasecachephasetiprev)rH   names     r   rE   rE   q   s    NNMMMMMMMM## %t$% 	4!6!6!89r   c                 b   |j                   }| j                   }d|v r@|d   x|d<   }|j                  x|j                  _        |j                  j                  _        d|v r%|d   x|d<   }|j                  |j                  _        d|v r&|d   x|d<   }|j                  |j                  _        yy)z/Copy cached attributes from srcrepo to destrepos	   changelogs   obsstores   _phasecacheN)
_filecachesvfsobjopener_inner)srcrepodestrepodestfilecachesrcfilecacheces        r   	copycacherg      s    ''M%%L|#+7+EEl#b/7}}<,l"*6{*CCk"Rmm%-9.-IIn%  &r   )r   r9   r    r   r   r   r   r   r
   rE   rg   rM   r   r   <module>ri      s1     	  W' W'v
:&r   