o ]Lb@sddlmZddlmZddlmZmZmZmZm Z m Z ddl m Z ej r-ddlmZmZejejejejhZddZd Zd ZGd d d eZgZd dZGdddeZGdddeZeGdddeZeGdddeZ eGdddeZ!eGdddeZ"eGdddeZ#eGdddeZ$eGdd d eZ%eGd!d"d"eZ&eGd#d$d$eZ'eGd%d&d&eZ(eGd'd(d(eZ)eGd)d*d*eZ*d+e j+voe j+d+,oe j+d+-Z.eGd,d-d-eZ/eGd.d/d/eZ0d0d1Z1d2d3Z2gZ3d4d5Z4Gd6d7d7eZ5e4Gd8d9d9e5Z6e4Gd:d;d;e5Z7e4Gdd?d?e5Z9d@dAZ:dBdCZ;GdDdEdEeZdJdKZ?dLdMZ@dNdOZAdPdQZBdRdSZCdTdUZDdVS)W)absolute_import)_)error localrepopycompat requirementsrevlogutil) compression)ListTypecCstjh}||j@SN)rSHARED_REQUIREMENT)repo preservedrA/usr/lib/python3/dist-packages/mercurial/upgrade_utils/actions.pypreservedrequirements&s rs deficiencys optimizationc@sDeZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdS) improvementzARepresents an improvement that can be made as part of an upgrade.NTF)__name__ __module__ __qualname____doc__typename descriptionupgrademessagedefaultpostupgrademessagepostdowngrademessagetouches_filelogstouches_manifeststouches_changelogtouches_requirementstouches_dirstatecompatible_with_sharerrrrr1s rcCt||Sr)allformatvariantappend)clsrrrregisterformatvariantn r+c@s,eZdZdZeZeddZeddZdS) formatvariantz6an improvement subclass dedicated to repository formatcCt)z.current value of the variant in the repositoryNotImplementedErrorrrrrfromrepoxzformatvariant.fromrepocCr.)z1current value of the variant in the configurationr/r1rrr fromconfig}r3zformatvariant.fromconfigN) rrrrFORMAT_VARIANTr staticmethodr2r4rrrrr-ss r-c@s8eZdZdZdZeddZeddZeddZ dS) requirementformatvariantzformatvariant based on a 'requirement' name. Many format variant are controlled by a 'requirement'. We define a small subclass to factor the code. NcCst|t|Sr)rnewreporequirementsdefaultcreateopts)uirrr_newreporequirementss z-requirementformatvariant._newreporequirementscCs|jdusJ|j|jvSr) _requirementrr*rrrrr2s z!requirementformatvariant.fromrepocCs |jdusJ|j||jvSr)r<r;r:r=rrrr4sz#requirementformatvariant.fromconfig) rrrrr<r6r; classmethodr2r4rrrrr7s  r7c@*eZdZdZejZdZedZ edZ dS)fncachesfncacheTsYlong and reserved filenames may not work correctly; repository performance is sub-optimalssrepository will be more resilient to storing certain paths and performance of certain operations should be improvedN) rrrrrFNCACHE_REQUIREMENTr<rrrrrrrrr@r@c@BeZdZdZejZdZedZ edZ dZ dZ dZ dZdZdZdS) dirstatev2s dirstate-v2Fsversion 1 of the dirstate file format requires reading and parsing it all at once. Version 2 has a better structure,better information and lighter update mechanisms"hg status" will be fasterTN)rrrrrDIRSTATE_V2_REQUIREMENTr<rrrrr!r"r#r$r%r&rrrrrDsrDc@rC)dirstatetrackedkeys tracked-hintFsDAdd a small file to help external tooling that watch the tracked setsHexternal tools will be informated of potential change in the tracked setTN)rrrrrDIRSTATE_TRACKED_HINT_V1r<rrrrr!r"r#r$r%r&rrrrrFs rFc@r?) dotencodes dotencodeTsLstorage of filenames beginning with a period or space may not work correctlysNrepository will be better able to store files beginning with a space or periodN) rrrrrDOTENCODE_REQUIREMENTr<rrrrrrrrrHrBrHc@r?) generaldeltas generaldeltaTsdeltas within internal storage are unable to choose optimal revisions; repository is larger and slower than it could be; interaction with other repositories may require extra network and CPU resources, making "hg push" and "hg pull" slowersrepository storage will be able to create optimal deltas; new repository data will be smaller and read times should decrease; interacting with other repositories using this storage model should require less network and CPU resources, making "hg push" and "hg pull" fasterN) rrrrrGENERALDELTA_REQUIREMENTr<rrrrrrrrrJsrJc@sJeZdZdZejZdZedZ edZ edZ edZ dZ dZdZdZdS) sharesafes share-safeTsold shared repositories do not share source repository requirements and config. This leads to various problems when the source repository format is upgraded or some new extensions are enabled.swUpgrades a repository to share-safe format so that future shares of this repository share its requirements and configs.sirepository downgraded to not use share safe mode, existing shares will not work and needs to be reshared.srepository upgraded to share safe mode, existing shares will still work in old non-safe mode. Re-share existing shares to use them in safe mode New shares will be created in safe mode.FN)rrrrrSHARESAFE_REQUIREMENTr<rrrrr rr!r"r#r$rrrrrLs(rLc@r?) sparserevlogs sparserevlogTsXin order to limit disk reading and memory usage on older version, the span of a delta chain from its root to its end is limited, whatever the relevant data in this span. This can severly limit Mercurial ability to build good chain of delta resulting is much more storage space being taken and limit reusability of on disk delta during exchange.sRevlog supports delta chain with more unused data between payload. These gaps will be skipped at read time. This allows for better delta chains, making a better compression and faster exchange with server.N) rrrrrSPARSEREVLOG_REQUIREMENTr<rrrrrrrrrN6s rNc@r?)persistentnodemapspersistent-nodemapFs9persist the node -> rev mapping on disk to speedup lookups#Speedup revision lookup by node id.N) rrrrrNODEMAP_REQUIREMENTr<rrrrrrrrrPPs rPc@r?) copiessdcs copies-sdcFs/Stores copies information alongside changesets.sAAllows to use more efficient algorithm to deal with copy tracing.N) rrrrrCOPIESSDC_REQUIREMENTr<rrrrrrrrrR_srRc@r?)revlogv2s revlog-v2FsVersion 2 of the revlog.svery experimentalN) rrrrrREVLOGV2_REQUIREMENTr<rrrrrrrrrTn  rTc@r?) changelogv2s changelog-v2Fs7An iteration of the revlog focussed on changelog needs.squite experimentalN) rrrrrCHANGELOGV2_REQUIREMENTr<rrrrrrrrrWwrVrWc@<eZdZdZdZedZedZeddZ eddZ d S) removecldeltachainsplain-cl-deltaTschangelog storage is using deltas instead of raw entries; changelog reading and any operation relying on changelog data are slower than they could beszchangelog storage will be reformated to store raw entries; changelog reading will be faster; changelog size may be reducedcs"|j}|jtfdd|DS)Nc3s|] }||kVqdSrr).0rev chainbaserr z.removecldeltachain.fromrepo..) changelogr^all)rclrr]rr2szremovecldeltachain.fromrepocCsdSNTrr1rrrr4szremovecldeltachain.fromconfigN) rrrrrrrrr6r2r4rrrrrZs rZzstdc@sFeZdZdZer dZndZedZedZe ddZ e dd Z d S) compressionengine compressionrezlibsMCompresion algorithm used to compress data. Some engine are faster than others;revlog content will be recompressed with the new algorithm.cCs:d}|jD]}|j}|ds|dr|ddd}q|S)Nrhsrevlog-compression-sexp-compression--r)r startswithsplit)r*rr reqprefixrrrr2s zcompressionengine.fromrepocCsN|jdd}|D]}|tjvr!tj|}|r!|r!|Sq d|S)Nsformatsrevlog-compression,)r: configlistr compengines available revlogheaderjoin)r*rrpcomperrrr4s   zcompressionengine.fromconfigN) rrrr _has_zstdrrrrr>r2r4rrrrrfs  rfc@rY) compressionlevelscompression-leveldefaultscompression levels#revlog content will be recompressedcCPt|}d}|dkr|jdd}n |dkr|jdd}|dur$dSt|SNrhsstoragesrevlog.zlib.levelresrevlog.zstd.levelrx)rfr2r: configintbytesr*rrtlevelrrrr2 zcompressionlevel.fromrepocCryrz)rfr4r:r{r|r}rrrr4rzcompressionlevel.fromconfigN) rrrrrrrrr>r2r4rrrrrws  rwcCs&g}tD] }||s||q|S)zBreturns a list of format upgrades which can be perform on the repo)r(r2r))rupgradesfvrrrfind_format_upgradess   rcCsZg}tD]&}|jdkr||||kr||q||r*||s*||q|S)zvreturns a list of format downgrades which will be performed on the repo because of disabled config option for themrg)r(rr2r4r))r downgradesrrrrfind_format_downgradess   rcCr'r)ALL_OPTIMISATIONSr))objrrrregister_optimizationr,rc@seZdZdZeZdS) optimizationz2an improvement subclass dedicated to optimizationsN)rrrr OPTIMISATIONrrrrrr#src@$eZdZdZeZedZedZdS)redeltaparentsre-delta-parents]deltas within internal storage will be recalculated to choose an optimal base revision where this was not already done; the size of the repository may shrink and various operations may become faster; the first time this optimization is performed could slow down upgrade execution considerably; subsequent invocations should not run noticeably slowersHdeltas within internal storage will choose a new base revision if neededN rrrrrrrrrrrrrr)s rc@r)redeltamultibasere-delta-multibasesdeltas within internal storage will be recalculated against multiple base revision and the smallest difference will be used; the size of the repository may shrink significantly when there are many merges; this optimization will slow down execution in proportion to the number of merges in the repository and the amount of files in the repository; this slow down should not be significant unless there are tens of thousands of files and thousands of mergessdeltas within internal storage will choose an optimal delta by computing deltas against multiple parents; may slow down execution time significantlyNrrrrrr?s rc@r) redeltaall re-delta-allsdeltas within internal storage will always be recalculated without reusing prior deltas; this will likely make execution run several times slower; this optimization is typically not neededsndeltas within internal storage will be fully recomputed; this will likely drastically slow down execution timeNrrrrrrYsrc@r)redeltafulladdre-delta-fulladdsevery revision will be re-added as if it was new content. It will go through the full storage mechanism giving extensions a chance to process it (eg. lfs). This is similar to "re-delta-all" but even slower since more logic is involved.seach revision will be added as new content to the internal storage; this will likely drastically slow down execution time, but some extensions might need itNrrrrrrmsrcCsttS)z8Determine optimisation that could be used during upgrade)listrr1rrrfindoptimizationssrcsbg|D]}t|dr|j}nd}|dur||vrq|qfddt|DS)aDetermine upgrade actions that will be performed. Given a list of improvements as returned by ``find_format_upgrades`` and ``findoptimizations``, determine the list of upgrade actions that will be performed. The role of this function is to filter improvements if needed, apply recommended optimizations from the improvements list that make sense, etc. Returns a list of action names. r<Nc3s|] }|vr|VqdSrr)r[o newactionsrrr_r`z,determine_upgrade_actions..)r safehasattrr<r)extendsorted)rformat_upgrades optimizations sourcereqsdestreqsdrrrrdetermine_upgrade_actionss  rc@seZdZdZddZeddZeddZedd Zed d Z ed d Z eddZ eddZ ddZ ddZddZddZddZddZddZd d!Zd"S)#UpgradeOperationz/represent the work to be done during an upgradec s|_|_|_|_|_|_jj_jj_jj@_t d}fdd|D_ j } t j j _d| vrGt j j_nd| vrQt j j_nd| vr[t j j_n d| vrdt j j_d| v_|_dS)Ncsg|] }|jvr|qSr)upgrade_actions)r[iselfrr z-UpgradeOperation.__init__..rrrr)r:new_requirementscurrent_requirementsrremoved_actionsrevlogs_to_process_added_requirements_removed_requirements_preserved_requirementsrunused_optimizationsupgrade_actions_namesr DELTAREUSEALWAYSdelta_reuse_modeDELTAREUSENEVERDELTAREUSESAMEREVSDELTAREUSEFULLADDforce_re_delta_both_parents backup_store) rr:rrrrrrall_optimizationsrrrr__init__s:           zUpgradeOperation.__init__cCstdd|jDS)NcSg|]}|jqSrrr[arrrrz:UpgradeOperation.upgrade_actions_names..)setrrrrrrsz&UpgradeOperation.upgrade_actions_namescCs&|jo|j o|j o|j o|j Sr)r$r!r"r#r%rrrrrequirements_onlysz"UpgradeOperation.requirements_onlycCD|jD]}|jtkr dS|jrdSq|jD]}|jrdSqdSNTF)rrrr!rrrrrrr!   z!UpgradeOperation.touches_filelogscCrr)rrrr"rrrrrr"rz"UpgradeOperation.touches_manifestscCrr)rrrr#rrrrrr#rz"UpgradeOperation.touches_changelogcCs@|jD]}|jtkr q|jrdSq|jD]}|jrdSqdSrd)rrrr$rrrrrr$!s   z%UpgradeOperation.touches_requirementscCs@|jD]}|jtkr q|jrdSq|jD]}|jrdSqdSr)rrrr%rrrrrr%.s   z!UpgradeOperation.touches_dirstatecCs:d}t|D]}|s|jd|jj||dd}qdS)zK Utility function to aid writing of a list under one label T, )labelFN)rr:write)rlrfirstrrrr_write_labeled<s  zUpgradeOperation._write_labeledcCs|jtd|jtd||jd|jd|jr5|jtd||jd|jd|jrM|jtd||jd|jd|jddS) Ns requirements s preserved: z"upgrade-repo.requirement.preserved s removed: z upgrade-repo.requirement.removeds added: zupgrade-repo.requirement.added)r:rrrrrrrrrrprint_requirementsGs&   z#UpgradeOperation.print_requirementscCs^dd|jD}|jddd|r-|jtd|dd|Dd|jd dSdS) NcSsg|] }|jtkr|qSr)rrrrrrr]rz8UpgradeOperation.print_optimisations..cSs|jSrr)rrrr`sz6UpgradeOperation.print_optimisations..)keysoptimisations: cSrrrrrrrrdrz#upgrade-repo.optimisation.performeds )rsortr:rrr)r optimisationsrrrprint_optimisations\s z$UpgradeOperation.print_optimisationscCs(|jD]}|jd|j|jfqdSNs %s %s )rr:statusrrrrrrprint_upgrade_actionsis z&UpgradeOperation.print_upgrade_actionscCsP|js |jdn|jdt|jD] }|jd|q|jddS)Nsno revlogs to process sprocessed revlogs: s - %s r)rr:rr)rrrrrprint_affected_revlogsms  z'UpgradeOperation.print_affected_revlogscCs,|jD]}|jtd|j|jfqdSr)rr:rrrr)rrrrrprint_unused_optimizationsvs z+UpgradeOperation.print_unused_optimizationscCs ||jvS)zcannot upgrade repository; share repository without share-safes-check :hg:`help config.format.use-share-safe`)hintN) rrrrrsrrrrrrM) rrequired missingreqsrblocking blockingreqsm bad_sharehrrrcheck_source_requirementss*     rc Csvtjtjtjtjtjtjtjtjtj h }t j D]!}t j |}| r8| r8|d||dkr8|dq|S)zObtain requirements that can be removed during an upgrade. If an upgrade were to create a repository that dropped a requirement, the dropped requirement must appear in the returned set for the upgrade to be allowed. exp-compression-%srerevlog-compression-zstd)rrOrSrQrMrUrXrrGrEr rprqrraddrr supportedrenginerrrsupportremovedrequirementss$   rcCstjtjtjtjtjtjtjtjtj tj tj tj tj tjh}tjD]!}tj|}|rB|rB|d||dkrB|dq!|S)zObtain requirements that upgrade supports in the destination. If the result of the upgrade would create requirements not in this set, the upgrade is disallowed. Extensions should monkeypatch this to add their custom requirements. rrer)rrXrSrGrErIrArKrQrrUrrMrOrr rprqrrrrrrrrsupporteddestrequirementss.     rc Cstjtjtjtjtjtjtjtjtj tj tj tj h }t jD]!}t j|}|r>|r>|d||dkr>|dq|S)aObtain requirements that can be added to a repository during upgrade. This is used to disallow proposed requirements from being added when they weren't present before. We use a list of allowed requirement additions instead of a list of known bad additions because the whitelist approach is safer and will prevent future, unknown requirements from accidentally being added. rrer)rrIrArKrOrSrQrMrrUrXrGrEr rprqrrrrrrrrallowednewrequirementss*     rc Cs|j}t|jt|}|||}|r&td}dt|}t||t|}|||}|rDtd}dt|}t||t |} || } | r`td}dt| } t|| dS)Ns;cannot upgrade repository; requirement would be removed: %srs>cannot upgrade repository; do not support adding requirement: sEcannot upgrade repository; do not support destination requirement: %s) rrrrrsrrrrr) rnew_reqsold_reqssupport_removalno_remove_reqsrsupport_addition no_add_reqsrrunsupported_reqsrrrcheck_requirements_changes/s.   rN)E __future__ri18nrrrrrr r utilsr TYPE_CHECKINGtypingr r rKrOrUrXRECLONES_REQUIREMENTSrr5robjectrr(r+r-r7r@rDrFrHrJrLrNrPrRrTrWrZrprqrrrvrfrwrrrrrrrrrrrrrrrrrrrrrrrrs    :&  ,!&\   ! !