o ]LbK@sddlmZddlZddlmZmZddlmZmZddl m Z ddl m Z m Z mZdZeeZd Zd ZeeZd Zd Zd ZdZdZdZdZdZdZd ZGddde jZ Gddde j Z!Gddde j"Z#dS))absolute_importN)hexsha1nodeconstants)pycompatutil)hashutil)basepack constants shallowutils!20sQQIIs!20sQs!20s20s20s20sHRs.histidxs .histpackc@s6eZdZeZeZddZd ddZddZdd ZdS) historypackstorecCst|SN) historypackselfpathrA/usr/lib/python3/dist-packages/hgext/remotefilelog/historypack.pygetpack0szhistorypackstore.getpackNc Csv|jD]}z |j|||dWStyYqw|D]}z |j|||dWSty4Yqwt||f)Nknown)packs getancestorsKeyErrorrefresh)rnamenoderpackrrrr3s     zhistorypackstore.getancestorsc Csn|jD]}z |||WStyYqw|D]}z |||WSty0Yqwt||fr)r getnodeinforr)rr r!r"rrrr#Bs     zhistorypackstore.getnodeinfocCtd|t|f)Ns&cannot add to historypackstore (%s:%s) RuntimeErrorrrfilenamer!p1p2linknodecopyfromrrraddQzhistorypackstore.addr) __name__ __module__ __qualname__ INDEXSUFFIX PACKSUFFIXrrr#r-rrrrr,s  rcseZdZeZeZdgZfddZddZdddZd d Z dd d Z d dZ ddZ ddZ ddZddZdddZddZddZddZZS) rrcs tt||t|_t|_dSr)superr__init__ INDEXFORMAT2 INDEXFORMATINDEXENTRYLENGTH2INDEXENTRYLENGTHr __class__rrr5]s zhistorypack.__init__c CsFg}|D]\}}z|||Wqty |||fYqw|Sr) _findnoderappend)rkeysmissingr r!rrr getmissingbs  zhistorypack.getmissingNc Cs\|r||vrgS|j|||d}i}|D]\}}}} } ||| | f||<q|s,t||f|S)zReturns as many ancestors as we're aware of. return value: { node: (p1, p2, linknode, copyfrom), ... } r) _getancestorsr) rr r!r ancestorsresultsancnoder)r*r+r,rrrrls  zhistorypack.getancestorscCs|||ddS)Nr)r<)rr r!rrrr#szhistorypack.getnodeinfoccs|durt}||}|\}}}}} |h} d} | |krw| s!dS||| \} } | t7} | r6| t| 7} | t}|| vrq| || t}| t}|t j krY||vrY| ||t j krg||vrg| ||||| t | fV| |ksdSdSNr) set _findsection _readentryPACKENTRYLENGTHlenANC_NODEremove ANC_P1NODE ANC_P2NODErnullidr- ANC_LINKNODE)rr r!rsectionr(offsetsizenodeindexoffset nodeindexsizependingoentryr,rDp1nodep2noderrrrAs2     zhistorypack._getancestorscCsR|j}tt|||t}d}|t}|dkr%|t7}||||}||fSrE)_datastructunpack PACKFORMATrI ANC_COPYFROM)rrRdatarXr, copyfromlenrrrrHszhistorypack._readentrycCr$)Ns!cannot add to historypack (%s:%s)r%r'rrrr-r.zhistorypack.addcCs|jdkr#|||}|D]\}}}}}||kr!|||||fSq n3||} | dd\} } ||| | | t} | durVtt| \}} || \} }| dd|fSt d|t |f)Nrrrs unable to find history for %s:%s) VERSIONrArG_bisectNODEINDEXENTRYLENGTHr\r]NODEINDEXFORMATrHrr)rr r!rBrDrYrZr+r,rQrTrUrXrRrrrr<s(   zhistorypack._findnodecCs|j}t|}t|j|d|jd}|j}|||j }|j }t |d|j D]}|||j } | |kr=nq.|} |||| |j} | sOt|t|j| } | \} } }}}|j||tj}td|d}|tj7}|j|||}||krtd||f||7}td|j| | tjd}| tj7} |j| | |}| |7} ||krtd||f| t7} | }|tj|t}|||||fS)Nrr!Hs&found file name %s when looking for %s)paramsrsha1digestr\r] fanoutstruct fanoutprefix _fanouttable indexstart _indexendrxrange fanoutcountrcr9rr7_indexr FILENAMESIZEr[ENTRYCOUNTSIZE)rr rgnamehash fanoutkeyfanoutstartindexendiendrXrawentryxrRrSrTrU rawnamelen actualnamelen actualnamefilenamelengthnodelistoffset nodelistsizerrrrGsp      zhistorypack._findsectionc Cs|}|j||t}|j||t}||kr!|j|||S||kr.|j|||S|||krm|||d}||||}|j||t} | |krZ|j|||S|| kra|}n|| krg|}|||ks4dS)Nr)rq NODELENGTH) rr!rwrzentrylen origstart startnodeendnodemidmidnoderrrrc s&   zhistorypack._bisectcCs |D] \}}||||qdSr)markhistoryentry)rledgeroptionsr(r!rrr markledger"s zhistorypack.markledgercCsl|j|g}t|}dd|D}t||dkr2|j|jvr4tj|jddtj|j dddSdSdS)NcSsh|] }|jr|j|jfqSr)historyrepackedr(r!.0errr )s  z&historypack.cleanup..rT) ignoremissing) sourcesgetrFrJrcreatedr unlinkpath indexpathpackpath)rrentriesallkeys repackedkeysrrrcleanup&s zhistorypack.cleanupccs*|D] \}}}}}}||fVqdSr) iterentries)rfnr|rrr__iter__2s zhistorypack.__iter__c csd}||jkr|j}td|||tjd}|tj7}||||}||7}td|||td}|t7}t|D]:}tt |||t }|t 7}||||t }||t 7}||t |t |t|t|fV|jt 7_qB|||jksdSdS)Nrrfr!I)datasizer[r\r]r rrrsrror^rIr_rKrMrNrP_pagedin freememory) rrRr` filenamelenr(revcountryrXr,rrrr6sF    zhistorypack.iterentriesr)r/r0r1r2r3SUPPORTED_VERSIONSr5r@rr#rArHr-r<rGrcrrrr __classcell__rrr:rrWs$    B  rcsVeZdZdZeZeZdgZdfdd ZddZddZ dfd d Z d d Z Z S)mutablehistorypacka A class for constructing and serializing a histpack file and index. A history pack is a pair of files that contain the revision history for various file revisions in Mercurial. It contains only revision history (like parent pointers and linknodes), not any revision content information. It consists of two files, with the following format: .histpack The pack itself is a series of file revisions with some basic header information on each. datapack = [,...] filesection = [,...] revision = The revisions within each filesection are stored in topological order (newest first). If a given entry has a parent from another file (a copy) then p1node is the node from the other file, and copyfrom is the filepath of the other file. .histidx The index file provides a mapping from filename to the file section in the histpack. In V1 it also contains sub-indexes for specific nodes within each file. It consists of three parts, the fanout, the file index and the node indexes. The file index is a list of index entries, sorted by filename hash (one per file section in the pack). Each entry has: - node (The 20 byte hash of the filename) - pack entry offset (The location of this file section in the histpack) - pack content size (The on-disk length of this file section's pack data) - node index offset (The location of the file's node index in the index file) [1] - node index size (the on-disk length of this file's node index) [1] The fanout is a quick lookup table to reduce the number of steps for bisecting the index. It is a series of 4 byte pointers to positions within the index. It has 2^16 entries, which corresponds to hash prefixes [00, 01, 02,..., FD, FE, FF]. Example: the pointer in slot 4F points to the index position of the first revision whose node starts with 4F. This saves log(2^16) bisect steps. dataidx = [1] [1] [,...] [1] fanouttable = [,...] (2^16 entries) fileindex = [,...] fileindexentry = [1] [1] nodeindex = [,...] [1] filename = [1] nodeindexentry = [1] [1] [1]: new in version 1. rcsDtt|j|||di|_i|_i|_t|_t|_ t |_ t |_ dS)N)version) r4rr5filesentrylocations fileentriesr6r7r8r9rerd)ruirrr:rrr5s zmutablehistorypack.__init__cCs<|pd}tdt|}|j|g||||||fdS)Nrf)r\r"rJr setdefaultr=)rr(r!r)r*r+r,rarrrr-s zmutablehistorypack.addc s2t|jD]}|j|}|j}dd|Dfdd}tttdd|D|}|dt dt ||t d t |ft j t |d }g}|j|i}||} |D]} | || <d | } || | t | 7} q[d |} |t | 7}|| ||f|j|<t|} | |j| <qdS) NcSsi|]}|d|qS)rrrrrr sz-mutablehistorypack._write..csD|\}}}}}}g}|tjkr|||tjkr |||Sr)rrOr=)r!r|r)r*parentsentrymaprr parentfuncs    z-mutablehistorypack._write..parentfunccss|]}|dVqdS)rNrrrrr sz,mutablehistorypack._write..s%s%s%srfrrs %s%s%s%s%s%sr)sortedrpackfptelllistreversedr sortnodeswriterawr\r"rJr rrrrr=joinrrrhrir) rr(r sectionstartr sortednodes sectionlen rawstrings locationsrRr!rawrawdatarrr_writesD           zmutablehistorypack._writeNcs$|jrdS|tt|j|dS)N)r)_closedrr4rclose)rrr:rrrszmutablehistorypack.closec Cs@|j}|j}|j}|j}ddt|jD}t|}t d}||t |||} g} g} d} |D]Y\} }}}|j |}t ||}t || ||| |}| t tjt ||| tjt |7} tt|D]\}}| t |||| d7} qm| t ||7} | |q4t d| }d| |d| S)Ncss.|]\}\}}t||||fVqdSr)rrhri)rr(rRrSrrrr s   z1mutablehistorypack.createindex..s!Qrrr)r7r9rerdr iteritemsrrr\calcsizerJrr"r=r FILENAMESTRUCTrrr)r nodelocations indexoffsetfileindexformatfileindexlengthnodeindexformatnodeindexlengthr indexlensizerTfileindexentriesnodeindexentries nodecountrtr(rRrSrUr{r!location nodecountrawrrr createindexsb          zmutablehistorypack.createindex)rr) r/r0r1__doc__r2r3rr5r-rrrrrrr:rr`sK 8r)$ __future__rr\mercurial.noderr mercurialrrmercurial.utilsrr r r r6rr8rrerdr^rIrsr2r3rKrMrNrPr_ basepackstorerrmutablebasepackrrrrrs4    +