Qc@sdZddlZddlmZmZmZmZmZddlm Z ddl Z ddl Z e dZ \ZZZe dZddd gZdd Zd efd YZd ZdZdZdZdZdZdZdZdS(s 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 iN(tnullidtnullrevtbinthextshort(t_iitpublictdrafttsecretc Cs|j}t}gtD]}t^q}ye|jd}zDx=|D]5}|j\}}|t|jt|qJWWd|j XWnZt k r} | j t j krn|rx |D]}|||}qWnt }nX||fS(sRead 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. t phaserootsN(t unfilteredtFalset allphasestsettsopenertsplittinttaddRtclosetIOErrorterrnotENOENTtTrue( trepot phasedefaultstdirtytitrootstftlinetphasetnhtinst((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyt _readrootsps$  %  t phasecachecBsheZedZdZdZedZdZdZ dZ dZ dZ d Z RS( cCsJ|rFt||\|_|_d|_|j||j|_ndS(N(R!R RtNonet _phaserevst filterunknownRtopener(tselfRRt_load((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyt__init__s   cCsJtdddt}|j|_|j|_|j|_|j|_|S(NR((R"R#R R RR&R$(R'tph((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytcopys     cCs4x-djD]}t||t||q WdS(Ns"phaseroots dirty opener _phaserevs(Rtsetattrtgetattr(R'tphcacheta((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytreplacescCs|s|jdkr|j}tgt|j}xutD]m}t|jj|j |}|r>x|D]}|||q>W||_n|jS(N( R$R#R Rtlent changelogt trackedphasestmaptrevR t descendants(R'RtrebuildtrevsRRR5((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyt getphaserevss    cCsZ|tkrtS|jdks4|t|jkrO|j|dt|_n|j|S(NR7(RRR$R#R1R9R(R'RR5((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyRs  $cCs|js dS|jdddt}zRxKt|jD]:\}}x+|D]#}|jd|t|fqKWq8WWd|jXt|_dS(NR twt atomictemps%i %s ( RR&Rt enumerateR twriteRRR (R'RRRth((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyR=s  ) cCs#||j|ssroots((%ln::) - (%ln::%ln))i( R txrangeR1R RR5R R R@textendtretractboundarytinvalidatevolatilesets( R'Rt targetphasetnodestdelrootsRtntoldsR((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytadvanceboundarys    .   cCs|j}|j|}g|D].}|j|||j|kr |^q }|rt|kr~tjtdn|j}|j ||j d|}|j d|D|j ||n|j dS(Ns!cannot change null revision phases roots(%ln::)css|]}|jVqdS(N(RA(RBRC((s4/sys/lib/python2.7/site-packages/mercurial/phases.pys s(R R RR5RtutiltAbortRR+tupdateR tintersection_updateR@RG(R'RRHRIt currentrootsRKR?tctxs((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyRFs   .   c Cst}|jj}xt|jD]~\}}g|D]}||kr5|^q5}|r"x.|D]&}|jjdt||fq`W|j|t }q"q"W|rt |_ nd|_ dS(sremove unknown nodes from the phase boundary Nothing is lost as unknown nodes only hold data for their descendants. s0removing unknown node %s from %i-phase boundary N( R R2tnodemapR<R tuitdebugRtsymmetric_difference_updateRRR#R$( R'RtfilteredRTRRIRAtmissingtmnode((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyR%s %     (t__name__t __module__RR)R+R0R R9RR=R@RMRFR%(((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyR"s      cCs6|jj}|j||||jj|dS(sAdd 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.N(t _phasecacheR+RMR0(RRHRIR.((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyRMscCs6|jj}|j||||jj|dS(sSet 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]R+RFR0(RRHRIR.((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyRF"scCsdi}dt}x(|jjtD]}||t| => phase} mapping. key and value are string. Accept unknown element input R`is2ignoring inconsistent public root from remote: %s is,ignoring unexpected root from remote: %i %s ( R R2RTt iteritemsRRRRUtwarnRtappendtnewheads( RtsubsetRt draftrootsRTRiRRAt publicheads((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytanalyzeremotephases\s&         cCsD|j}|jd||||}g|D]}|j^q.S(scompute new head of a subset minus another * `heads`: define the first subset * `roots`: define the second we subtract from the firsts(heads((%ln + parents(%ln)) - (%ln::%ln))(R R RA(RtheadsRtrevsettc((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyRs{s  cCs|jddt}ytj|SWnRtk rzyt|SWq{tk rvtd}tj||q{XnXdS(suhelper to get the target phase of new commit Handle all possible values for the phases.new-commit options. R^s new-commits0phases.new-commit: not a valid phase name ('%s')N( tconfigRt phasenamestindext ValueErrorRRterrort ConfigError(RUtvtmsg((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytnewcommitphases   cCst|jjdS(s@utility function that check if a repo have any secret changeset.i(tboolR]R (R((s4/sys/lib/python2.7/site-packages/mercurial/phases.pyt hassecrets(t__doc__RRARRRRRti18nRRNRtrangeR RRRR3R|R#R!tobjectR"RMRFReRoRwRsRR(((s4/sys/lib/python2.7/site-packages/mercurial/phases.pytes" (