o ]Lb@sddlmZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZddlmZddlmZd d Zd d Zd dZddZddZddZddZejddZd!ddZddZddZdd Z dS)")absolute_importN)_)open)error extensionshgpycompatutilwireprotov1peerwireprotov1server)urlutil)contextcCs"|dd}|sttd|S)z)get the mainbranch, and enforce it is set fastannotates mainbranchsFfastannotate.mainbranch is required for both the client and the server)configrAbortr)uimasterr=/usr/lib/python3/dist-packages/hgext/fastannotate/protocol.py _getmasters rcCs|||}|d|S)N getannotate)append)origrepoprotoresultrrr _capabilities/s  rc Csld}|jddd}t||}|rUt|j}z7z ||s%|||Wn#tyI|z|||Wn tyF|YnwYnwW| n| w|j |kr|j |j fD]C}t j|siq`t|d } | } Wdn1s}wYt|jjd} || d} |d| t| | f7}q`Wd|SWd|S1swY|S)NrsserverbuildondemandTsrb/s%s%d%s)r configboolrannotatecontextr isuptodateannotate Exceptionrebuildcloselastnode revmappath linelogpathospathexistsrreadlenvfsbase) rrr+r'r buildondemandactxrpfcontent vfsbaselenrelpathrrr _getannotate5sP                r8cCs"dtjvrdStddtdS)Nrs path lastnode)r commandswireprotocommandr8rrrr_registerwireprotocommand`s  r;cCstttdtdS)Ns _capabilities)r;r wrapfunctionr rrrrr serveruisetuphsr>cCsi}d}t|d}d}d}}||kra|||d}|dkrH|dkrA||d|dt|||<|t|7}d}d}}n|dkrGd}n|dkrQ||7}n|dkrY||7}|d7}||ks|S)Nrr r)r.int)payloadrilstatevfspathsizechrrr_parseresponseps.     rHcs Gfddd|j}||_dS)Ncs eZdZejdfdd ZdS)z#peersetup..fastannotatepeerNcs2|dstddS||pdd}|tfS)Nrs*remote peer cannot provide annotate cache NNrspathslastnode)capablewarnrrH)selfr+r'argsr=rr getannotates z/peersetup..fastannotatepeer.getannotateN)__name__ __module__ __qualname__r batchablerOrr=rrfastannotatepeersrU __class__)rpeerrUrr=r peersetups rYccs\|j}|ddd}td|||}|d}t|i|}z |VW|dS|w)Nrs remotepathsdefaultr)rrr get_unique_pull_pathrrXr&)rr remotedestr remotepathrXrrr annotatepeersr^c Cs|sdS|dur#t|}t||||WdS1swY|dur)i}|j}g}|}|dt||D]}||d|||dq>|D]a}| } ddt | D} t | D]L} | drsd| d vr{|d | qf| | } |jr|d t| | f|jtj| || d  } | | Wdn1swYqfqRWddS1swYdS) z1download annotate cache from the server for pathsNs"fastannotate: requesting %d files rrJcSsi|] \}}t||qSr)r pconvert).0r3vrrr szclientfetch..s fastannotate/s/../rs(fastannotate: ignored malicious path %s s%fastannotate: writing %d bytes to %s swb)r^ clientfetchrcommandexecutordebugr.r callcommandgetrr iteritemssorted startswith debugflagr/makedirsr*r+dirnamewrite) rpaths lastnodemaprXrresultsbatcherr3rr\r+r5r4rrrrcsZ        "rcc Csj|jddd}|dkr|Sg}|D] }zt|||kr#||Wqty2||Yqw|S)zreturn a subset of paths whose history is long and need to fetch linelog from the server. works with remotefilelog and non-remotefilelog repos. rsclientfetchthreshold r)r configintr.filerr$)rro thresholdrr+rrr_filterfetchpathss  rwcCsGddd|j}||_dS)Nc@seZdZdddZdS)z(localreposetup..fastannotaterepoNc Sst|j}g}i}z>t||D])}t||}|j|dds)|||j||<Wdn1s3wYq|rEt||||WdSWdSt yb}z|j d|WYd}~dSd}~ww)NF)stricts"fastannotate: prefetch failed: %r ) rrrwrr!r"rr'rcr$re) rMrorXrneedupdatepathsrpr+r2exrrrprefetchfastannotates&   z=localreposetup..fastannotaterepo.prefetchfastannotaterP)rQrRrSr{rrrrfastannotatereposr|rV)rrr|rrrlocalreposetups r}cCs6t|r t||ttjvrtjtdSdSrP)r;localr}rYrwirepeersetupfuncsr)rrrrrclientreposetups   rrI)! __future__r contextlibr*mercurial.i18nrmercurial.pycompatr mercurialrrrrr r r mercurial.utilsr rrrr8r;r>rHrYcontextmanagerr^rcrwr}rrrrrs*   $ +  0