m RDc@s'dZdkTdklZdklZeedeeddZdZdd>Z e Z eZ e e BZ d Z d Zd Zd Zd ZdZdZdZdZdefdYZdefdYZdefdYZdefdYZdefdYZdS(sM revlog.py - storage back-end for mercurial This provides efficient delta storage with O(1) retrieve and append and O(changes) merge between branches Copyright 2005 Matt Mackall This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. (t*(sgettext(s demandloads)binascii changegroup errno heapq mdiff osssha struct util zlibiiicCs/|djotSnttd|dS(Ntinlinesunknown revlog flag %s(tflagtREVLOGNGINLINEDATAt RevlogErrort_(R((t4/usr/lib/python2.4/site-packages/mercurial/revlog.pytflagstrs cCsQ||g}|iti|d}|i|d|i||i S(sgenerate a hash from the given text and its parent hashes This hash combines both the current file contents and its history in a manner that makes it easy to distinguish nodes with the same content in the revision graph. iiN( tp1tp2tltsorttshatnewtstupdatettexttdigest(RRR R R((Rthash#s   cCs|pd|fSnt|djo-|ddjod|fSnd|fSnti|}t|t|jo-|ddjod|fSnd|fSnd|fS(s7 generate a possibly-compressed representation of text ti,ittuN(Rtlentzlibtcompresstbin(RR((RR1scCs|p|Sn|d}|djo|Sn|djoti|Sn|djo |dSnttd|dS(s decompress the given input iRtxRisunknown compression type %rN(RttRt decompressRR(RR((RR=s    s >4l20s20s20si8s>Qiiiiii20s12xi s>it lazyparsercBsqtZdZeidjpei o eedZdZ dZ e dZ dZ e e dZRS(sK this class avoids the need to parse the entirety of large indices tnttwin32apicCs||_||_ti||_||_||_||i|_ dg|i |_ ht d<|_ d|_d|_d|_||_dS(Nii(tdataftselft indexformattformattstructtcalcsizeRtsizetdatasizeR tNonetindextnullidtmaptallmaptallt mapfind_countt shaoffset(R!R R&R"R/((Rt__init__as       c Cs|iodSnd}|i}d|_d}d}|id}|i i dx||jo|i i |} d}xltdD]^}| ||i||id!}||i|<|d7}||ijoPn||i7}qW||7}qVWdS(s during a commit, we need to make sure the rev being added is not a duplicate. This requires loading the entire index, which is fairly slow. loadmap can load up just the node map, which takes much less time. Niiii(R!R,tstartR'tendtcurtcountRt blocksizeR tseektreadtdatatofftxrangeRR/tnR+R ( R!R4R2R3R5R;R1RR9R8((Rtloadmapos.        c Cs|iodSn|djo&|ii||ii|}nt ||i }||i }d}xt|D]|} |i|| djoQ||||i !}||i|| <||i|id!}|| |i|R?R;R((Rt loadblocks     c Cs|iodSn|idjo*|i||ijo|SndSn|id7_|id}xJ|i |djo5|djod|_ d|_dSn|d8}qkW|d|i }|i d}x|djot||d}|ii||ii||} ||}xto| i|d|}|}|djoj||i }||i }| ||i||id!} | |jo |||i |i| <|Sqq)Pq)W||8}qWdS(s;search backwards through the index file for a specific nodeiiiiiN(R!R,R(R.R<tnodeR+R tlastR)R-RR2R5tmaxR1R R6R7R8tfindendtTruetrfindR9R?R/R;( R!RBR2R?R5R9RER1RCR;R8((RtfindnodesN              cCs|iodSnt}|djo-d}d|i|i}|i}t }nY|o(||i}||i}||}n*|d@|i}|id}||}x,||jo|i ||||7}qW|o t |_ndS(Niii i@( R!R-tFalseR?R(R=RR5R'R2RFRA(R!R?R2R-R5R=((Rt loadindexs*         (t__name__t __module__t__doc__tostnametutilt is_win_9xthasattrt safe_to_useR0R<R(RARHRJ(((RRVs -    ,t lazyindexcBsMtZdZdZdZdZdZdZdZdZ RS(s!a lazy version of the index arraycCs ||_dS(N(tparserR!tp(R!RU((RR0scCst|iiS(N(RR!RVR)(R!((Rt__len__scCsE|djo|t|ii7}n|ii||ii|S(Ni(tposRR!RVR)RJ(R!RX((Rtloads cCsP|ii|p |i|}t|toti |ii |}n|S(N( R!RVR)RXRYtrett isinstancetstrR$tunpackR"(R!RXRZ((Rt __getitem__s cCs||ii||BS(Ni(RtoffsetR(R!RR((RRscCs1t|ito|iii||ndS(s8load a block of indexes all at once from the lazy parserN(R[R!R)RTRVRJR1R2(R!R1R2((RRJscCs=t|ito&|ii}|i|i|_ndS(s5loads both the map and the index from the lazy parserN(R[R!R)RTRVRJR+R(R!RV((Rt loadindexmaps   cCs=t|ito&|iii|iii|_ndS(s"loads the map from the lazy parserN(R[R!RRdRVR<R+(R!((RR<scCs |it@S(N(R!RR(R!((RRscCs|it|idS(Ni(R!RBRR)(R!((RttipscCs t|iS(N(RR!R)(R!((RR4scCs#|djotp|i|dS(Nii(trevR*R!R)(R!R((RRBscCsNy|i|SWn8tj o,ttd|it|fnXdS(Ns%s: no node %s(R!RRBRfRRRlRi(R!RB((RRscCs,|tjodp|i|i|dS(Nii(RBR*R!R)R(R!RB((RtlinkrevscCs~|tjottfSn|i|}|i|dd!}|itjo|Sng}|D]}||i|qa~S(Nii( RBR*R!RtrR)tdRRt_[1]R(R!RBRRRR((Rtparentss cCsi|djodSn|i|dd!}|itjo,g}|D]}||i|qD~Sn|S(Nii(ii(RR!R)RRRRR(R!RRRR((Rt parentrevss  ,cCsP|djodSn|itjo|i|i|dSn|i|dS(Nii(RR!RRRR)(R!R((RR1s  cCs|i||i|S(N(R!R1Rtlength(R!R((RR2scCsbd}|itjo|i|d}n|djo|Sn|i|i|}t |S(s?return the length of the uncompressed text for a given revisioniiiN( R R!RRR)RtrevisionRBRR(R!RR R((RR&s cCs(|djodSn|i|dSdS(Nii(RR!R)(R!R((RRs cCs#|djo|p|i|dS(Nii(RR!R)(R!R((RtbasescCsh}|g}d||<|o|i|}nd}x|o|id}||joq<n|tjoq<nx\|i |D]K}|i||joqn||jod||<|i |qqWq<W|S(Nii( t reachableRtvisittstopR!tstopntpopR;R*RRVRb(R!RRR;RVRRR((RRs*      cCs8gggf}|dj oOt|}|p|Sntg} |D]} | |i| qE~ }nt g}d}|djo`|djoSg} t d|i D]}| |i|q~ t gt|i fSn|djo |i d}d}h}nt|}|p|Snh}|}ti|d}tg} |D]} | |i| q\~ }x|o|i} | t joqn|i| }||jo| |joPd|| <|ig} |i| D]} | t jo | | qq~ qC| |jo|i| qCqqW|p|Sn|djoug} |D]} | |jo | | qoqo~ }|o4tg} |D]} | |i| q~ }q|Snd}t g}ti|d} | i}g}xt t|d|dD]}|i|} t} |djo t} n| | joct} | |joLt |i| } | d| jp| d| jo|i| qqnLt |i| } | d| jp| d| jod| | locate a node based on revision number or subset of hex nodeidiisAmbiguous identifiersNo match foundN(tidR!RRRBRRR\t ValueErrorR4t OverflowErrorRR;Rit startswithRbRRRR((R!RRRR;((Rtlookups4      cCsti||S(s$return a delta between two revisionsN(tmdiffttextdifftaR@(R!RR@((RtdiffscCsti||S(s#apply a list of patches to a stringN(RtpatchesRtpl(R!RR((RRsic si|i|io"|dtii7n}d} i p| |ni d} | ti d}| jo||jo| }n| |d}ti d||!S(Nicsrt}|p3oii}qIii }n|i |i |f_ dS(N(RDtcachelenRt cache_lengthtdfRR!RnRlRmR6R1R7Rq(RR(RR!R1RR(Rt loadcaches i(R!R1RRRRR$R%R"R2RRqRt cache_startRt cache_endRR( R!RRRR2RR1RRRRR((R!RR1RRRtchunks "    cCs#|i|}|i|d|S(s>return or calculate a delta between a node and its predecessoriN(R!RRBRtrevdiff(R!RBR((Rtdelta+scCs|i|}|i|}||jo"|d|jo|i|Sn5|i|i|i ||i|i |SdS(s1return or calculate a delta between two revisionsiN( R!Rtrev1tb1trev2tb2RRRRB(R!RRRR((RR0sc Cs|tjodSn|io#|id|jo|idSnd}|i|}|i|}|io d}n|i |i }|ioZ|id|joF|id|jo2|id}|id}|i ||dn*|i ||d|i |d|}g}x;t|d|dD]"} |i|i | d|q:W|i||}|i|\}}|t|||jo#ttd|i |fn|||f|_|S(s*return an uncompressed revision of a givenRiiiRsintegrity check failed on %s:%dN(RBR*R!RpR(RRRRRRnRmRJRtbinsR:RRbRRRR RRR( R!RBR RRRRRRR((RR:s6   2   #cCs|ipdSn|p)|i|id}|iddn|i}|djodSn|i |i}|djot t d|in|d} |i| }|i|i||i|id}ti|i}xmt|iD]Y}|i||d|}|i|}|i||i|} |i| qW|i|i|i|iddt }|i!t"M_!|ioY|i#d}ti%|i|d } ti%t'|i!} |i| |i| nxLtd|iD]5} |i#| }ti%|i|} |i| q W|i*|i+|i| |d|_,dS( NRiiis%s not found in the transactiontwit atomictempi(-R!RRRnRlR6ttellR&ttrtfindttrinfoR(RRttrindexR1tdataofftaddRmRR$R%R"tcalcR:R4RRR7RtwritetcloseRFRRR)RtpackRcRR R?trenametreplaceRq(R!RRRR&RR1RRRRcRR?R RRR((RtcheckinlinesizeasR             cCs |djo d}n|djo|i}n|djo t}nt|||} | |i jo| Sn|i }|d}|o|i |}|i|} |i|}|p1|i|i} |i| t|}nt|} t| dt| d}|| |}n| p|t|djo4t|} t| dt| d}|}n|i |}d} |djo|i|} n|itjo| |||||| f}nC|i| d|t||||i ||i || f}|i!i"|||i | nodes[0] the receiver is guaranteed to have this parent as it has all history before these changesets. parent is parent[0] Niis%s%s(RtnodelistR;R!Rtrevst changegroupt closechunkRRBRVtinsertR:RRRR@tnbt infocollectR(RRtmetatgenchunk( R!RRR RR@RRVR;RR RR((Rtgroup2s$*    ic Cs|i}|d}d }d}}d} } }|o|i |} n|i |i d}|idd|i|i |i|i|io d } n)|i|i| |i |id} d }x|D]}tid|d \}}}}||}||ijo |}qn|d}xD||fD]6}||ijo t"t#d t$|qIqIW|p>|}||ijo$t"t#d t$|d qn||jo4t%|}|d|d} t(i)||}n||jp| | t*| |djo| o| i+n|i+|i,|}|i.||g}|i/|||||} | |jot"t#d nt*|}nx|i1t2jo%| t*| |||||f}nC|i4| dt*| ||||i5||i5||f}|i6i7|||i|<|iox|i8ti9|i:||i8| |i;|||ip.|i |id} |i |i d}q=n_| p.|i |id} |i |i d}n| i8| |i8ti9|i:|||d||f\}}}}|i|}|i|} |i |} qW|S(s add a delta group given a set of deltas, add them to the revision log. the first delta is against its parent, which should be in our log, the rest are against the previous delta. iiisa+iRt 20s20s20s20siPsunknown parent %ssunknown base %sisconsistency error adding groupN(<R!R4RRR(RBRRR1R2ttextlenRnRltifhR6RRRRtdfhRmtchainRRR$R]RR tcst linkmapperRRRRVRRtshortRttempdtcdeltaRt patchedsizeRtflushRRRRtchkRRRcRRR)RbRRR"R(R!RRRtuniqueRRRRR2RR1RRRRBRRRRRR RcRRVRRR((RtaddgroupUs   "  "   $(  ,  %B     "cCs{|idjp||ijodSnt|ito|inxB||i|djo)|d7}||ijodSqRqRW|i|}|i p<|i |i d}|i||ti|i}n||ti|i7}|i |id}|i|d|_d|_x0t||iD]}|i|i|=qPW|i|3dS(NiiiR(R!R4RR[R)RTRtminlinkR1R2RRnRmRttruncateR$R%R"RltindexfR(RpRqR:RRRB(R!RRR2RRR((Rtstrips.&       c Csd} |io|i|id} ny<|i|i}|idd|i}|| } Wn5t j o)}|i t ijond} nXy|i|i}|idd|i}ti|i}||}|||}|ioXd}x-t|iD]}||i|7}q%Wd} ||i||}nWn5t j o)}|i t ijond}nX| |fS(Niii(texpectedR!R4R2RnRmRtR6RtactualtddRuRvRwRxRlR$R%R"RR?tdiRt databytesR:RR( R!R!RtR?R#R$RRRvR R"((Rt checksizes>        (-RKRLRMtREVLOG_DEFAULT_VERSIONR0RYRRRRRJRR<RRR4RBRRRRR1R2R&RRR(RRRRRRRRRRRRRRR RRR%(((RRksR   A *                         #  ' 1T L # h $N(RMRBti18ntgettextRt demandloadtglobalsRRRtREVLOG_DEFAULT_FLAGStREVLOG_DEFAULT_FORMATR&RRRRRRRRRtobjectRRTRdt ExceptionRRk(RRkRRTRRdRRRRRRR)RRRRRR&R+R,R((Rt? s2        %