o ö]Lbã@sÐdZddlmZddlmZddlmZmZdZedZ dZ e dZ e e Z e dZ e d d Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„e d¡DƒZdd„Zdd„Zdd„Zdd„ZGd d!„d!eƒZd"S)#a3 A "pvec" is a changeset property based on the theory of vector clocks that can be compared to discover relatedness without consulting a graph. This can be useful for tasks like determining how a disconnected patch relates to a repository. Currently a pvec consist of 448 bits, of which 24 are 'depth' and the remainder are a bit vector. It is represented as a 70-character base85 string. Construction: - a root changeset has a depth of 0 and a bit vector based on its hash - a normal commit has a changeset where depth is increased by one and one bit vector bit is flipped based on its hash - a merge changeset pvec is constructed by copying changes from one pvec into the other to balance its depth Properties: - for linear changes, difference in depth is always <= hamming distance - otherwise, changes are probably divergent - when hamming distance is < 200, we can reliably detect when pvecs are near Issues: - hamming distance ceases to work over distances of ~ 200 - detecting divergence is less accurate when the common ancestor is very close to either revision or total distance is high - this could probably be improved by modeling the relation between delta and hdist Uses: - a patch pvec can be used to locate the nearest available common ancestor for resolving conflicts - ordering of patches can be established without a DAG - two head pvecs can be compared to determine whether push/pull/merge is needed and approximately how many changesets are involved - can be used to find a heuristic divergence measure between changesets on different branches é)Úabsolute_importé)Únullrev)ÚpycompatÚutiliÀéééécCs"d}|D] }|dt|ƒ}q|S)zconvert a bytestring to a longré)Úord)ÚbsÚvÚb©rú0/usr/lib/python3/dist-packages/mercurial/pvec.pyÚ_binDsrcCs2d}t |¡D]}t |d@¡|}|dL}q|S)Nóéÿr)rÚxrangeÚbytechr)rÚlr ÚprrrÚ_strLs  rcCs t|dt…ƒt|td…ƒfS)zdepth and bitvecN)rÚ _depthbytes)rrrrÚ_splitUs rcCst|tƒt|tƒS©N)rrÚ _vecbytes)ÚdepthÚbitvecrrrÚ_joinZsr cCs(d}|r|d@r |d7}|dL}|s|S)Nrrr)ÚxÚcrrrÚ_hweight^sýr#cCsg|]}t|ƒ‘qSr)r#)Ú.0r!rrrÚ gsr%r cCs0||A}d}|r|t|d@7}|dL}|s|S)z+find the hamming distance between two longsrrr)Ú_htab)ÚarÚdr"rrrÚ_hammingjsþr)cCsº|\}}|\}}||kr||||f\}}}}t||ƒ}||}|} ||A} d} ||kr4||dd} nd} || } | rT| rP| | @rJ| | N} | d8} | dK} | s>| | fSt| |ƒ} | | fS)Nrr )r)Ú_flipbit)r!Úyr"Úd1Úv1Úd2Úv2ÚhdistÚddistrÚmÚiÚchangesrrrrÚ _mergevects. ü þr5cCst|ƒd@t}|d|>AS)Nlÿÿr)ÚhashÚ_vecbits)rÚnodeÚbitrrrr*šs r*c Csò| ¡}t |d¡s i|_|j}| ¡|vrj|j}t | ¡d¡D]G}||vri| |¡}|  |¡\}}|t krGdt |ddt …ƒf||<q"|t kr]||\}} |dt | |ƒf||<q"t|||||ƒ||<q"t|| ¡Ž} tt | ¡ƒS)z3construct a pvec for ctx while filling in the cacheÚ _pveccacherréN)ÚreporÚ safehasattrr:ÚrevÚ changelogrrr8Ú parentrevsrrrr*r5r ÚpvecÚ b85encode) ÚctxÚrÚpvcÚclÚnr8Úp1Úp2r(rr rrrÚctxpvec s&    €rJc@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)rAcCs8t|tƒr||_tt |¡ƒ\|_|_dSt|ƒ|_dSr) Ú isinstanceÚbytesÚ_bsrrÚ b85decodeÚ_depthÚ_vecrJ)ÚselfÚ hashorctxrrrÚ__init__¹s z pvec.__init__cCs|jSr)rM)rQrrrÚ__str__Àsz pvec.__str__cCs|j|jko |j|jkSr)rPrO©rQrrrrÚ__eq__Ãsz pvec.__eq__cCs2|j|j}|dkr dSt|j|jƒ|krdSdS)NrFT)rOr)rP©rQrÚdeltarrrÚ__lt__Æs z pvec.__lt__cCs||kSrrrUrrrÚ__gt__Îsz pvec.__gt__cCs*t|j|jƒ}t|j|jƒ|krdSdS)NFT)ÚabsrOr)rPrWrrrÚ__or__Ñsz pvec.__or__cCs||Brtdƒ‚|j|jS)Nsconcurrent pvecs)Ú ValueErrorrOrUrrrÚ__sub__×s z pvec.__sub__cCs(t|j|jƒ}t|j|jƒ}t||ƒSr)r[rOr)rPÚmax)rQrr(ÚhrrrÚdistanceÜs z pvec.distancecCs2t|j|jƒ}|tkst|j|jƒtkrdSdS)NF)r[rrOÚ_radiusr)rP)rQrÚdistrrrÚnearásÿz pvec.nearN) Ú__name__Ú __module__Ú __qualname__rSrTrVrYrZr\r^rardrrrrrA¸s rAN)Ú__doc__Ú __future__rr8rÚrrÚ_sizeÚ_bytesÚ _depthbitsrrr7rbrrrr r#rr&r)r5r*rJÚobjectrArrrrÚs, +     &