o ]Lb,]@sbdZddlmZddlZddlZddlmZddlmZm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z dd lm!Z"Gd d d ejZ#Gd d d e#e j Z$Gddde#ej%Z&GdddejZ'Gdddej(Z)Gdddej*Z+ddZ,Gddde-Z.d#ddZ/ddZ0Gddde-Z1 d$d!d"Z2dS)%zRepository class for viewing uncompressed bundles. This provides a read-only repository interface to bundles as if they were part of the actual repository. )absolute_importN)_)hexnullrev)bundle2 changegroup changelogcmdutil discoveryencodingerrorexchangefilelog localrepomanifestmdiffpathutilphasespycompatrevlog revlogutilsutilvfs)urlutil) constantscsXeZdZddZdddZddZdfdd Zd d Zd d ZddZ ddZ Z S) bundlerevlogc CsLt|}tjj||||d||_t|}|d|_t|_| D]}|\}} } } } } }}t| }| |}|j |rJ|j |j |q#| |krQt}n|| }| | fD]}|j |skt||jtdqY|j | s{t| |jtd|| }tj||||||| || |d}|j ||j ||d7}q#dS)N)targetradixrsunknown parentsunknown delta base)flags data_offsetdata_compressed_lengthdata_delta_baselink_rev parent_rev_1 parent_rev_2node_id)vfsmod readonlyvfsr__init__bundlelen repotiprevset bundlerevs deltaitertellindexhas_nodeaddrevrr LookupError display_idrrentryappend)selfopenerrr cgunpacker linkmappern deltadatanodep1p2cs deltabasedeltarsidedatasizestartlinkrevpbasereverL6/usr/lib/python3/dist-packages/mercurial/bundlerepo.pyr)8sR             zbundlerevlog.__init__NcCs<||jkr tj||S|j|||j||SN)r,r_chunkr*seekrGreadlength)r9r4dfrLrLrMrOps zbundlerevlog._chunkcCsr||jkr||jkr|j|d}||kr||Sn||jkr-||jkr-tj|||St||||S)z1return or calculate a delta between two revisions)r,r1rOrrevdiffrtextdiffrawdata)r9rev1rev2revbrLrLrMrUys zbundlerevlog.revdiffc s|dur ||}d}d}g}|}||jkr7|jr&|jd|kr&|jd}n|||j|d}||jks|tkr>d}n|durUtt|j| |||d}|\} }}|rYd}|rk| | } t || g}|s[|||fS)NFrrT)_df)r4r,_revisioncacher8r1rsuperr_rawtextr?rOpoprpatches) r9r?r4r] validatedrawtextchainiterrevr__rD __class__rLrMr`s6         zbundlerevlog._rawtextcOtrNNotImplementedErrorr9argskwargsrLrLrM addrevisionzbundlerevlog.addrevisioncOrkrNrlrnrLrLrMaddgrouprrzbundlerevlog.addgroupcOrkrNrlrnrLrLrMstriprrzbundlerevlog.stripcCrkrNrlr9rLrLrM checksizerrzbundlerevlog.checksizerN) __name__ __module__ __qualname__r)rOrUr`rqrsrtrv __classcell__rLrLrirMr7s 8  rc@eZdZddZdS)bundlechangelogcCs6tj||dd}t||tjdf|j||dS)NcSs|SrNrL)xrLrLrMsz*bundlechangelog.__init__..)r r)rrevlog_constantsKIND_CHANGELOGr)r9r:r;r<rLrLrMr)szbundlechangelog.__init__Nrwrxryr)rLrLrLrMr| r|cs*eZdZ  dddZfddZZS)bundlemanifestNr\cCsdtjj||||dt||tj|f|jj|||dur*i}|jj dkr*t |j}||_ ||_ dS)N)trees03) rmanifestrevlogr)rrKIND_MANIFESTLOG_revlogrr*version_getfilestarts _dirlogstarts _linkmapper)r9 nodeconstantsr:r;r< dirlogstartsdirrLrLrMr)s    zbundlemanifest.__init__csJ||jvr|j|j|t|j|j|j|j|j|dStt||S)N)r) rr*rPrrr:rr_dirlog)r9drirLrMrs zbundlemanifest.dirlog)Nr\)rwrxryr)rrzrLrLrirMrs  rc@r{) bundlefilelogcCs2tj|||t|tj|f|jj||d|_dS)N)rrr;r<)rr)rr KIND_FILELOGrr)r9r:pathr;r<rLrLrMr)s zbundlefilelog.__init__NrrLrLrLrMrrrc@r{) bundlepeercCdSNFrLrurLrLrMcanpushrrzbundlepeer.canpushN)rwrxryrrLrLrLrMrrrcs4eZdZfddZddZddZddZZS) bundlephasecachecs8tt|j|i|t|drt|j|_dSdS)Nr:)r_rr)r safehasattrr'r(r:rnrirLrMr)s zbundlephasecache.__init__cCrkrNrlrurLrLrMwriterrzbundlephasecache.writecCrkrNrl)r9fprLrLrM_writerrzbundlephasecache._writecCs||j|<|d|_dS)NT) phaseroots invalidatedirty)r9phasenewrootstrrLrLrM _updaterootss  zbundlephasecache._updateroots)rwrxryr)rrrrzrLrLrirMrs  rcsFi}tjiD]}|d}||<tfddiD]}qq|S)Nsfilenamecs dSrN) deltachunkrLr;rLrMr~ s z _getfilestarts..)iter filelogheaderr0)r;filespos chunkdatafnamechunkrLrrMrs rcseZdZdZddZddZd&ddZejd d Z ejd d Z d dZ ejddZ ddZ ejddZejddZddZfddZddZddZdd Zd!d"Zd'fd$d% ZZS)(bundlerepositorya%A repository instance that is a union of a local repo and a bundle. Instances represent a read-only repository composed of a local repository with the contents of a bundle file applied. The repository instance is conceptually similar to the state of a repository after an ``hg unbundle`` operation. However, the contents of the bundle are never applied to the actual base repository. Instances constructed directly are not usable as repository objects. Use instance() or makebundlerepository() to create instances. c CsR||_||_|jddddd|_t|d}t|j||}t |t j r[||_ d|_ d}|jddD]}|jdkrC|rAtd |}|||q4|sSttd |d tjn/t |tjr|rx|j|jd d d}t|j|||j}||_ ||_ n ttdt|i|_|jj d|_!t"#|dt"j$dd||j!dDdS)NphasesspublishFs bundlereporbT)seekable changegroups#can't process multiple changegroupssNo changegroups foundrs.hg10unHG10UN)headersbundle type %s cannot be readrcSg|]}|qSrLr?.0ctxrLrLrM Xz-bundlerepository.__init__..)% _tempparent_urlui setconfigtempfiler posixfiler readbundle isinstancer unbundle20 _bundlefile _cgunpacker iterpartstyperm_handlebundle2partr AbortrrPosSEEK_SETr cg1unpacker compressed_writetempbundlerQr _cgfilesposr r, firstnewrevrretractboundarydraft)r9 bundlepathurl tempparentfr*cgpartpartrLrLrMr)sP    zbundlerepository.__init__cCsv|jdkrdS|}|jdd}t|}||vr$td}t|||r1| |j d|}t ||d|_ dS)Nrsversions01s#Unsupported changegroup version: %ss.cg%sunsUN) rparamsgetrsupportedincomingversionsrr rrrrQ getunbundlerr)r9r*rcgstreamr legalcgversmsgrLrLrMr[s  z#bundlerepository._handlebundle2partr\cCs~|jjd|d\}}||_t|d}|| |d}|s!n||qWdn1s1wY|jj|jddS) zWrite a temporary file to disks hg-bundle-)prefixsuffixwbTiNr)mode)rmkstemprrfdopenropen)r9readfnrrfdtemptempfptemprrLrLrMrjs  z!bundlerepository._writetempbundlecCs t||jSrN)r_phasedefaultsrurLrLrM _phasecacheys zbundlerepository._phasecachecCs(|jt|j|j}|j|_|SrN)rchangelogheaderr|svfsr0manstart)r9crLrLrMr }s  zbundlerepository.changelogcCdSrNrLrurLrLrM_refreshchangelogsz"bundlerepository._refreshchangelogcCsZ|j|j|j|jj}t|j|j |j|}|j |_ t |j |||SrN)rrPrmanifestheader unfilteredr r4rrrr0 filestartr manifestlog narrowmatch)r9r< rootstorerLrLrMrs   zbundlerepository.manifestlogcCs8|j|j|j|jD]}q|j|_dS)zgConsumes the manifest portion of the bundle, setting filestart so the file portion can be read.N)rrPrrr/r0r)r9rDrLrLrM_consumemanifests  z!bundlerepository._consumemanifestcCs |j|jSrN)r rrurLrLrMrszbundlerepository.manstartcCs|jd|jvr ||jS)Nr)r__dict__rrrurLrLrMrs zbundlerepository.filestartcCs|jSrN)rrurLrLrMrszbundlerepository.urlcsj|js|j|jt|j|_||jvr-|j|j||jj}t|j ||j|St t | |SrN) rrrPrrrr r4rrr_rfile)r9rr<rirLrMrs   zbundlerepository.filecCs>|j|jdur|j|j|jrt|jddSdS)z'Close assigned bundle file immediately.NT)rcloserrunlinkrshutilrmtreerurLrLrMrs  zbundlerepository.closecCrrrLrurLrLrMcancopyrrzbundlerepository.cancopycCst|SrN)rrurLrLrMpeerzbundlerepository.peercCstSrN)r getcwdrurLrLrMrrzbundlerepository.getcwdNcs|dur|j}|j|}|j|}td}|jj|kr'|j|t||jj|kr7|j|t|tt | ||S)Ns9setting parent to node %s that only exists in the bundle ) nullidr r4rr,rwarnrr_r setparents)r9r@rAp1revp2revrrirLrMrs    zbundlerepository.setparents)r\rN)rwrxry__doc__r)rrrunfilteredpropertycacherr rrrrrrrrrrrrrzrLrLrirMrs0 <        rc Cs|r ttd|dd}|stt}|durd}|r=t}||kr+d}nt |}| |r=|t |d}t |}|}|jdkrd|dd}t |dkr_||d} } n |\} } n||} } t|| | S)Ns#cannot create new bundle repositorysbundles mainreporootr\+rr)r rrconfigr findrepor rr normasprefix startswithr+rr localpathschemesplitmakebundlerepository) rrcreateintents createopts parentpathcwdusrepopath bundlenamerLrLrMinstances.          rc Cs|r dt||f}nd|}z tj||dd}d}Wn&tjyBt}z tj||dd}Wn ty?t |wYnwGdddt |j }||_ t |||||S) z?Make a bundle repository object based on repo and bundle paths.s bundle:%s+%ss bundle:%sF)rNTc@s eZdZdS)z5makebundlerepository..derivedbundlerepositoryN)rwrxryrLrLrLrMderivedbundlerepository!sr)r expandpathrrr RepoErrorrmkdtemp Exceptionrrrrjr))rrrrreporrrLrLrMrs(   rc@s$eZdZddZddZddZdS)bundletransactionmanagercCrrNrLrurLrLrM transaction+rrz$bundletransactionmanager.transactioncCrkrNrlrurLrLrMr.rrzbundletransactionmanager.closecCrkrNrlrurLrLrMrelease1rrz bundletransactionmanager.releaseN)rwrxryr$rr%rLrLrLrMr#*s r#Fc stj|||d}|\}}} |s)z |rt|Wn ty"Ynw|gjfSt|fdd| D} dd} |sC| s,|dd} d| voPd| v} | o] d o] d} | r &}| d d || t j |d d d d}t|||}Wdn1swYn d r }| d d || d}Wdn1swYnK|dur ds }| d|d d}Wdn1swYd} n  }| d|| d d}Wdn1swY| r d}nd}t||||}|rd| s,t|j|j|} |}| r3| } | j|| }r{ddjdD} }| dddi}Wdn 1scwYt jd|d}t|_t ||fdd}| ||fS)aDobtains a bundle of changes incoming from peer "onlyheads" restricts the returned changes to those reachable from the specified heads. "bundlename", if given, stores the bundle to this file path permanently; otherwise it's stored to a temp file and gets deleted again when you call the returned "cleanupfn". "force" indicates whether to proceed on unrelated repos. Returns a tuple (local, csets, cleanupfn): "local" is a local repo from which to obtain the actual incoming changesets; it is a bundlerepo for the obtained bundle when the original "peer" is remote. "csets" lists the incoming changeset node ids. "cleanupfn" must be called without arguments when you're done processing the changes; it closes both the original "peer" and the one returned here. )headsforcecsg|]}|vr|qSrLrL)rr}) commonsetrLrMrVsz$getremotechanges..Nsdevelslegacy.exchangesbundle2sbundle1s getbundlesincomingsclient)roleT)sourcecommonheadss bundlecapsscg)r*r+r,schangegroupsubsetr)snodesr*)sbasesr,r*sHG10BZrcSrrLrrrLrLrMrrslistkeyss namespacer)rr&cs&rr tdSrN)rrrrL)r* bundlereporrLrMcleanups   z!getremotechanges..cleanup) r findcommonincomingrrOSErrorrr-local configlistcapablecommandexecutor callcommandr caps20to10resultr writechunks_forwardchunksr writebundlerbaseuirootr&rr findmissingr pulloperationr# trmanager_pullapplyphases)rr"r onlyheadsrr'tmpcommonincomingrheadsrlegexc forcebundle1 canbundle2rKb2rcg bundletypecsets reponodes remotephasespullopr.rL)r*r-r(rrMgetremotechanges5s                   rP)NN)NNF)3r __future__rrri18nrr?rrrrr r r r r rrrrrrrrrrrrr'utilsrrrrr|rrr localpeerr phasecacherrobjectrrrr#rPrLrLrLrMs.  T  w(   Q"&