o ]LbI@sddlmZddlZddlmZddlmZmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZddlmZmZmZ d)d d Zd d Zd dZddZd*ddZd*ddZddZ ddZ!ddZ"Gddde#Z$d+ddZ%d d!Z&d"d#Z'd,d%d&Z(d'd(Z)dS)-)absolute_importN)_)hexshort) bundle2 changegroup discoveryerrorexchangeobsoleteobsutilpathutilphasespycompat requirementsscmutilutil)hashutil stringutilurlutilTc Csd}|j}||s|||d||} tdd| D} td| } d|t |t | dd|f} t |} d}| d krKd }|rJd }n|rPd }nd }t j|||d}| |dd}tj|j|d| |||||d S)z8create a bundle with the specified revisions as a backups strip-backups%ln::%lncss|]}|VqdSN)r.0cr2/usr/lib/python3/dist-packages/mercurial/repair.py 4zbackupbundle..s%s/%s-%s-%s.hgNs01sHG20sBZsHG10BZsHG10UN) missingroots ancestorsofT)s cg.versions obsolescencesphasesstrip) compression)vfsisdirmkdirsetsortedrsha1joindigestrrr localversionr outgoingrwritenewbundleui)repobasesheadsnodesuffixcompress obsolescence backupdirr% allcommits allhashes totalhashname cgversioncomp bundletyper. contentoptsrrr backupbundle(sN   rAcCs6t}t|t|D] }|||q t|S)z+find out the filelogs affected by the strip)r(rxrangelenupdatefilesr))r1striprevrExrrr _collectfiles[srHcs |\}}fdd|DS)Ncg|]}|qSr)linkrevrrrevlogrr gz"_collectrevlog..) getstrippoint)rNrFr brokensetrrMr_collectrevlogesrScCsHt}t|D] }|t||q|D] }|t|||q|S)z|}|}t;j?||d|dWdn 1swYWdn 1swY|@d}fdd|D} jA|| Wdn 1swYBD]8\}!}"z|!C|"Wq(tDy`}#z|#jEtEjFkrU|Gt2d |!:|"tHI|#fWYd}#~#q(d}#~#wwWn.|ru|Gt2d!|:||r|Gt2d"|:||Gt2d#|:||r|C|Wdn 1swYJ|S)$Ns&cannot strip from inside a transaction)snoner#FcrIr)rev)rr4clrrrOrPzstrip..r)startc3s|]}|vVqdSrr)rp)tostriprrrrzstrip..crIrr4rKr[rrrOrPcrIrr`rKr[rrrOrPcrIrr`rKr[rrrOrPrsdevelsstrip-obsmarkerscsg|] \}}|vr|qSrr)rim) obsmarkersrrrOsstemp)r6r7r#aT) checkambigrsadding branch srbsbundle:sstrip %s)sourceurlsrepaircg|] }|fqSrr`rrb newbmtargetr1rrrOserror removing %s: %s s+strip failed, backup bundle stored in '%s' s1strip failed, unrecovered changes stored in '%s' sG(fix the problem, then recover the changesets with "hg unbundle '%s'") )Kcurrenttransactionr ProgrammingError unfiltered destroyingr% _bookmarks changelog isinstancebytesminrHrXr(revsany parentrevsadddifference_update descendantsr0 configboolr exclusivemarkers enumerateobsstore_bookmarkmovements_createstripbackuprAuninterruptible transaction _offsetmapkeysrD _newfiles startgroupstrip stripmanifestrUendgroup readjournalsvfstruncatestore markremoveddeleteobsmarkersinvalidatevolatilesets _phasecache filterunknownnoteropenr readbundleverbosesilentrnullcontextmanagerr+r unbundle20r hidepassword applybundleclose applychanges undofilesunlinkOSErrorerrnoENOENTwarnr forcebytestr destroyed)$r0r1nodelistbackuptopicr% striplistrFrEsaverevs saveheadsrLr| savebases stripbases stripobsidxupdatebm backupfiler4 tmpbundlefiletroldfilesfnentriesrUtroffsetfpfgen maybe_silent tmpbundleurltxnname bmchangesundovfsundofileer)r\rlrcr1r_rrvs*                            brc sddd|D}|sdSd}|r|d}t|||}t|\}d$} t| tj|fdd|D} j| | Wd|S1sQwY|S)z/perform a "soft" strip using the archived phasecSg|]}|qSrr`rrrrrO8zsoftstrip..s sort(%ln::)Nrr#crirr`rjrkrrrODrm) r(rrrrretractboundaryarchivedrrr) r0r1rrrr_rr4rrrrrkr softstrip6s   rcCst|j}g}|D]}|||}||vr||qd}|r6|d||}|r4||}||fSd}||fS)Nsmax(parents(%ld) - (%ld)).)rrrZappendrwfirstr4)r1r_bmrrbrZrlrrrrIs rcCsT|j}|j}t|||||}|jtd|||jdd|||S)Nssaved backup bundle to %s s backupbundle) r%rsrAr3r0statusrr+log)r1rr4rr%r\rrrrr_s rcsjjfdd|D}d}t|||tj|}||}|r:dtfdd|D}| t d|dd d |DS) zDreturn list of roots of nodes where descendants are covered by nodescsh|]}|qSrrrn)torevrr nrz!safestriproots..s5%ld - ( ::( (roots(%ld):: and not _phase(%s)) -%ld) )s, c3s |] }t|VqdSr)rr4r)r1rrrwsz!safestriproots..s9warning: orphaned descendants detected, not stripping %s cSrrr`rrrrrO|rz"safestriproots..s roots(%ld)) rprsrZr(rwrinternalr+r)rr)r0r1nodesrwrevsetr_notstripnodestrr)r1rrsafestriprootsks rc@s(eZdZdZddZddZddZdS) stripcallbackz(used as a transaction postclose callbackcCs&||_||_||_|p d|_g|_dS)NrY)r0r1rrr)selfr0r1rrrrr__init__s   zstripcallback.__init__cCs|j|dSr)rextend)rrrrraddnodesszstripcallback.addnodescCs6t|j|j|j}|rt|j|j||j|jdSdSr)rr0r1rrrr)rrrootsrrr__call__szstripcallback.__call__N)__name__ __module__ __qualname____doc__rrrrrrrrs  rcCsp|}|st|||}t|||||dS|d}|dur,t||||d}|d||r1||_||dS)ailike strip, but works inside transaction and won't strip irreverent revs nodelist must explicitly contain all descendants. Otherwise a warning will be printed that some nodes are not stripped. Will do a backup if `backup` is True. The last non-None "topic" will be used as the backup topic name. The default backup topic name is "backup". )rrsstripN)rnrr getpostcloser addpostcloserr)r0r1rrrrrcallbackrrr delayedstrips    rcCst|D]}|||qdSr)rTr)r1rFrrErNrrrrs rccsf|jdVt|r/|jD]\}}}|dr.|dr.|dd}|j|VqdSdS)Nrsmeta/s 00manifest.ii) manifestlog getstorageristreemanifestr datafiles startswithendswith)r1t unencodedsizedirrrrrTs  rTFc Cs|}tj|jvr|tddS|F|jj}|j|jdt |j }t }t }|rh|D]3}|dddkrf|dddkrf| |dd| ||ddd}|j |rf| |q3nO|j td td t|d } |D]:} | | || } | D]*}||vrq| |d |} d |} |j | r| | |j | r| | qqx| tj|jvrt|D] }d|} d|} |j | r| | |j | r| | qt||}t||}t||D] }|td|qt||D] }|td|q|s|rG|td||f||_ d|_|d }||Wdn 1sAwYn|tdWddSWddS1sbwYdS)ztRebuilds the fncache file from repo history. Missing entries will be added. Extra entries will be removed. sE(not rebuilding fncache because repository does not support fncache) N)rrsdata/s.is.ds rebuildings changesets)unittotals data/%s.is data/%s.dsmeta/%s/00manifest.ismeta/%s/00manifest.ds removing %s s adding %s s(%d items added, %d removed from fncache Tsfncachesfncache already up to date )rprFNCACHE_REQUIREMENTrrlockrfncache ensureloadedr(rrz_exists makeprogressrCrDrEcompleteTREEMANIFEST_REQUIREMENTrdirsr)write_dirtyr)r0r1 only_datafnc oldentries newentries seenfilesrdatafprogressrZctxradraddcount removecountr^rrrrrebuildfncaches                        $r c Cs|sdSg}|j}d}t|D]\}}||vr|d7}q||q|jdddd}t|d|jD]}||q2||S)aDelete some obsmarkers from obsstore and return how many were deleted 'indices' is a list of ints which are the indices of the markers to be deleted. Every invocation of this function completely rewrites the obsstore file, skipping the markers we want to be removed. The new temporary file is created, remaining markers are written there and on .close() this file gets atomically renamed to obsstore, thus guaranteeing consistency.NrrsobsstorewT) atomictemp) _allrrrr encodemarkers_versionrr) rindicesleftcurrentrrarbnewobsstorefilerurrrrs   r)TT)TrY)NT)F)* __future__rri18nrr4rrrrr r r r r rrrrrrutilsrrrrArHrSrXrrrrrobjectrrrrTr rrrrrs.  < 3   A   \