o ]Lb=@sddlmZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZdd lmZmZmZGd d d eZGd d d eZdS))absolute_importN)bin)_)ancestorerrormdiffpycompatrevlog) storageutil)flagutil) constantsfileserverclient shallowutilc@s$eZdZddZddZddZdS)remotefilelognodemapcCs||_||_dSN) _filename_store)selffilenamestorerC/usr/lib/python3/dist-packages/hgext/remotefilelog/remotefilelog.py__init__!s zremotefilelognodemap.__init__cCs|j|j|fg}t| Sr)r getmissingrbool)rnodemissingrrr __contains__%s z!remotefilelognodemap.__contains__cCs||vrt||Sr)KeyErrorrrrrr__get__)szremotefilelognodemap.__get__N)__name__ __module__ __qualname__rrr!rrrrr s rc@sJeZdZdZejZddZddZdFddZ d d Z dde j dfd d Z  dFd dZddZddZeZddZddZeZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Z  ' ' '  dGd(d)Zd*d+Zd,d-Zd.d/Z d0d1Z!dHd2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&dd?Z(d@dAZ)dBdCZ*dDdEZ+dS)I remotefilelogTcCs8||_||_||_t|j|j|_d|_ttj |_ dS)Nr ) openerrrepor contentstorenodemapversiondictr flagprocessors_flagprocessors)rr&pathr'rrrr4s zremotefilelog.__init__cCs4||}|ds |S|dd}||ddS)z&returns the file contents at this nodes N)revision startswithindex)rrtsrrrread>s   zremotefilelog.readNc Cs>t||d|d}t|||}|j||||||dS)Ncopycopyrev)r)rcreaterevlogtextgetr hashrevisionsha1 addrevision) rtextmeta transactionlinknodep1p2hashtextrrrraddFs zremotefilelog.addcCstt||}d||f} |} d} |r"d|vr"|d} t|d} | d|| ||| f7} t} i} g}| |jjkrX|}| rFt|j| |j}| | | | | | | ||jjkrp| | || || |d}|r| d}| |\}}}}|pd}|d|||||f7}||jjkr|| vr| || |||jjkr|| vr| || ||st| |7} | S)Ns%s%sr6r7s %s%s%s%s%sr)rbuildfileblobheaderlenrsetr'nullidr%r&update ancestormapappendrCpop)rr<r=flagsr@rArr?headerdatarealp1copyfromvisited pancestorsqueuep1flog ancestortextcpa1pa2ancestorlinknode pacopyfromrrr_createfileblobPsV              zremotefilelog._createfileblobc  CsV|dur t|||}t|\} } t|||\} } |j| |||||||| | fd S)N) _metatuple)r r: parsemetar processflagswriteaddrawrevision)rr<r>r?r@rA cachedeltarrMsidedatar= metaoffsetrawtext validatehashrrrr;s& zremotefilelog.addrevisionc  Csl| r| \} } nt|\} } |dkrd} | r|| d} n|} || | |||||} |jj|j|| |S)Nr)r r^r\r'r(addremotefilelognoder)rrdr>r?r@rArrMrar]r=rcblobtextrOrrrr`s  zremotefilelog.addrawrevisioncCs2|jj|j|}||\}}}}|r||fSdSNFr' metadatastore getancestorsr)rr ancestorsr@rAr?rQrrrrenameds zremotefilelog.renamedcCst||S)z#return the size of a given revision)rFr5r rrrsizeszremotefilelog.sizecCs"||jjkrdS||}||kS)zpcompare text with a given file revision returns True if text is different than what is stored. T)r'rHr5)rrr<nodetextrrrcmps  zremotefilelog.cmpcCdS)NTrrrrr __nonzero__zremotefilelog.__nonzero__cCs|jdvrdStd)N)s.hgtagss.hgsubs .hgsubstaterslen not supported)r RuntimeErrorrrrrr__len__s zremotefilelog.__len__cCgSrrrrrrrheadszremotefilelog.headscCrqrhrrrrrremptyrtzremotefilelog.emptycCs4t|tr td|jj}||j|t j dS)Ns3remotefilelog does not accept integer rev for flagsr) isinstanceintrProgrammingErrorr'r(getmetarr9r METAKEYFLAG)rrrrrrrMs zremotefilelog.flagscCsR||jjkr|jj|jjfS|jj|j|}||\}}}}|r%|jj}||fSr)r'rHrjrkrrrrJr@rAr?rQrrrparentss zremotefilelog.parentscCs ||Sr)rrrevrrr parentrevss zremotefilelog.parentrevscCs&|jj|j|}||\}}}}|Srrirrrrr?szremotefilelog.linknodecCs|jj||Sr)r' unfiltered changelogrr?r rrrlinkrev$zremotefilelog.linkrevFccs~~~~~d}|D]F} || \} } |dur| } }| | kr#|jj} | |jjkr2d} || | }n|| } d}tj| | | || | || d| |ddd Vq dS)Nr) rp1nodep2noder?basenoderMbaserevisionsizer0deltarbprotocol_flags) rr'rHrevdiffrawdatar revlogrevisiondeltar?rM)rnodes nodesorder revisiondataassumehaveparentrevisions deltaprevious deltamodesidedata_helpersprevnoderr@rArr0rrrr emitrevisions's:    zremotefilelog.emitrevisionscCst||||Sr)rtextdiffr)rnode1node2rrrrQrzremotefilelog.revdiffcCs8t|dkr t|}t|dkrt||jtd|S)N(sinvalid lookup input)rFrr LookupErrorrrr rrrlookupTs   zremotefilelog.lookupcCs|Srrr rrrr^ryzremotefilelog.revcCst|tr td|S)Ns2remotefilelog does not convert integer rev to node)r{r|rr}rrrrrbs zremotefilelog.nodecCs||jjkrdSt|dkrt||jtd||jjjks&||jjj vr)tj |jj }| |j|}|r8|S| |j| tjd}|dkrJ|St|||dS)zreturns the revlog contents at this node. this includes the meta data traditionally included in file revlogs. this is generally only used for bundling and communicating with vanilla hg clients. rDrsinvalid revision inputr)r'rHrFrrrr nodeconstantswdiridwdirfilenodeidsWdirUnsupportedr(r9r~r rr processflagsread)rrrawrrdrMrrrr0js"   zremotefilelog.revisioncCs|j|ddS)NF)r)r0r rrrrszremotefilelog.rawdatacCs|jj}|j}t|jj|j|}z||WSty Ynwt |j|}t j |j |}zt|WSty?Ynw||j|fgz||WStyXYnwt||jtd)z3reads the raw file blob from disk, cache, or serversno node)r' fileservice localcacher getcachekeynamerr5r getlocalkeyosr.join localpathrreadfileIOErrorprefetchrrr)ridrrcachekeylocalkeyrrrr_reads0       zremotefilelog._readcCs|jj|j|Srrir rrrrJszremotefilelog.ancestormapcCsv||jjks ||jjkr|jjS|||\}}ddt|D}t|||||}|r7tt|j |S|jjS)NcSi|]\}}||qSrr.0kvrrr z*remotefilelog.ancestor..) r'rH_buildrevgraphr iteritemsrrlminmap __getitem__rabrevmap parentfuncr)ancsrrrrszremotefilelog.ancestorcCsf||jjks ||jjkr|jjS|||\}}ddt|D}t|||||}t|j|S)z@calculate all the heads of the common ancestors of nodes a and bcSrrrrrrrrrz6remotefilelog.commonancestorsheads..) r'rHrrrrcommonancestorsheadsrrrrrrrs  z"remotefilelog.commonancestorsheadscsN||}||}tt}t||fD]8}t|D]0\}}||} |\} } } } | |jjkr=| s=| |  | | |jjkrM| |  | qqtt}i}t fdd|D}|r| \}}||vrz|ry|| ||qbt |t |d}|||<|r|| |||D] }|||fq|sd||jfS)zBuilds a numeric revision graph for the given two nodes. Returns a node->rev map and a rev->[revs] parent function. c3s |] }|vrd|fVqdSrr)rn allparentsrr sz/remotefilelog._buildrevgraph..r )rJ collections defaultdictlistrGrrr'rHrKrCdequerLrFr9 appendleftr)rrramapbmap parentsmapmappingrpdatarr@rAr?rQrrrTprevrevcurrent currentrevparentrrrrsF             zremotefilelog._buildrevgraphcCsdSrr)rminlinkr>rrrstriprtzremotefilelog.stripcCrwrrrrrrrfilesrtzremotefilelog.filescCrq)N)rrrrrrrr checksizertzremotefilelog.checksize)NN)NFFFNN)F),r"r#r$ _generaldeltar RevlogError_flagserrorclassrr5rCr\r REVIDX_DEFAULT_FLAGSr;r`rmrnrawsizerprs__bool__rvrxrzrMrrr?rrrrrrr0rrrJrrrrrrrrrrr%/sd  @ + ,    *    1 r%) __future__rrrmercurial.nodermercurial.i18nr mercurialrrrrr mercurial.utilsr mercurial.revlogutilsr r rrobjectrr%rrrrs