o ]Lb2>@sddlmZddlZddlZddlmZmZddlmZddl m Z m Z ddl m Z mZmZdZd Zd Zd Zd ZGd dde jZGddde j ZGddde jZdS))absolute_importN)hexsha1nodeconstants)_)pycompatutil)basepack constants shallowutils.dataidxs .datapackcsTeZdZeZeZfddZddZddZddZd d Z d d Z d dZ Z S) datapackstorecstt|||dSN)superr__init__)selfuipath __class__>/usr/lib/python3/dist-packages/hgext/remotefilelog/datapack.pyr#szdatapackstore.__init__cCst|Sr)datapack)rrrrrgetpack&zdatapackstore.getpackcCtd)Ns)must use getdeltachain with datapackstore RuntimeErrorrnamenoderrrget)rzdatapackstore.getc Cr|jD]}z |||WStyYqw|D]}z |||WSty0Yqwt|t|fr)packsgetmetaKeyErrorrefreshrrr!r"packrrrr&,    zdatapackstore.getmetac Cr$r)r%getdeltar'r(rr)rrrr,;r+zdatapackstore.getdeltac Cr$r)r% getdeltachainr'r(rr)rrrr-Jr+zdatapackstore.getdeltachaincCr)Nscannot add to datapackstorerrr!r"datarrraddYrzdatapackstore.add) __name__ __module__ __qualname__ INDEXSUFFIX PACKSUFFIXrrr#r&r,r-r0 __classcell__rrrrrs rc@seZdZeZeZdZdZdgZddZddZ dd Z d d Z d d Z d ddZ ddZddZddZd!ddZddZddZddZdS)"rs!20siQQ(cCs2g}|D]\}}||}|s|||fq|Sr)_findappend)rkeysmissingr!r"valuerrr getmissinghs  zdatapack.getmissingcCstd|t|f)Ns,must use getdeltachain with datapack (%s:%s))rrr rrrr#qsz datapack.getc Cs||}|durt|t|f|\}}}}|j|||}d}|td||dd7}|d7}|td||dd7}td||d}|d7}t||||} | S) Nr!Hr8r7!Q!I)r9r'r_datastruct unpack_fromr parsepackmeta) rr!r"r=deltabaseoffsetoffsetsizerawentrymetalenmetarrrr&vs  zdatapack.getmetac Cs`||}|durt|t|f|\}}}}|j||dd}|\}}} } } || || | fS)NT)r&)r9r'r _readentry freememory) rr!r"r=rHrIrJentryfilename deltabasenodedeltarMrrrr,s   zdatapack.getdeltacCs||}|durt|t|f|j}|g}|d}|j}|tkrJ|tkrJ|j|}t |j |j |||}|d}| ||tkrJ|tks&g} |D]\}}} } | | | \} }} }| | || | |fqN|| S)Nr)r9r'rparamsINDEXENTRYLENGTHFULLTEXTINDEXMARKNOBASEINDEXMARK indexstartrEunpack INDEXFORMAT_indexr:rNrO)rr!r"r=rTchainrHentrylenloc deltachainrIrJrQrRrSrrrr-s.    zdatapack.getdeltachainFcCs$|j|||}|jt|7_d}td|ddd}||||}||}|t} ||| } || | t} | t} || | d} td| d}|| d| d|}||}|r| d|}td||d}||d|d|}t |}|| | ||fS|| | |fS)Nr8r?rrAr@rBrC) rD_pagedinlenrErY NODELENGTH _decompressrFr rG)rrIrJr&rK lengthsize filenamelenrQ nodestartdeltabasestartr"rR deltastart rawdeltalendeltalenrS metastartrLrawmetarMrrrrNs*     zdatapack._readentrycC t|Sr)zlib decompressrr/rrrrc zdatapack._decompresscCstd||f)Nscannot add to datapack (%s:%s)rr.rrrr0sz datapack.addcCsb|j}t|j|d|jd}|j}|||j}|j}t |d|j D]}|||j}||kr6nq'|}|j } | ||t } | ||t } |j } | |kr\| ||| } nN| |kri| ||| } nA||| kr|||d}|||j| }| ||t }||kr| ||| } n||kr|}n||kr|}||| ksodSt|j| S)Nrrr8)rTrErY fanoutstruct fanoutprefix _fanouttablerX _indexendrxrange fanoutcountr[rbrUrZ)rr"rT fanoutkeyfanoutstartindexendiendindex startnodeendnoder]rPmidmidnoderrrr9sJ   zdatapack._findNcCs |D] \}}||||qdSr) markdataentry)rledgeroptionsrQr"rrr markledgers zdatapack.markledgercCsl|j|g}t|}dd|D}t||dkr2|j|jvr4tj|jddtj|j dddSdSdS)NcSs$h|]}|js |jr|j|jfqSr) datarepackedgcedrQr").0errr s z#datapack.cleanup..rT) ignoremissing) sourcesr#setrarcreatedr unlinkpath indexpathpackpath)rrentriesallkeys repackedkeysrrrcleanups zdatapack.cleanupccs&|D] \}}}}||fVqdSr) iterentries)rfn deltabaserjrrr__iter__s zdatapack.__iter__c cs6d}|j}||jkr|}td|||dd}|d7}||||}||7}|||tj}|tj7}|||tj}|tj7}|||d}td|d} |d7}t||||| } || 7}td||d} |d| 7}|||| fV|j ||7_ | r|j}||jks dSdS) Nrr?r8rrAr@rBrC) rDdatasizerErYr NODESIZErarcrFr`rO) rrIr/ oldoffsetrerQr"rrirjuncompressedlenrLrrrr"s6    zdatapack.iterentries)Fr)r1r2r3r4r5rZrUSUPPORTED_VERSIONSr>r#r&r,r-rNrcr0r9rrrrrrrrr]s&  !! - rc@sDeZdZdZeZeZejZejZdgZ ddZ d ddZ dd Z dS) mutabledatapacka A class for constructing and serializing a datapack file and index. A datapack is a pair of files that contain the revision contents for various file revisions in Mercurial. It contains only revision contents (like file contents), not any history information. It consists of two files, with the following format. All bytes are in network byte order (big endian). .datapack The pack itself is a series of revision deltas with some basic header information on each. A revision delta may be a fulltext, represented by a deltabasenode equal to the nullid. datapack = [,...] revision = [1] [1] metadata-list = [, ...] metadata-item = metadata-key could be METAKEYFLAG or METAKEYSIZE or other single byte value in the future. .dataidx The index file consists of two parts, the fanout and the index. The index is a list of index entries, sorted by node (one per revision in the pack). Each entry has: - node (The 20 byte node of the entry; i.e. the commit hash, file node hash, etc) - deltabase index offset (The location in the index of the deltabase for this entry. The deltabase is the next delta in the chain, with the chain eventually terminating in a full-text, represented by a deltabase offset of -1. This lets us compute delta chains from the index, then do sequential reads from the pack if the revision are nearby on disk.) - pack entry offset (The location of this entry in the datapack) - pack content size (The on-disk length of this entry's pack data) 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 [0000, 0001,..., FFFE, FFFF]. Example: the pointer in slot 4F0A points to the index position of the first revision whose node starts with 4F0A. This saves log(2^16)=16 bisect steps. dataidx = fanouttable = [,...] (2^16 entries) index = [,...] indexentry = [1]: new in version 1. r8cCrmr)rncompressrprrr _compressrqzmutabledatapack._compressNc Cst|dkrttd|t|dkrttd|||jvr#dS||}dtdt||||tdt||f}t |}|tdt|7}||7}|j }t|} ||| f|j|<| |dS) Nisname too long %sr snode should be 20 bytes %sr?r@rB) rarrrrjoinrEr*r buildpackmetapackfptellwriteraw) rr!r"rRrSmetadatarawdatarlrIrJrrrr0s.      zmutabledatapack.addc Csptddt|jD}d}|j}|D]!\}}}} |tjkr"t} n||t } t ||| || } || 7}q|S)Ncss&|]\}\}}}||||fVqdSrr)rrdbosrrr s z.mutabledatapack.createindex..r) sortedr iteritemsrrZrnullidrVr#rWrEr*) r nodelocations indexoffsetrrawindexfmtr"rrIrJdeltabaselocationrPrrr createindexs   zmutabledatapack.createindexr) r1r2r3__doc__r4r5rrZrUrrr0rrrrrrNsF  &r) __future__rrErnmercurial.noderrmercurial.i18nr mercurialrrr r r rbrVrWr4r5 basepackstorerrmutablebasepackrrrrrs  >r