o ]Lb,@sZdZddlmZddlZddlZddlmZddlmZm Z m Z m Z m Z ddl mZmZddlmZm Z mZmZmZmZe jrndd lmZmZmZmZmZmZmZmZdd lm Z m!Z"ee#ee$fZ%eee j&e%ge%fZ'e(d Z)e*d \Z+Z,Z-d Z.dZ/e+e,e-e.e/fZ0e,e-e.e/fZ1gdZ2e3e4e2Z5de5e.<de5e/<dde56DZ7e78Z9e9:dde5De9:dde5De,e-e.e/fZ;e-e.e/fZd@ddZ?ddZ@ddZAddZBd d!ZCd"d#ZDGd$d%d%eEZFdAd&d'ZGd(d)ZHd*d+ZId,d-ZJd.d/ZKd0d1ZLd2d3ZMd4d5ZNGd6d7d7eEZOd8d9ZPd:d;ZQdd?ZSdS)Ba Mercurial phases support code --- Copyright 2011 Pierre-Yves David Logilab SA Augie Fackler This software may be used and distributed according to the terms of the GNU General Public License version 2 or any later version. --- This module implements most phase logic in mercurial. Basic Concept ============= A 'changeset phase' is an indicator that tells us how a changeset is manipulated and communicated. The details of each phase is described below, here we describe the properties they have in common. Like bookmarks, phases are not stored in history and thus are not permanent and leave no audit trail. First, no changeset can be in two phases at once. Phases are ordered, so they can be considered from lowest to highest. The default, lowest phase is 'public' - this is the normal phase of existing changesets. A child changeset can not be in a lower phase than its parents. These phases share a hierarchy of traits: immutable shared public: X X draft: X secret: Local commits are draft by default. Phase Movement and Exchange =========================== Phase data is exchanged by pushkey on pull and push. Some servers have a publish option set, we call such a server a "publishing server". Pushing a draft changeset to a publishing server changes the phase to public. A small list of fact/rules define the exchange of phase: * old client never changes server states * pull never changes server states * publish and old server changesets are seen as public by client * any secret changeset seen in another repository is lowered to at least draft Here is the final table summing up the 49 possible use cases of phase exchange: server old publish non-publish N X N D P N D P old client pull N - X/X - X/D X/P - X/D X/P X - X/X - X/D X/P - X/D X/P push X X/X X/X X/P X/P X/P X/D X/D X/P new client pull N - P/X - P/D P/P - D/D P/P D - P/X - P/D P/P - D/D P/P P - P/X - P/D P/P - P/D P/P push D P/X P/X P/P P/P P/P D/D D/D P/P P P/X P/X P/P P/P P/P P/P P/P P/P Legend: A/B = final state on client / state on server * N = new/not present, * P = public, * D = draft, * X = not tracked (i.e., the old client or server has no internal way of recording the phase.) passive = only pushes A cell here can be read like this: "When a new client pushes a draft changeset (D) to a publishing server where it's not present (N), it's marked public on both sides (P/P)." Note: old client behave as a publishing server with draft only content - other people see it as public - content is pushed as draft )absolute_importN)_)binhexnullrevshortwdirrev)getattrsetattr)errorpycompat requirementssmartsettxnutilutil)AnyCallableDictIterableListOptionalSetTuple) localrepouis>i20s `)spublicsdraftssecretsarchivedsinternalcCsi|]\}}||qSr).0phasenamerr2/usr/lib/python3/dist-packages/mercurial/phases.py r$cCsi|]}||qSrrr r!rrr#r$cCsi|]}d||qS)%irr&rrr#r$r%cCs tj|jvS)z6True if the internal phase can be used on a repository)rINTERNAL_PHASE_REQUIREMENTreporrr#supportinternals r,c Cs|}d}ddtD}z2t|j|jd\}}z|D]}|\}}|t|t |qW| n| wW||fSt yi} z| j t j krN|rZ|D]}|||}qRd}WYd} ~ ||fSd} ~ ww)aRead phase roots from disk phasedefaults is a list of fn(repo, roots) callable, which are executed if the phase roots file does not exist. When phases are being initialized on an existing repository, this could be used to set selected changesets phase to something else than public. Return (roots, dirty) where dirty is true if roots differ from what is being stored. FcSi|]}|tqSrsetr irrr#r$z_readroots.. phaserootsTN) unfiltered allphasesr trypendingrootsvfssplitintaddrcloseIOErrorerrnoENOENT) r+ phasedefaultsdirtyrootsfpendingliner!nhinstrrr# _readrootss,    rHcCs>g}t|D]\}}|D] }|t||q qd|S)zwencode a 'phase -> nodes' mapping into a binary stream The revision lists are encoded as (phase, root) pairs. )r iteritemsappend _fphasesentrypackjoin) phasemapping binarydatar!nodesheadrrr# binaryencodes  rScCsbddtD}tj} ||}t||kr"|rttd |St|\}}|| |q )zdecode a binary stream into a 'phase -> nodes' mapping The (phase, root) pairs are turned back into a dictionary with the phase as index and the aggregated roots of that phase as value.cSi|]}|gqSrrr0rrr#r$r'z binarydecode..Tsbad phase-heads stream) r5rLsizereadlenr AbortrunpackrK)stream headsbyphase entrysizeentryr!noderrr# binarydecodes  r_c Cs d}|r||d\}}|dd|ko||k}d}|t|kr2||\}} |d|dko1| |k}|rO|rOt|d|dd|f||d<||dS|rct|d|d|f||d<dS|rut||dd|f||<dS||t||d|fdS)NFrr)rWr xrangepopinsert) dataidxrevt merge_beforer1t1 merge_afterr2t2rrr#_sortedrange_inserts   $$  rncCs||\}}||kr dS|d|df}t|dkr(||t||||dS|d|krGt|d|dd|f||<t||||dS|d|krdt|d||f||<t||d||dSt|d||ft||d|ft|d|dd|fg|||d<dS)Nrrr`)rWrbrnr ra)rdrerfrgrirjrrr#_sortedrange_split s"      roc Cs|durdS|s|dt||d||ffdSd}t|}||f}||kr||d}||d}|d} |d} || krM|| krMt||||dS| |dkru|rl||ddd|krlt||d||dSt||||dS| |dkr|dt|kr||ddd|krt||d||dSt||d||dS| |kr|}n|d}||ks(|t|kr|t||d|fdS||\} } | d|kr||t||d|fdS||dt||d|fdS)zYadd a phase move to the list of ranges If data is None, nothing happens. Nrrr`)rcr rarWrornrK) rdrfoldnewlowhighrgmidrevsrevs_low revs_highrirjrrr#_trackphasechange#sN     (    $ryc@seZdZd)ddZddZddZd*d d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZdd Z d+d!d"Zd#d$Zd*d%d&Zd'd(ZdS), phasecacheTcCs<|rt||\|_|_d|_d|_|||j|_dSdSNr)rH phaserootsrA_loadedrevslen _phasesets filterunknownr8opener)selfr+r@_loadrrr#__init__\s  zphasecache.__init__cCsH|}|j}t||jkr|||tddt|j DS)z3detect if there are revisions with non-public phasecss |] \}}|tkr|VqdSNpublicr r!rvrrr# nsz0phasecache.hasnonpublicphases..) r4 changelogrWr} invalidate loadphaserevsanyr rJr|rr+clrrr#hasnonpublicphasesfs  zphasecache.hasnonpublicphasescCsL|}|j}t||jkr|||tjddt |j DS)zreturns the roots of all non-public phases The roots are not minimized, so if the secret revisions are descendants of draft revisions, their roots will still be present. cSsg|] \}}|tkr|qSrrrrrr# s z2phasecache.nonpublicphaseroots..) r4rrWr}rrr/unionr rJr|rrrr#nonpublicphaserootsts  zphasecache.nonpublicphaserootsNcsttv}|rttstSdtdkr0\}j|dn tj fddDfdd}|sej j rPj j |durYt S|||t @S|durnt}||sw|S| fd d S) z&return a smartset for the given phasesFrTcsg|]}j|qSr)r~)r prrr#rr%z(phasecache.getrevset..cs2t|vrdvrr|}|t|Sr)r r!copyr;) wdirsubsetwdirrevs)phasesr+ revsneedscopyrr#_addwdirs  z&phasecache.getrevset.._addwdirNcs|vSrr)rrvrr#sz&phasecache.getrevset..)rr/rr5 differencer fullreposetrWr~rr filteredrevsbasesetfilter)rr+rsubset publicphaserrr)rr+rvrrr# getrevsets6          zphasecache.getrevsetcCs@|jdddd}|j|_|j|_|j|_|j|_|j|_|S)NF)r) __class__r|rrArr}r~)rphrrr#rs zphasecache.copycCs dD] }t||t||qdS)z4replace all values in 'self' with content of phcache)r3sdirtysopeners_loadedrevslens _phasesetsN)r r )rphcachearrr#replaceszphasecache.replacecCs|}|j|jSr)r4r computephasesr|)rr+rrr#_getphaserevsnativeszphasecache._getphaserevsnativecCs|}|j}ddtD|_t}ttD].}t|j |j |}|rDt| |}|D]}| |q-| |||||j|<qt||_dS)NcSr-rr.r&rrr#r$r2z4phasecache._computephaserevspure..)r4rr5r~r/reversed trackedphasesr maplistrfr| descendantsr;difference_updateupdaterWr})rr+r lowerrootsr!rBpsr7rrr#_computephaserevspures     z phasecache._computephaserevspurecCsJ|jdur#z||}|\|_|_WdSty"||YdSwdS)z0ensure phase information is loaded in the objectN)r~rr}AttributeErrorr)rr+resrrr#rs   zphasecache.loadphaserevscCsd|_d|_dSr{)r}r~rrrr#rs zphasecache.invalidatecCs`|tkrtS|tkrttd||jkr|||tD] }||j|vr-|Sq tS)Nscannot lookup negative revision) rr ValueErrorrr}rrrr~)rr+rfr!rrr#r!s   zphasecache.phasecCs@|jsdS|jddddd}z ||W|dS|w)Nr3wT) atomictemp checkambig)rAr_writer<)rrCrrr#write s  zphasecache.writecCsDt|jD]\}}t|D] }|d|t|fqqd|_dS)Ns%i %s F)r rJr|sortedrrrA)rfpr!rBhrrr#rs   zphasecache._writecCs6||j|<|d|_|dd|jd|jd<dS)NTphase)r31s phases_moved)r|rrAaddfilegeneratorrhookargs)rr!newrootstrrrr# _updaterootss zphasecache._updaterootsc Csp|}|j|||g|d|dur2d|jvr2|jd}|j}t|D]}|||}t||d|q#|dS)Nrphases)r4_retractboundarychangesr!rryinvalidatevolatilesets) rr+r targetphaserv phasetrackingr!rfrevphaserrr# registernew!s    zphasecache.registernewc s:|durg}|dur d}n|jd}fdd|Ddd|D}t}g} fddtDD]Sfdd|D}|sFnCj} d | |} || |rZq5| D] } t||  | q\d d d | | D} | | kr | || | | q5|sd kr ||  |S)zSet all 'nodes' to phase 'targetphase' Nodes with a phase lower than 'targetphase' are not affected. If dryrun is True, no actions will be performed Returns a set of revs whose phase is changed or should be changed Nrcsg|]}|qSrrfr nr*rr#rAz.phasecache.advanceboundary..cSg|]}|qSrrr rrrr#rAc3s|] }|kr|VqdSrrr&rrr#rEz-phasecache.advanceboundary..cs g|] }|kr|qSrr!r rf)r!r+rrr#rGs %ln::%ldcSsh|]}|qSrr^)r ctxrrr# Vsz-phasecache.advanceboundary..sroots((%ln::) - %ld)r)rgetr4r/r5r|rvrryr!rextendrr)rr+rrrQrvdryrunrrdelrootsoldsaffectedrrBr)r!r+rrr#advanceboundary,sD      zphasecache.advanceboundarycsfddt|jD}|durd}n|jd}|}||||rl|durl|j}|}t|d||} t ddD](} | r[|| g} t|d| | } | | 8} n| } t | D] } t || | qaqC| dS)Ncsi|] \}}|kr||qSrrrrrr#r$fs z.phasecache.retractboundary..rs(%ln::) - (%ln::)r`r) r rJr|rrr4rr/rvrarryr)rr+rrrQoldrootsrrrrqrr!rBrvrrrr#retractboundaryes.        zphasecache.retractboundarycs>|durg}ttfvrtst}d|}t|jjjj fddj D}t |} } fdd|Ddd|D} fdd| D} | rt | vrct td|| t| fd d|D} d | } fd d|D} | | | | krfd d| D|d SdS)Ns-this repository does not support the %s phasech|]}|qSrrr r^torevrr#rr2z.phasecache._retractboundary..cg|]}|qSrrrrrr#rr2z/phasecache._retractboundary..cSrrrrrrr#rrcs g|] }|kr|qSrrr)r+rrrr#rss!cannot change null revision phasecsg|]}|kr|qSrrr minnewrootrr#rrs roots(%ld::)csh|]}|kr|qSrrrrrr#rrcrrrr)tonoderr#rr2TF)archivedinternalr, phasenamesr ProgrammingErrorr4rrfr^r|r/rrXrrminrvr)rr+rrrQrvr"msg currentroots finalrootsrr aboveroots updatedrootsr)rr+rrrrr#rs<      zphasecache._retractboundarycsd}|jjjt|jD])\}}tfdd|D}|r6|D]}|jdt ||fq | |d}q |r.s0removing unknown node %s from %i-phase boundary TN) rindexrr rJr|rrdebugrsymmetric_difference_updaterAr)rr+filteredr!rQmissingmnoderrr#rs"    zphasecache.filterunknown)TrNN)__name__ __module__ __qualname__rrrrrrrrrrr!rrrrrrrrrrrr#rz[s*   7     9 ! (rzcCs@|durg}|j}|j||||||d}|s|j||S)auAdd nodes to a phase changing other nodes phases if necessary. This function move boundary *forward* this means that all nodes are set in the target phase or kept in a *lower* phase. Simplify boundary to contains phase roots only. If dryrun is True, no actions will be performed Returns a set of revs whose phase is changed or should be changed N)rvr) _phasecacherrr)r+rrrQrvrrrrrr#rs    rcC*|j}||||||j|dS)zSet nodes back to a phase changing other nodes phases if necessary. This function move boundary *backward* this means that all nodes are set in the target phase or kept in a *higher* phase. Simplify boundary to contains phase roots only.N)rrrr)r+rrrQrrrr#rs rcCr)zregister a new revision and its phase Code adding revisions to the repository should use this function to set new changeset in their target phase (or higher). N)rrrr)r+rrrvrrrr#rs rcCsdt}dt}|j}|jjtD]}|j|||tkr'||t |<q| r0d|d<|S)/List phases root for serialization over pushkeyr(sTrue publishing) rsortdictdraftr4rrr|r!rfr publishing)r+keysvaluerr7rrr# listphasess  rc Cs|}|Y||}tt|}tt|}||krK||krK|d}t|||t|gWdn1s=wY WddS||krX WddS WddS1sdwYdS)rs pushkey-phaseNTF)r4lockr!absr: transactionrr)r+nhex oldphasestr newphasestr currentphasenewphaseoldphaserrrr# pushphases       $rcsT|jddtD}tdtD]}dt|}fdd|||D||<q|S)zFinds the phase heads for a subset of a history Returns a list indexed by phase number where each item is a list of phase head nodes. cSrTrrr0rrr#r$7r'z$subsetphaseheads..Nsheads(%%ln & %s())csg|]}|qSrrrrrr#r<r%z$subsetphaseheads..)rr5secretrrv)r+rr[r!revsetrrr#subsetphaseheads/s   rcCsBtD]}d}dd|||||D}|rt||||qdS)z+Updates the repo with the given phase headss%ln - _phase(%s)cSg|]}|qSrrr crrr#rIr2z updatephases..N)r5r/r)r+trgetterr[r!rheadsrrr# updatephases@sr#c Cs|}g}|jjj}t|D]?\}}|dkrqt|}t|}|tkr5||j kr4|j t d|q|t krC||rB||q|j t d||fqt|||}||fS)zCompute phases heads and root in a subset of node from root dict * subset is heads of the subset * roots is { => phase} mapping. key and value are string. Accept unknown element input r s2ignoring inconsistent public root from remote: %s s,ignoring unexpected root from remote: %i %s )r4rrrr rJrr:rnullidrwarnrr rKnewheads) r+rrB draftrootsrrr!r^ publicheadsrrr#analyzeremotephasesNs:    r)c@seZdZdZddZdS)remotephasessummaryasummarize phase information on the remote side :publishing: True is the remote is publishing :publicheads: list of remote public phase heads (nodes) :draftheads: list of remote draft phase heads (nodes) :draftroots: list of remote draft phase root (nodes) cCsX|}||_|dd|_t|||}|\|_|_|d|j|}dd|D|_dS)Nr Fsheads(%ln::%ln)cSrrrrrrr#rr2z0remotephasessummary.__init__..) r4_allremoterootsrr r)r(r'r/ draftheads)rr+ remotesubset remoterootsunfianadheadsrrr#r~s  zremotephasessummary.__init__N)rrr__doc__rrrrr#r*us r*c sddlm}j}|jj|s|S|r|jgkrgSfdd|D}fdd|D}d||}||d||}||8}|sM|rd| |d |}| ||} || t |j t|S) zcompute new head of a subset minus another * `heads`: define the first subset * `roots`: define the second we subtract from the firstr)dagopcsh|] }|jkr|qSr)r$rr+rfrr#rsznewheads..crrrrrrr#rr2znewheads..s (%ld::%ld)s-parents(%ld + (%ld and merge())) and not nullsparents(%ld) and not null)r3r4rrget_revr$rvrrreachablerootsr rr^r) r+r"rBr3r new_heads affected_zone candidates prunestartprunedrr4r#r&s,     r&cCs8|dd}zt|WStyttd|w)zuhelper to get the target phase of new commit Handle all possible values for the phases.new-commit options. rs new-commits0phases.new-commit: not a valid phase name ('%s'))config phasenumber2KeyErrorr ConfigErrorr)rvrrr#newcommitphases    rBcCst|jjtS)z@utility function that check if a repo have any secret changeset.)boolrr|rr*rrr# hassecretsrDcCs&|durd}nt|}||t|dS)NrI)snodesoldphaser)r)r^rqrrrrr#preparehookargssrErr)Tr2 __future__rr>structi18nrr^rrrrr r r r r5r rrrr TYPE_CHECKINGtypingrrrrrrrrrruimodr:bytes Phaserootslocalrepository PhasedefaultsStructrLrangerr rrrr5r cmdphasenamesdict enumerateritems phasenumberrr>r mutablephasesremotehiddenphaseslocalhiddenphasesr,rHrSr_rnroryobjectrzrrrrrrr#r)r*r&rBrDrErrrr#sn f   (       ! 8 t   ''