^cPdZddlZddlmZddlmZmZmZmZm Z ddl m Z m Z ddl mZm Z mZmZmZmZe jrCddlmZmZmZmZmZmZmZmZdd l mZmZee ee!fZ"eeej#e"ge"fZ$ej%d Z&e'd \Z(Z)Z*d Z+d Z,e(e)e*e+e,fZ-e)e*e+e,fZ.gdZ/e0e1e/Z2de2e+<de2e,<de23DZ4e45Z6e67de2De67de2De)e*e+e,fZ8e*e+e,fZ9e,e+fZ:dZ;dZdZ?dZ@dZAdZBGddZCd-dZDdZEd ZFd!ZGd"ZHd#ZId$ZJd%ZKGd&d'ZLd(ZMd)ZNd*ZOd+ZPdS).a 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 N)_)binhexnullrevshortwdirrev)getattrsetattr)errorpycompat requirementssmartsettxnutilutil)AnyCallableDictIterableListOptionalSetTuple) localrepouis>i20s `)spublicsdraftssecretsarchivedsinternalci|]\}}|| Sr ).0phasenames 2/usr/lib/python3/dist-packages/mercurial/phases.py r%sAAA{udtUAAAci|]}||Sr r r!r"s r$r%r%s:::eUE:::r&ci|]}d|z| S)%ir r(s r$r%r%sBBBeUU]EBBBr&c(tj|jvS)z6True if the internal phase can be used on a repository)rINTERNAL_PHASE_REQUIREMENTrepos r$supportinternalr/  2d6G GGr&c(tj|jvS)z6True if the archived phase can be used on a repository)rARCHIVED_PHASE_REQUIREMENTr-s r$supportarchivedr3r0r&c|}d}dtD} tj|j|jd\}} |D]N}|\}}|t|t|O | n#| wxYwn%#t$r|r|D]}|||}d}YnwxYw||fS)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. Fc,i|]}|tSr setr!is r$r%z_readroots..s ) ) )!Q ) ) )r& phaserootsT) unfiltered allphasesr trypendingrootsvfssplitintaddrcloseFileNotFoundError) r. phasedefaultsdirtyrootsfpendingliner"nhs r$ _readrootsrLs ??  D E ) )y ) ) )E ' 49mLL 7  / / JJLL rc%jj!%%c"gg.... / GGIIIIAGGIIIII   '" ' '$  %<s*#C AB4C4C  CC0/C0cg}|D]8\}}|D]0}|t||19d|S)zwencode a 'phase -> nodes' mapping into a binary stream The revision lists are encoded as (phase, root) pairs. r&)itemsappend _fphasesentrypackjoin) phasemapping binarydatar"nodesheads r$ binaryencoderWsu J$**,,?? u ? ?D   m00== > > > > ? 88J  r&cLdtD}tj} ||}t ||kr$|r!t jtdn9t|\}}|| ||S)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.ci|]}|gSr r r8s r$r%z binarydecode..---aAr---r&Tsbad phase-heads stream) r<rPsizereadlenr AbortrunpackrO)stream headsbyphase entrysizeentryr"nodes r$ binarydecoderes .-9---L"I) I&& u:: ! ! @k!$=">">??? #**511 tU""4((() r&c"d}|r#||dz \}}|ddz|ko||k}d}|t|kr ||\}} |d|dzko| |k}|r@|r>t|d|ddz|f||dz <||dS|r#t|d|dz|f||dz <dS|r t||ddz|f||<dS||t||dz|fdS)NFrr)r]rangepopinsert) dataidxrevt merge_beforer1t1 merge_afterr2t2s r$_sortedrange_insertrusJL 5cAgB"vzS(4R1W K SYYcBesQw&227 3 3r!ubfqj1115S1W   3r!ucAg..2S1W 332 ++Q/S  C%S1W--q122222r&cf||\}}||krdS|d|df}t|dkr)||t||||dS|d|kr5t|dz|ddz|f||<t||||dS|d|kr2t|d||f||<t||dz||dSt|d||ft||dz|ft|dz|ddz|fg|||dz<dS)Nrrrg)r]rirurh)rkrlrmrnrprqs r$_sortedrange_splitrws^ #YFBBww A! A 2ww!||  D#sA..... A#37BrFQJ//4S D#sA..... B32a5#&&+S D#'3222222a5#   # 3a ! $ 37BrFQJ ' ' , S37]r&c|dS|s-|dt||dz||ffdSd}t|}||f}||kr||zdz}||d}|d} |d} || kr|| krt||||dS| |dzkrG|r1||dz dd|krt||dz ||nt ||||dS| |dz kr^|dzt|kr1||dzdd|krt||dz||nt ||dz||dS| |kr|}n|dz}||k|t|kr*|t||dz|fdS||\} } | d|kr+||t||dz|fdS||dzt||dz|fdS)zYadd a phase move to the list of ranges If data is None, nothing happens. Nrrrg)rjrhr]rwrurO) rkrmoldnewlowhighrnmidrevsrevs_low revs_highrprqs r$_trackphasechanger%s{  |  Ac37++c3Z8999 C t99D c A **TzaCy|7H (??si// tS#q 1 1 1 F sQw   7tC!G}Q'+s22"4q#q9999#D#sA666 F a  QwT""tC!G}Q'7':c'A'A"4q#q9999#D#'3::: F c>>DD'C7 **: c$ii U3a((!,--- #YFB !us{{ C%S1W--q122222 C!GeCq111566666r&ceZdZddZdZdZddZdZdZd Z d Z d Z d Z d Z dZdZdZdZ ddZdZddZdZdS) phasecacheTc|rNt||\|_|_d|_d|_|||j|_dSdSNr)rL phaserootsrF_loadedrevslen _phasesets filterunknownr?opener)selfr.rE_loads r$__init__zphasecache.__init__^s\  $*4T=*I*I 'DOTZ"#D "DO   t $ $ $)DKKK  $ $r&c|}|j}t||jkr)|||t d|jDS)z3detect if there are revisions with non-public phasec36K|]\}}|tk|VdSNpublicr!r"rs r$ z0phasecache.hasnonpublicphases..ps3   UDuD  r&) r; changelogr]r invalidate loadphaserevsanyrrNrr.cls r$hasnonpublicphaseszphasecache.hasnonpublicphaseshs   ^ r77d) ) ) OO      t $ $ $  $(O$9$9$;$;      r&c(|}|j}t||jkr)|||t jd|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. c.g|]\}}|tk|Sr rrs r$ z2phasecache.nonpublicphaseroots..s-E4F??"??r&) r;rr]rrrr7unionrrNrs r$nonpublicphaserootszphasecache.nonpublicphaserootsts   ^ r77d) ) ) OO      t $ $ $suu{#'?#8#8#:#:  r&Ncttv}|r=ttst jSdtdkr\}j|dntj fdDfd}|sTj j rj j z |t j S|||t j zS|t j}||s|S| fdS)z&return a smartset for the given phasesFrTc*g|]}j|Sr )r)r!prs r$rz(phasecache.getrevset..s BBBatq1BBBr&ct|vrLdvr0r|}|t|Sr)r r"copyrB) wdirsubsetwdirrevsphasesr. revsneedscopys r$_addwdirz&phasecache.getrevset.._addwdirsV*$$d)9)9););v)E)E /'}}H  W%%%Or&Nc |vSrr )rrs r$z&phasecache.getrevset..s 1D=r&)rr7rr< differencer fullreposetr]rrr filteredrevsbasesetfilter) rr.rsubset publicphaserrrrs ``` @@r$ getrevsetzphasecache.getrevsets 4   V&  2^^..v66F 2+D111 v;;!  CQ?1%D MM9BBBB6BBBCD        :~* :dn99~'---x-- 0 6 666~!-d338FD))D  ==!8!8!8!899 9r&c|ddd}|j|_|j|_|j|_|j|_|j|_|S)NF)r) __class__rrrFrrr)rphs r$rzphasecache.copys[^^D$e^ 4 4,,.. :K  /  r&c NdD]!}t||t||"dS)z4replace all values in 'self' with content of phcache)r:sdirtysopeners_loadedrevslens _phasesetsN)r r )rphcacheas r$replacezphasecache.replaces>  2 2A D!WWa00 1 1 1 1 2 2r&ch|}|j|jSr)r;r computephasesr)rr.s r$_getphaserevsnativezphasecache._getphaserevsnatives)  ~++DO<<.s???E5#%%???r&)r;rr<rr7reversed trackedphasesr maplistrmr descendantsrBdifference_updateupdater]r)rr.r lowerrootsr"rGpsr>s r$_computephaserevspurez phasecache._computephaserevspures   ^??Y???UU m,, , ,E$RVT_U-CDDE ,..//!!!DFF4LLLL$$Z000!!"%%%)+&!"ggr&c|jM ||}|\|_|_dS#t$r||YdSwxYwdS)z0ensure phase information is loaded in the objectN)rrrAttributeErrorr)rr.ress r$rzphasecache.loadphaserevssw ? " 1..t447:4#T___! 1 1 1**4000000 1 # "s$/AAc"d|_d|_dSr)rr)rs r$rzphasecache.invalidatesr&c$|tkrtS|tkrttd||jkr)|||tD]}||j|vr|cStS)Nscannot lookup negative revision) rr ValueErrorrrrrrr)rr.rmr"s r$r"zphasecache.phases '>>M ==QABBCC C $% % % OO      t $ $ $"  Edoe,,, - r&c|jsdS|dddd} |||dS#|wxYw)Nr:wT) atomictemp checkambig)rFr_writerC)rrHs r$writezphasecache.write saz  F KK tK N N  KKNNN GGIIIIIAGGIIIIs AA%c |jD]>\}}t|D])}|d|t |fz*?d|_dS)Ns%i %s F)rrNsortedrrrF)rfpr"rGhs r$rzphasecache._writesl O1133 7 7LE5E]] 7 7uc!ffo56666 7 r&c||j|<|d|_|dd|jd|jd<dS)NTphase)r:1s phases_moved)rrrFaddfilegeneratorrhookargs)rr"newrootstrs r$ _updaterootszphasecache._updaterootssR!)   H&6 DDD'+ O$$$r&c(|}||||g||Md|jvrD|jd}|j}t |D] }|||}t ||d|!|dS)N)rphases)r;_retractboundarychangesr"rrinvalidatevolatilesets) rr.r targetphaser phasetrackingr"rmrevphases r$ registernewzphasecache.registernew!s   dB RdCCC >i2:55Jy1MJEd|| F F 5s++!-dHEEEE ##%%%%%r&c |g}|d}n|jd}fd|Dd|Dz}t}g} fdtDD]ӊfd|D}|snj} d| |} || |rR| D](} t|| | )dd | | D} | | kr/ | || | | z |s2d 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 NrcDg|]}|Sr )rm)r!nr.s r$rz.phasecache.advanceboundary..As%---!Q ---r&cg|]}|Sr r r!rs r$rz.phasecache.advanceboundary..As0A0A0Aq0A0A0Ar&c3(K|] }|k|V dSrr )r!r"rs r$rz-phasecache.advanceboundary..Es-JJek6I6Ie6I6I6I6IJJr&cHg|]}|k|Sr r")r!rmr"r.rs r$rz.phasecache.advanceboundary..Gs1JJJC4::dC+@+@E+I+IC+I+I+Ir&%ln::%ldc6h|]}|Sr rd)r!ctxs r$ z-phasecache.advanceboundary..Vs0 r&sroots((%ln::) - %ld)r)rgetr;r7r<rrrrr"rextendrr)rr.rrrUrdryrunrrdelrootsoldsaffectedrrGr"s`` ` @r$advanceboundaryzphasecache.advanceboundary,s <D : MMJNN955M  ----u---0A0AD0A0A0AA%%JJJJJJJ . .EJJJJJJ4JJJD ?5)DyydD99H NN8 $ $ $   !!1djjq&9&9;88$;T8LLEu}}!!%333u --- *a%%dB XFFF  ' ' ) ) )r&c~fd|jD}|d}n|jd}|}||||r||j}|}t |d||} tddD]j} | r@|| g} t |d| | } | | z} n| } t| D]} t|| | k| dS)Nc(i|]\}}|k ||Sr r )r!r"rrs r$r%z.phasecache.retractboundary..fs4   t ## 4###r&rs(%ln::) - (%ln::)rgr) rrNrrr;rr7rrhrrr)rr.rrrUoldrootsrr{rzrr"rGrrs ` r$retractboundaryzphasecache.retractboundaryesv    #4466    : MMJNN955M    ! !$K ? ? L)/+.C;'C499%93DDEEH{B33 L L$$LL33EtyyeXFFGGD$HH#DLLA%mQ{KKKKL ##%%%%%r&cT|g}tkrtrtkr5ts&t}d|z}t j|jj jj fdj D}t|x} } fd|Dd|Dz} fd| D} | rt| vr!t jtd|| t#| fd|D} d| } fd |D} | | | | kr%fd | D|d Sd S) Ns-this repository does not support the %s phasec&h|] }|Sr r r!rdtorevs r$rz.phasecache._retractboundary..s!MMMd MMMr&c&g|] }|Sr r rs r$rz/phasecache._retractboundary..s!222DEE$KK222r&cg|]}|Sr r rs r$rz/phasecache._retractboundary..s5F5F5FAa5F5F5Fr&cHg|]}|k|Sr r)r!rmr.rrs r$rz/phasecache._retractboundary..s8   tzz$'<'<{'J'JC'J'J'Jr&s!cannot change null revision phasec g|] }|k| Sr r r!rm minnewroots r$rz/phasecache._retractboundary..s#KKK# 9J9J#9J9J9Jr&s roots(%ld::)c h|] }|k| Sr r r s r$rz.phasecache._retractboundary..s#JJJ#z9I9I#9I9I9Ir&c&h|] }|Sr r )r!rmtonodes r$rz.phasecache._retractboundary..s!@@@cffSkk@@@r&TF)internalr/archivedr3 phasenamesr ProgrammingErrorr;rrmrdrr7rr^rrminrr)rr.rrrUrr#msg currentroots finalrootsrr aboveroots updatedrootsrrrs`` ` @@@r$rzphasecache._retractboundarys <D 8 # ##D)) $h&&#D))'k*DBTIC(-- -  "$MMMM 0LMMM #L 1 11 X2222E2225F5F5F5F5FF      #     ,(""k!$H"I"IJJJ    ) ) )XJKKKKKKKJ99_jAALJJJJJJJJ   l + + +  ! !   @@@@Z@@@"   4ur&cpd}|jjj|jD]j\}}t fd|D}|rH|D].}|jdt||fz/| |d}k|rd|_ | dS)zremove unknown nodes from the phase boundary Nothing is lost as unknown nodes only hold data for their descendants. Fc32K|]}| |VdSrr )r!rdhas_nodes r$rz+phasecache.filterunknown..s0JJd88D>>JTJJJJJJr&s0removing unknown node %s from %i-phase boundary TN) rindexrrrNrrdebugrsymmetric_difference_updaterFr)rr.filteredr"rUmissingmnoders @r$rzphasecache.filterunknowns >'0 O1133 LE5JJJJeJJJJJG $EGMML <</011':::  DJ r&)TrNN)__name__ __module__ __qualname__rrrrrrrrrrr"rrrrrrrrr r&r$rr]sO$$$$       (5:5:5:5:n    2 2 2===&&& 111& ,,, & & &?C7777r&&&B++++Zr&rc|g}|j}|||||||}|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)rr) _phasecacherrr)r.rrrUrrrrs r$rrso |##%%G%% b+u4&G *   ))) Nr&c|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)r*rrr)r.rrrUrs r$rrsO##%%G D"k5999W%%%%%r&c|j}||||||j|dS)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)r*rrr)r.rrrrs r$rrsO ##%%G b+t444W%%%%%r&cjtj}dtz}|j}|jjtD]K}|j|||tkr||t|<L| rd|d<|S)/List phases root for serialization over pushkeyr*sTrue publishing) rsortdictdraftr;rr*rr"rmr publishing)r.keysvaluerr>s r$ listphasesr5s =??D EME    $B +E2$$   ! !$t 5 5 > >#DTO &"&] Kr&c $|}|5||}tt |}tt |}||kra||kr[|d5}t |||t|gdddn #1swxYwY ddddS||kr ddddS ddddS#1swxYwYdS)r.s pushkey-phaseNTF)r;lockr"absrA transactionrr)r.nhex oldphasestr newphasestr currentphasenewphaseoldphasers r$ pushphaser@!s ??  D   Dz'')) s;''((s;''(( 8 # #8(;(;!!"233 Arb(SYYK@@@ A A A A A A A A A A A A A A A        X % %                          sBA4D!C > D C DC D#D7DD  D c|jdtD}tdtD]7}dt|z}fd|||D||<8|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. ci|]}|gSr r r8s r$r%z$subsetphaseheads..<rZr&Nsheads(%%ln & %s())c:g|]}|Sr r)r!rrs r$rz$subsetphaseheads..As#MMMarwwqzzMMMr&)rr<secretrr)r.rrar"revsetrs @r$subsetphaseheadsrF4s B--9---L7F7#NN&E)::MMMM499VV3L3LMMM U r&ctD]G}d}d|||||D}|rt||||HdS)z+Updates the repo with the given phase headss%ln - _phase(%s)c6g|]}|Sr rr!cs r$rz updatephases..Ns PPPaPPPr&N)r<r7r)r.trgetterrar"rEheadss r$ updatephasesrMEsm<<$PP488FL4G#O#OPPP  < D((**eU ; ; ; < => 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 )r;rrrrNrrArnullidrwarnrr1rOnewheads) r.rrG draftrootsrr:r"rd publicheadss r$analyzeremotephasesrTSs2 ??  DJ~#,H{{}} e = 4yyE  F??t{"" . e^^x~~ (!!$''' GLLBCC$-      444K  ""r&ceZdZdZdZdS)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) c |}||_|dd|_t |||}|\|_|_|d|j|}d|D|_dS)Nr/Fsheads(%ln::%ln)c6g|]}|Sr rrIs r$rz0remotephasessummary.__init__..s 44416688444r&) r;_allremoterootsrr2rTrSrRr7 draftheads)rr. remotesubset remoterootsunfianadheadss r$rzremotephasessummary.__init__s  *%//-??!$ kBB,/)$/,do|LL44V444r&N)r&r'r(__doc__rr r&r$rVrVzs- 5 5 5 5 5r&rVcV ddlm}j}|jj |s|S|r |jgkrgS fd|D} fd|D}d||}||d||}||z}|s|rW| |d|}| ||} || tj |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)dagopc<h|]}|jk |Sr )rO)r!rr.rms r$rznewheads..s-;;;A!t{*:*:Q*:*:*:r&c&g|] }|Sr r )r!rrms r$rznewheads..s! # # #SSVV # # #r&s (%ld::%ld)s-parents(%ld + (%ld and merge())) and not nullsparents(%ld) and not null)rbr;rrget_revrOrrrreachablerootsr rrdr) r.rLrGrbr new_heads affected_zone candidates prunestartprunedrms ` @r$rQrQse ??  D B ( C  Edk]** ;;;;;;;;I # # # #U # # #EIImUI>>M  ...8%J-J,J,$$$YY;YGG %%dJ CC##F+++  BGVI%6%6 7 77r&c|dd} t|S#t$r%tjt d|zwxYw)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)rvs r$newcommitphaserssg )]++A A     A B BQ F    s %/AcJt|jjtS)z@utility function that check if a repo have any secret changeset.)boolr*rrDr-s r$ hassecretrvs  +F3 4 44r&cH|d}n t|}||t|dS)Nr&)snodesoldphaser)r)rdrzr{s r$preparehookargsrxs+ {oz# G GGr&rr%)Qr`structi18nrrdrrrrr r r r rer rrrr TYPE_CHECKINGtypingrrrrrrrrrruimodrAbytes Phaserootslocalrepository PhasedefaultsStructrPrhrr1rDrrr<r cmdphasenamesdict enumeraterrN phasenumberrror mutablephasesremotehiddenphaseslocalhiddenphasesr/r3rLrWrerurwrrrrrr5r@rFrMrTrVrQrsrvrxr r&r$rsddN                       c3u:o&J)+Z8*DEM  h'' av   UFHh 7 (3 000 T))M** + + " 8" 8AAj.>.>.@.@AAA !! ::z:::;;; BBzBBBCCC(3 h1x(HHH HHH >    &333*   ,575757prrrrrrrrj . & & &&&&@&" < < <$#$#$#N55555555,$8$8$8N    555 HHHHHr&