o ]Lb@sdddlmZddlZddlZddlZddlmZmZmZm Z m Z Gddde Z ddZ d d ZdS) )absolute_importN)errorhgobsoletescmutilutilc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) 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. cCs@||_tj|d|_tj|d|_d|_t |_ d|_ dS)N)max)maxlenF) copy_uir lrucachedict_cache collectionsdeque_inqueue _accepting threadingEvent _newentry_thread)selfuir r5/usr/lib/python3/dist-packages/mercurial/repocache.py__init__s   zrepoloader.__init__cCs>|jrJ|jjdkr dSd|_tj|jd|_|jdS)NrT)target)rrr rrThread _mainloopstartrrrrr (s  zrepoloader.startcCsB|jsdSd|_|j|jd|_|j|jdS)NF)rrrsetjoinrclearrr!rrrstop1s   zrepoloader.stopcCs|j||jdS)z6Request to load the specified repository in backgroundN)rappendrr"rpathrrrload;s zrepoloader.loadcCs(|jr |jr td|j|dS)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. s0cannot obtain cached repo while loader is activeN)ris_aliverProgrammingErrorrpeekr'rrrget@s zrepoloader.getcsvjr9tjjr4jzjWn ty$Ynwt j fddjsjsdSdS)Ncs SN)_loadrr(rrr]s z&repoloader._mainloop..) rgccollectrwaitr$rpopleft IndexErrorr callcatchr r!rr0rrMs   zrepoloader._mainloopcCsrt}z|j|}Wntyt|j|}Ynwt ||j dd|t||j ||dS)Ns repocaches&loaded repo into cache: %s (in %.3fs) ) rtimerrpopKeyErrorr repositoryr unfiltered _warmupcacherloginsert)rr(r reporrrr/_s  zrepoloader._loadN) __name__ __module__ __qualname____doc__rr r%r)r-rr/rrrrr s    r cCsV||j|jj|jj|jj|jjtjD]}t ||q|j |dSr.) invalidateall changelogobsstore_all successors predecessorschildrenr cachefuncsgetrevs _phasecache loadphaserevs)r@namerrrr=rs r=cCs|j}|j}d|vr|d|d<}|j|j_|j_d|vr,|d|d<}|j|j_d|vr?|d|d<}|j|j_dSdS)z/Copy cached attributes from srcrepo to destrepos changelogsobsstores _phasecacheN) _filecachesvfsobjopener _realopener)srcrepodestrepo destfilecache srcfilecachecerrr copycaches r[) __future__rrr2rrrrrrobjectr r=r[rrrrs  [