^c~ ddlZddlmZmZmZddlmZmZmZm Z m Z m Z ddl m Z mZe jr3ddlmZmZmZmZmZmZmZmZmZddlmZeeeeeeeeeeef sJe jZejZejZejZGdd Z d Z!d Z"Gd d Z#Gdde#Z$dZ%de%zZ&de%zZ'dZ(ee(Z)de)zZ*dZ+dZ,dZ-GddZ.dS)N)binhexnullrev)encodingerrorobsoletepycompatscmutilutil) repoviewutil stringutil) AnyCallableDictIterableListOptionalSetTupleUnion) localrepoc6eZdZdZdZdZdZdZdZdZ dS) BranchMapCachez8mapping of filtered views of repo with their branchcacheci|_dSN) _per_filterselfs 5/usr/lib/python3/dist-packages/mercurial/branchmap.py__init__zBranchMapCache.__init__DscP|||j|jSr) updatecacher filternamerrepos r __getitem__zBranchMapCache.__getitem__Gs& 00r"c|j}|j}|j||st |g}t|}|e||}|| |jj |j z }| fd|Dnt || | j dz|r|||s J||j|j<dS)zz-BranchMapCache.updatecache..bs/GG!A4F4FA4F4F4F4FGGr"r)start) changelogr%rgetvalidfor branchcachefromfile subsettablefilteredcopy filteredrevsextendrevsr+update) rr'clr%r; subsetnamesubset extrarevsr.s @r r$zBranchMapCache.updatecacheKs] ^_ !%%j11 >!6!6> ))$//F >%44J%z22f**,,",9BOK  GGGGyGGGGGGG%T** BGG&-!"3G44555  & MM$ % % %t$$00j000,2)))r"c,|j}|j|j}g}t}|D]<}||z }|D]2}|} || \} } | r||3=|rt fd|D} t|||| | |} dD]P}| |}| |r"| |j |<| |dSOdSdS)zReplace the branchmap cache for a repo with a branch mapping. This is likely only called during clone with a branch map from a remote. c3HK|]}t|VdSr)int)r,nodeclrevs r r/z)BranchMapCache.replace..s3@@3uuT{{++@@@@@@r") closednodes)sbases immutablesservedN) r1rev branchinfosetvaluesaddmaxr4rDr7r3rwrite)rr'remotebranchmapr= clbranchinforbheadsclosedbheadshr-bcrtiprevcache candidaterviewrEs @r replacezBranchMapCache.replacensl^} %,,.. " "F v G " "E!HH#|A1"JJqMMM  "  @@@@@@@AAGW ""$$" E@    i00>>%((27D$Y/KK&&&FF    r"c8|jdSr)rclearrs r r\zBranchMapCache.clears      r"c|}|jD]6\}}|jr*||}||7dSr) unfilteredritems_delayedr7rM)rr'unfir%rWs r write_delayedzBranchMapCache.write_delayedsl  !%!1!7!7!9!9 " " J~ "}}Z00 D!!! " "r"N) __name__ __module__ __qualname____doc__r!r(r$rZr\rbr"r rrAsvBB111!3!3!3F%%%N!!!"""""r"rcJtd|z)zEraises ValueError when branchcache found a node which does not existsznode %s does not exist) ValueErrorrrDs r _unknownnoderks - : ; ;;r"c(|j d|jzSdS)Nsbranch cache (%s)s branch cacher%)r's r _branchcachedescrns "#do55r"ceZdZdZddedddfdZdZdZdZdZ d Z d Z d Z d Z e Zd ZedZdZedZdZdZdZdZddZdZdZdZdZdZdS)r4a<A dict like object that hold branches heads cache. This cache is used to avoid costly computations to determine all the branch heads of a repo. The cache is serialized on disk in the following format: [optional filtered repo hex hash] ... The first line is used to check if the cache is still valid. If the branch cache is for a filtered repo view, an optional third hash is included that hashes the hashes of all filtered and obsolete revisions. The open/closed state is represented by a single letter 'o' or 'c'. This field can be used to avoid changelog reads when determining if a branch head closes a branch or not. rgNc0||_d|_| |j|_n||_||_||_|t |_n||_t||_ d|_ t |_ ||_ |j d|_ dSdS)zhasnode is a function which can be used to verify whether changelog has a given node or not. If it's not provided, we assume that every node we have exists in changelogFNcdS)NTrg)xs r z&branchcache.__init__..sdr") _repor`nullidtipnoder+ filteredhashrI _closednodesdict_entries_closedverified_verifiedbranches_hasnode)rr'entriesrvr+rwrFhasnodes r r!zbranchcache.__init__s  ?;DLL"DL (   #D   +D W  $!$ = *NDMMM ! r"c|jrdS|jD]&}||st|'d|_dS)zverify the closed nodes we haveNT)r{rxr}rk)rrDs r _verifyclosedzbranchcache._verifyclosedsU    F% # #D==&& #T"""#r"c||jvs ||jvrdS|j|D]&}||st|'|j|dS)z'verify head nodes for the given branch.N)rzr|r}rkrK)rbranchns r _verifybranchzbranchcache._verifybranchst  & &&D4J*J*J Fv&  A==## Q ""6*****r"ct|j|jz }|D]}||dS)z"verifies nodes of all the branchesN)rIrzkeysr|r)rneedverificationrTs r _verifyallzbranchcache._verifyallsVt}113344t7MM! " "A   q ! ! ! ! " "r"c*t|jSr)iterrzrs r __iter__zbranchcache.__iter__sDM"""r"c||j|<dSr)rz)rkeyvalues r __setitem__zbranchcache.__setitem__s" cr"cF|||j|Srrrzrrs r r(zbranchcache.__getitem__s# 3}S!!r"c>||||jvSrrrs r __contains__zbranchcache.__contains__ s# 3dm##r"c#~K|jD] \}}||||fV!dSr)rzr_r)rkvs r iteritemszbranchcache.iteritemssTM''))  DAq   q ! ! !Q$JJJJ  r"c>||||jvS)z2checks whether a branch of this name exists or notr)rlabels r hasbranchzbranchcache.hasbranchs# 5!!! %%r"cd} |||}t|}t|ddd}|dd\}}t |t|}}d}|jj }t|dkrt |d}||||||} | |std| ||n#ttf$rY|r|dSdSt"$rX} |jjr@d} |j| t+|t-j| fzd} Yd} ~ nd} ~ wwxYw|r|n#|r|wwxYw| S)N  )rvr+rwrz tip differssinvalid %s: %s )cachevfs _filenamernextrstripsplitrrCr1rlenr3riloadIOErrorOSErrorclose Exceptionui debugflagdebugrnr forcebytestr) clsr'flineitercachekeylastlrevrwrr.instmsgs r r5zbranchcache.fromfiles &  cmmD1122AAwwHH~~,,U3399$BBH!"1"JD$TCII$DLn,G8}}q  "8A;// S) F??4(( 0 /// KKh ' ' ' '!          w  ) (.."/55FFFFFF       s=DDGF*.G F*AF% G%F**GGc|D]}|d}|s|dd\}}}|dvrtdtj|}t |}|j|g ||dkr|j |dS)z[fully loads the branchcache by reading from the file using the line iterator passedrrrsoczinvalid branch statecN) rrrirtolocalstriprrz setdefaultappendrxrK)rr'rlinerDstaters r rzbranchcache.loadIs , ,D;;u%%D !%D!!4!4 D%E!! !7888$U[[]]33Et99D M $ $UB / / 6 6t < < <}}!%%d+++ , ,r"c0d}|jr d||jfz}|S)z7name of a branchcache file for a given repo or repoviewsbranch2s%s-%srm)r'filenames r rzbranchcache._filenameYs) ? >8T_"==Hr"c |j|j}n#t$rYdSwxYw|j|krdSt j||jd}|j|kS)zcheck that cache contents are valid for (a subset of) this repo - False when the order of changesets changed or if we detect a strip. - True when cache is up-to-date for the current repo or its subset.FT needobsolete)r1rDr+ IndexErrorrvr rw)rr'rDtiphashs r r3zbranchcache.validforas  >&&t{33DD   55  <4  5&tT[tLLL G++s " 00c`|d}d}t|D]}||jvr|}d}n||fS)zhReturn tuple with last open head in heads and false, otherwise return last closed head and true.TF)reversedrx)rheadstiprQrSs r _branchtipzbranchcache._branchtipvsUBi%  A)))*F{r"cD|||dS)zReturn the tipmost open head on branch head, otherwise return the tipmost closed head on branch. Raise KeyError for unknown branch.r)r)rrs r branchtipzbranchcache.branchtipstF|,,Q//r"c fd|DS)Nc3.K|]}|jv |VdSr)rx)r,rrs r r/z'branchcache.iteropen..s0??aAT->$>$>$>$>$>$>??r"rg)rnodess` r iteropenzbranchcache.iteropens????5????r"Fc|||j|}|s"t||}|Sr)rrzlistr)rrrQrs r branchheadszbranchcache.branchheadssH 6""" f% /u--..E r"c#vK|D]!\}}||f||zV"dSr)r_r)rbnrs r iterbrancheszbranchcache.iterbranchessO 7 7IBu+ 6 66 6 6 6 6 7 7r"c\||jS)zreturns all the heads)rrzrJrs r iterheadszbranchcache.iterheadss& }##%%%r"cxt||j|j|j|j|j|jS)z-return an deep copy of the branchcache object)typertrzrvr+rwrxrs r r8zbranchcache.copys<tDzz J M L K        r"c |}t|dds d|_dS ||}||dd5}t |jd|jzg}|j'| t |j| d |dzd}t|j D]Y\}}tj|}|D]=} |d z }| |jvrd } nd } | d t | | |fz>Z dddn #1swxYwY|jd dt)|t+|j |d|_dS#t,t.t0jf$r:} |jdt7j| zYd} ~ dSd} ~ wwxYw)N finalizedTw) atomictemps%drrrrros %s %s %s branchcaches%wrote %s with %d labels and %d nodes Fs couldn't write branch cache: %s )currenttransactiongetattrr`rrrrvr+rwrrMjoinsortedrzr_r fromlocalrxrlogrnrrrrAbortrrr) rr'trrrr nodecountrrrDrrs r rMzbranchcache.writes  $ $ & &r;-- !DM F ~~d++Hx$?? K1 --ut{/BC$0OOC(9$:$:;;; (++e3444 $*4=+>+>+@+@$A$AKKLE5$.u55E %KK!Q 4#444$(EE$(E TE50I IJJJJ KK  K K K K K K K K K K K K K K K GKK9 &&DM""    "DMMM%+.    GMM4)$//0          s=-F5C:E$ F5$E((F5+E(,AF55H /HH ctj}|ji}|j}|D]h}||\}}||g||r-|j |i|j } d} | jj } tj|d} |D]8\}} |j|g}fd|D}t%}t'| D]?}|| vr|s|| d| |D}t%}t%}t%}|D]`}|| vr||||vs||d|kr||K||at)|t)|cxkrdks,n||||||||A|rr| !t%} || z rJt1|}|t3|kr(t%||}||z}|rfdt'|D||<t3| }|| kr|} :| |j kr!| |_  | |_||sy|j|_t<|_ |D]L}|st3fd|D}||j kr! ||_||_ MtAj!||j d |_!tj|z }|j"#d d tI|||%|dS) zGiven a branchhead cache, self, that may have extra nodes or be missing heads, and a generator of nodes that are strictly a superset of heads missing, this function updates self to be correct. Nsobsoletec:h|]}|SrgrGr,rDr=s r z%branchcache.update..s#888t 888r"c(g|]}|tk |Srg)r)r,ps r z&branchcache.update..sIIIALL1LLLr"rrc:g|]}|Srgrj)r,rGr=s r rz&branchcache.update..=s#III IIIr"c3BK|]}|VdSrrrs r r/z%branchcache.update..Rs-<>11$' Y(I(I$J$J  I- JIIIIx8H8HIIIV %%F  T[ !DK777++DL}}T"" ) ;DL!DK)) ) )<<<4sI@ilcleZdZdZddZdZejdZdZ dZ dZ d Z dd Z d Zd Zd S)raPersistent cache, mapping from revision number to branch name and close. This is a low level cache, independent of filtering. Branch names are stored in rbc-names in internal encoding separated by 0. rbc-names is append-only, and each branch name is only stored once and will thus have a unique index. The branch info for each revision is stored in rbc-revs as constant size records. The whole file is read into memory, but it is only 'parsed' on demand. The file is usually append-only but will be truncated if repo modification is detected. The record for each revision contains the first 4 bytes of the corresponding node hash, and the record is only used if it still matches. Even a completely trashed rbc-revs fill thus still give the right result while converging towards full recovery ... assuming no incorrectly matching node hashes. The record also contains 4 bytes where 31 bits contains the index of the branch and the last bit indicate that it is a branch close commit. The usage pattern for rbc-revs is thus somewhat similar to 00changelog.i and will grow with it but be 1/8th of its size. TcB|jJ||_g|_t|_d|_ |jt}t||_|r$d| dD|_n%#ttf$r|r |j |_YnwxYw|jrz |jt}||jdd<nM#ttf$r9}|jdt#j|zYd}~nd}~wwxYwt't|jt(zt|j|_|jdkrg|_t|j|_dS)Nrc6g|]}tj|Srg)rr)r,rs r rz+revbranchcache.__init__..s0-/H$R((r"s(couldn't read revision branch cache: %s )r%rt_names bytearray_rbcrevs _rbcsnameslenrread _rbcnamesrrrr _branchinforHrrrrr _rbcrecsizer1 _rbcrevslen_rbcnamescount)rr'readonlybndatadatars r r!zrevbranchcache.__init__s&&&  !   3]'' 22F!$VD  39<<3F3F ! 3 3 3 3"&"2 3 ;  }))(33#' aaa  W%    @ -d334     + -s4>/B/B    q DK!$+..s*AB B/.B/:+C&&D07/D++D0cd|_|jdd=d|_t|jj|_t|jtz|_ tj |ddS)Nrs _namesreverse) rrr$rrtr1r#rr"rr clearcachedpropertyrs r _clearzrevbranchcache._clearse KNtz344!$"2["@AA   '788888r"c>dt|jDS)Nci|]\}}|| Srgrg)r,r-rTs r z0revbranchcache._namesreverse..s888A1888r") enumeraterrs r _namesreversezrevbranchcache._namesreverses 884;!7!78888r"cL|jj}|tz}|tkr||St |j|tzkr||S||dt}tttj |j|\}}t|tz}|r |t z}|dkrn||krS |j||fS#t$$r6|jjd|YnTwxYw|jjd|z|tz}|j|d=t-|j||_||S)zWReturn branch name and close flag for rev, using and updating persistent cache.NssRreferenced branch names not found - rebuilding revision branch cache from scratch sPhistory modification detected - truncating revision branch cache to revision %d )rtr1r"rrHrrr!rD _rbcnodelen unpack_from _rbcrecfmtr bufferbool _rbccloseflag_rbcbranchidxmaskrrrrr*rr#) rrGr1 rbcrevidxreponode cachenode branchidxrtruncates r rHzrevbranchcache.branchinfosJ( +%  '>>'',, , t}   K 7 7 7##C(( (>>#&&| |4*  DM22I   9Y.//  + * *I  # #  ( " " {9-u44    ##J   JM  :>D $$$s/C>>=D>=D>c`|jj}||\}}||jvr|j|}n8t |j}|j|||j|<||}|r |tz}| |||||fS)z7Retrieve branch info from changelog and update _rbcrevs) rtr1rHr/rrrrDr6 _setcachedata)rrGr1rTrr;r9s r r!zrevbranchcache._branchinfosJ( '',,5 " " "*1-IIDK((I K  q ! ! !$-D q !>>#&&  '  &I 3)444%xr"cb|j\}}||jvr|j|}n8t|j}|j|||j|<|r |t z}|||jj ||dt|vr|`dSdS)z%add new data information to the cacherHN) rHr/rrrr6r>rtr1rDvars)rrGchangelogrevisionrrr;s r setdatazrevbranchcache.setdatas)4  T' ' '*62IIDK((I K  v & & &)2D v &  '  &I 3 4 9 9# > > JJJ 4:: % % & %r"c|tkrdS|tz}|tz}t|j}||kr0|jdt t |ztt|j|||t|j ||_ |j }|r| d|jdSdS)z:Writes the node's branch data to the in-memory cache data.Nrswrite-revbranchcache)rr"rrr:rL _rbcmininc pack_intor3rr#rtr addfinalizerM)rrGrDr;r8 requiredsizerbccurrs r r>zrevbranchcache._setcachedatas '>> F+%  ;. T]## L M Z)F)F!F G G G*dmYiHHHt/55 Z * * , ,  @ NN2DJ ? ? ? ? ? @ @r"Nc|j}d}d} |jt|jkr-|d}d}|||jtz}|t|jkr0d}||d}| ||ne#tttj tjf$r;}|jd|t#j|fzYd}~nd}~wwxYw||dSdS#||wwxYw)z!Save branch cache if it is dirty.Nr"F)waits namess+couldn't write revision branch cache%s: %s )rtr$rrwlock _writenamesr#r"r _writerevsrrrr LockErrorrrrrrelease)rrr'rKstepr0rs r rMzrevbranchcache.write+shz "S%5%555  ..   &&&${2EDM****= JJEJ22Ee,,,%+u?    GMM?06678            ! u  !s0B!B/.D./'D1D D. DD..Ec|jdkr|jtd}||jkr|dnD||j dtzd|_d|_ |jdkrA|j td|jtd}|d d|j|jd D||_|t|j|_d S) z,write the new branch names to revbranchcacherabrs%s changed - rewriting it T) ignoremissingswbc3>K|]}tj|VdSr)rr)r,rTs r r/z-revbranchcache._writenames..XsA"1%%r"N)r$ropenr tellrrMrrrr# unlinkpathrrrr)rr'rs r rLzrevbranchcache._writenamesHsO  ! # # ""9e44Avvxx4---  rMrLrMrgr"r rrzs,!/!/!/!/H999 999-%-%-%^    ,@@@*    :///2     r"r)/structrDrrrrrr r r r utilsr r TYPE_CHECKINGtypingrrrrrrrrrranyr6calcsizerEr2rrkrnr4r _rbcversionr rr3r"rDr1r7r6rrgr"r rds                           3                & ?    \"\"\"\"\"\"\"\"~<<< vvvvvvvvr          ; &  $  hz"" +    v v v v v v v v v v r"