
    	^c                     `    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dS )    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
d	S )

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                     |                                 | _        t          j        |          | _        t          j        |          | _        d| _        t          j
                    | _        d | _        d S )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__   s^    7799'F333 $)888"**    c                     | j         rJ | j        j        dk    rd S d| _        t	          j        | j                  | _         | j                                          d S )Nr   T)target)r   r   r   r   r   Thread	_mainloopstartr   s    r   r#   zrepoloader.start'   s]    <=1$$F 't~>>>r   c                     | j         sd S d| _        | j                                         | j                                          d | _         | j                                         | j                                         d S )NF)r   r   r   setjoinr   clearr   r$   s    r   stopzrepoloader.stop0   su    | 	Fr   c                 l    | j                             |           | j                                         dS )z6Request to load the specified repository in backgroundN)r   appendr   r&   r   paths     r   loadzrepoloader.load:   s2    T"""r   c                     | j         r-| j                                         rt          j        d          | 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?   sU     < 	DL1133 	(C   {d+++r   c                 b     j         rt          j                      j                                          j         ri j                                         	  j                                        n# t          $ r Y n)w xY wt          j
         j         fd            j         i j         d S d S )Nc                  .                                    S N)_load)r-   r   s   r   <lambda>z&repoloader._mainloop.<locals>.<lambda>\   s    DJJt4D4D r   )r   gccollectr   waitr(   r   popleft
IndexErrorr   	callcatchr   r,   s   `@r   r"   zrepoloader._mainloopL   s    o 	F JLLLN!!!/ F$$&&&=0022DD!   E!$(,D,D,D,D,DEEE / F o 	F 	F 	F 	F 	Fs   A1 1
A>=A>c                    t          j                    }	 | j                            |          }n<# t          $ r/ t          j        | j        |                                          }Y nw xY wt          |           |j
                            dd|t          j                    |z
             | j                            ||           d S )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((DD 	> 	> 	>=400;;==DDD	>T6JLL5 		
 	
 	
 	4&&&&&s   0 6A)(A)N)__name__
__module____qualname____doc__r   r#   r)   r.   r3   r"   r7    r   r   r
   r
      s                 
, , ,F F F$' ' ' ' 'r   r
   c                    |                                   | j         | j        j         | j        j         | j        j         | j        j         t          j        D ]}t          j	        | |           | j
                            |            d S r6   )invalidateall	changelogobsstore_all
successorspredecessorschildrenr   
cachefuncsgetrevs_phasecacheloadphaserevs)rH   names     r   rE   rE   q   s    NNMMMM# % %t$$$$""4(((((r   c                 
   |j         }| j         }d|v r*|d         x|d<   }|j        x|j        _        |j        _        d|v r|d         x|d<   }|j        |j        _        d|v r |d         x|d<   }|j        |j        _        dS dS )z/Copy cached attributes from srcrepo to destrepos	   changelogs   obsstores   _phasecacheN)
_filecachesvfsobjopener_realopener)srcrepodestrepodestfilecachesrcfilecacheces        r   	copycacherf   ~   s    'M%L|##+7+EEl#b-5]:*l""*6{*CCk"Rm%%-9.-IIn%  &%r   )r   r9   r    r   r   r   r   r   r
   rE   rf   rM   r   r   <module>rh      s        				                 W' W' W' W' W' W' W' W'v	) 	) 	)& & & & &r   