o ]Lba@sddlmZddlZddlmZddlmZmZddlm Z m Z m Z m Z m Z mZddlmZdZdZGd d d eZdPd d ZddZddZdQddZdQddZddZddZddZdZdZdZdZ dZ!dZ"d Z#d!Z$e%d"e%d#e%d$e%d%gZ&d&d'Z'd(d)Z(d*d+Z)d,d-Z*d.d/Z+dRd0d1Z,Gd2d3d3e-Z.dSd4d5Z/d6d7Z0d8d9Z1d:d;Z2dd?Z4d@dAZ5dBdCZ6edDedEedFedGedHdIZ7dJdKZ8dLdMZ9dNdOZ:dS)T)absolute_importN)_)hexshort)diffutilencodingerrorphasespycompatutil)dateutilc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)markerzWrap obsolete marker raw datacCs||_||_d|_dSN)_repo_data _decodedmeta)selfrepodatar3/usr/lib/python3/dist-packages/mercurial/obsutil.py__init__@s zmarker.__init__cCs t|jSr)hashrrrrr__hash__Fs zmarker.__hash__cCs t|t|kr dS|j|jkSNF)typerrotherrrr__eq__Is z marker.__eq__cC |jdS)z%Predecessor changeset node identifierrrrrrrprednodeN zmarker.prednodecCr")z-List of successor changesets node identifiersrr#rrrr succnodesRr%zmarker.succnodescCr")z2Parents of the predecessors (None if not recorded)r#rrrr parentnodesVr%zmarker.parentnodescCst|jdS)zDecoded metadata dictionary)dictrrrrrmetadataZzmarker.metadatacCr")z#Creation date as (unixtime, offset)r#rrrrdate^r%z marker.datecCr")zThe flags field of the markerrr#rrrrflagsbr%z marker.flagsN) __name__ __module__ __qualname____doc__rrr!r$r&r(r+r.r/rrrrr=s rFccsH|dur |j}n|rt||}n|j|}|D]}t||VqdS)zreturns markers known in a repository If is specified, only markers "relevant" to those nodes are are returnedN)obsstoreexclusivemarkersrelevantmarkersr)rnodes exclusive rawmarkers markerdatarrr getmarkersgs  r;cCst|dddS)NcSs|dd|dp dfS)Nrr)mrrryszsortedmarkers..)keysortedmarkersrrr sortedmarkerswsrDc cs||jj}|g}t|}|r<|}||d}|D]}|d}||vr%q||||vr2|Vq||q|sdSdS)zyield the list of next predecessors pointing on visible changectx nodes This function respect the repoview filtering, filtered revision will be considered missing. rrN)r4 predecessorssetpopgetaddappend) rnodeid precursorsstackseencurrent currentpreccsprec precnodeidrrrclosestpredecessors|s     rSc cszt|}t|}|jj}|r;|}|V||dD]}|d|@r$q|d}||vr6||||q|sdSdS)zYield node for every precursors of . Some precursors may be unknown locally. This is a linear yield unsuited to detecting folded changesets. It includes initial nodes too.rrrN)rFrErHrGrI) r4r7 ignoreflags remainingrNrQrOmarksucrrrallpredecessorss     rXccs|t|}t|}|r<|}|V|j|dD]}|d|@r"q|dD]}||vr6||||q&q|s dSdS)zYield node for every successor of . Some successors may be unknown locally. This is a linear yield unsuited to detecting split changesets. It includes initial nodes too.rrrN)rFrG successorsrHrI)r4r7rTrUrNrOrVrWrrr allsuccessorss      rZcCdd|DS)z"return a set with no prune markerscSsh|]}|dr|qS)rr.0r=rrr z _filterprunes..rrBrrr _filterprunesr,r`csL|}|jjj}|jj}|jj|jj}t}t|}fdd|D}| t|}|r| } t | | d} | dD] } | dsL| | qA| | dD] } | ds^| | qS| D]@} | |vrhqa| dsr| d| krw|| | d} | |vrqa|| } | r| |vrqat | }||r|| | | qa|s/|S)aset of markers relevant to "nodes" but no other locally-known nodes This function compute the set of markers "exclusive" to a locally-known node. This means we walk the markers starting from until we reach a locally-known precursors outside of . Element of with locally-known successors outside of are ignored (since their precursors markers are also relevant to these successors). For example: # (A0 rewritten as A1) # # A0 <-1- A1 # Marker "1" is exclusive to A1 or # (A0 rewritten as AX; AX rewritten as A1; AX is unknown locally) # # <-1- A0 <-2- AX <-3- A1 # Marker "2,3" are exclusive to A1 or # (A0 has unknown precursors, A0 rewritten as A1 and A2 (divergence)) # # <-2- A1 # Marker "2" is exclusive to A0,A1 # / # <-1- A0 # # <-3- A2 # Marker "3" is exclusive to A0,A2 # # in addition: # # Markers "2,3" are exclusive to A1,A2 # Markers "1,2,3" are exclusive to A0,A1,A2 See test/test-obsolete-bundle-strip.t for more examples. An example usage is strip. When stripping a changeset, we also want to strip the markers exclusive to this changeset. Otherwise we would have "dangling"" obsolescence markers from its precursors: Obsolescence markers marking a node as obsolete without any successors available locally. As for relevant markers, the prune markers for children will be followed. Of course, they will only be followed if the pruned children is locally-known. Since the prune markers are relevant to the pruned node. However, while prune markers are considered relevant to the parent of the pruned changesets, prune markers for locally-known changeset (with no successors) are considered exclusive to the pruned nodes. This allows to strip the prune markers (with the rest of the exclusive chain) alongside the pruned changesets. cs g|] }t|ds|qS)r)r`rHr]nsuccessormarkersrr s z$exclusivemarkers..rrr) unfiltered changelogindexhas_noder4rErYchildrenrFsortrGlistrHrJrIr`issubset)rr7unfiriprecursorsmarkerschildrenmarkers exclmarkersrM seennodesrOrCrVrQknown precmarkersrrcrr5sN6        .r5cs|}t|d|}|jrN|jjjd}t||krNt|}dd|D}dd|D}|t|j|fdd|D}t|d|}t||ksd d|DS) aRreturn all nodes in the "foreground" of other node The foreground of a revision is anything reachable using parent -> children or precursor -> successor relation. It is very similar to "descendant" but augmented with obsolescence information. Beware that possible obsolescence cycle may result if complex situation. s%ln::r<cSh|]}|qSrnoder]crrrr^Yzforeground..cSsg|] }|r|qSr)mutablerwrxrrrreZszforeground..c3s|] }|r|VqdSrrrarirr \szforeground..cSrurrvrxrrrr^^rz) rfrFr4rgrhrilenupdaterZ)rr7 foregroundplensuccsr{rsrr|rrFs    rsef1r- @s^branch$s ^.*-source$s ^.*_source$s^source$cs |dtfddtD S)zvCheck that the key of a meta item (extrakey, extravalue) does not match at least one of the blacklist pattern rc3s|]}|VqdSr)match)r]patternmetakeyrrr}sz%metanotblacklisted..)any METABLACKLIST)metaitemrrrmetanotblacklistedsrcCsBg}|D]}|ds|ds|drd}||q|S)z/Drop all information but the username and patchs# User#s@@s@@ ) splitlines startswithrJ)hunk cleanhunklinerrr _prepare_hunks   rcCst|d}|dur |St|S)zreturn a cleaned up linesN)nextr)iterdifflinesrrr _getdiffliness rc Cst|jddi}|j|}|j|d}|j|}|j|d}d\}}d||fvrGt|}t|}||krAdSd||fvs3dS)z|return True if both ctx introduce the "same diff" This is a first and basic implementation, with many shortcoming. sgitT)opts)rrNF) r diffalloptsruirrfrevdiffr) leftctxrightctxdiffoptsleftunfileftdiff rightunfi rightdiffleftrightrrr_cmpdiffs    rcCsd}|D]i}||kr|tO}||kr|tO}||kr*|tO}||kr6|tO}||krB|t O}| }t t t|}| }t t t|}||krd|tO}t||sm|tO}q|S)zeFrom an obs-marker relation, compute what changed between the predecessor and the successor. r) description DESCCHANGEDuser USERCHANGEDr. DATECHANGEDbranch BRANCHCHANGEDparents PARENTCHANGEDextraitemsrlfilterr METACHANGEDr DIFFCHANGED)sourcerYeffects changectx changeextractxmeta sourceextrasrcmetarrr geteffectflags,   rcCs|du|dukrd}t||jjj}|jj}|jj j }t j }|dur)|j }|d}|d} t} t} |D]4} | d} || }|dusO|| vsO|| krPq9| |||||kr]q9t|| pcg|rm| |q9| S)zreturn the set of pre-existing revisions obsoleted by a transaction Either the transaction or changes item of the transaction (for hooks) must be provided, but not both. Ns.exactly one of tr and changes must be provideds obsmarkerss origrepolenr)r ProgrammingErrorrfrgrhget_rev _phasecachephaser4rYrHr publicchangesrFrIrm)rtrretorevr succsmarkersr addedmarkers origrepolenseenrevs obsoletedrVrwrrrr getobsoleteds2    rcs>eZdZdZfddZddZejddZdd Z Z S) _succszAsmall class to represent a successors with some metadata about itcs"tt|j|i|t|_dSr)superrrrFrC)rargskwargs __class__rrr s z_succs.__init__cCst|}|j|_|Sr)rrCcopy)rnewrrrrs z _succs.copycCst|Sr)rFrrrr_setsz _succs._setcCs|j|jSr)rrmrrrrcanmergesz_succs.canmerge) r0r1r2r3rrr propertycacherr __classcell__rrrrrs  rcCs|jj}|g}t|}|duri}|r|d}||vp$|o$||ko$||v}||vr1||n|rE||vr@t|fg||<ng||<nt||D]$} | dD]} | |vrl| |vr`g|| <qQ|| || nqQqKng} t||D]J} t} | j | | g} | dD]2} g}| D]'}|| D] }| }|j |j |D] }||vr||q||qq|r|} q| | qxg}g}t dd| Dtdd}|D]}|D]}||r|j |j n q||||q||||<|s||S)a Return set of all latest successors of initial nodes The successors set of a changeset A are the group of revisions that succeed A. It succeeds A as a consistent whole, each revision being only a partial replacement. By default, the successors set contains non-obsolete changesets only, walking the obsolescence graph until reaching a leaf. If 'closest' is set to True, closest successors-sets are return (the obsolescence walk stops on known changesets). This function returns the full list of successor sets which is why it returns a list of tuples and not just a single tuple. Each tuple is a valid successors set. Note that (A,) may be a valid successors set for changeset A (see below). In most cases, a changeset A will have a single element (e.g. the changeset A is replaced by A') in its successors set. Though, it is also common for a changeset A to have no elements in its successor set (e.g. the changeset has been pruned). Therefore, the returned list of successors sets will be [(A',)] or [], respectively. When a changeset A is split into A' and B', however, it will result in a successors set containing more than a single element, i.e. [(A',B')]. Divergent changesets will result in multiple successors sets, i.e. [(A',), (A'')]. If a changeset A is not obsolete, then it will conceptually have no successors set. To distinguish this from a pruned changeset, the successor set will contain itself only, i.e. [(A,)]. Finally, final successors unknown locally are considered to be pruned (pruned: obsoleted without any successors). (Final: successors not affected by markers). The 'closest' mode respect the repoview filtering. For example, without filter it will stop at the first locally known changeset, with 'visible' filter it will stop on visible changesets). The optional `cache` parameter is a dictionary that may contains precomputed successors sets. It is meant to reuse the computation of a previous call to `successorssets` when multiple calls are made at the same time. The cache dictionary is updated in place. The caller is responsible for its life span. Code that makes multiple calls to `successorssets` *should* use this cache mechanism or risk a performance hit. Since results are different depending of the 'closest' most, the same cache cannot be reused for both mode. Nr<rcss|]}|r|VqdSrr)r]srrrr}sz!successorssets..T)r?reverse)r4rYrFremoverGrrDrJrIrCrrextendrAr~rr)r initialnodeclosestcache succmarkers toproceed stackedsetrOcase2conditionrVrW succssetsbasemarkss productresultprefixsuffixnewsspartrNfinal candidatescand seensuccsrrrsuccessorssetss1 !               rc Cs|sdSt||dd}|gkrtg}|jj}g}|D]3}|r)||qd}||dD]}|dsId}t}|j |||q3|sR|tqg}|D] }|||jdqW|S)zncompute the raw data needed for computing obsfate Returns a list of dict, one dict per successors set NT)rFrr)s successorssmarkers) obsoleterrwrr4rYrJrHrCrI) rctxssetssuccsmapfullsuccessorsetsssetfoundanyrVvaluesrrrsuccessorsandmarkerss2     rcCs<t|dkrdSt|dkrdS|d}t|dkrdSdS)a}Compute a changeset obsolescence fate based on its successorssets. Successors can be the tipmost ones or the immediate ones. This function return values are not meant to be shown directly to users, it is meant to be used by internal functions only. Returns one fate from the following values: - pruned - diverged - superseded - superseded_split rprunedrdiverged supersededsuperseded_splitr~)rrYrrr _getobsfate5s   rcCs(|sd}|St|dkrd}|Sd}|S)zhReturn the verb summarizing the successorset and potentially using information from the markers rrs rewrittenssplitr) successorsetrCverbrrr obsfateverbPs rcCr[)z/returns the list of dates for a list of markerscSsg|]}|dqS)r-rr\rrrre_rzz markersdates..rrBrrr markersdates]r,rcC$dd|D}dd|D}t|S)z9Returns a sorted list of markers users without duplicatescSg|]}t|dqSr)r*r\rrrredr_z markersusers..cSs$h|]}|drt|dqS)suser)rHrtolocalr]metarrrr^es  zmarkersusers..r@)rC markersmetausersrrr markersusersbs rcCr)z>Returns a sorted list of markers operations without duplicatescSrrrr\rrrrepr_z%markersoperations..cSs h|] }|dr|dqS)s operation)rHr rrrr^qs  z$markersoperations..r@)rCr  operationsrrrmarkersoperationsns rcs@|j}|j}| o | }g}|t||t|} | r&|dd| |r<fdd|D} |dd| t|} |sT|jdd} t| dkrT| | vrTd } |sX|rd| rd|d d| t |} | r|rt | }t | }||krt |d }|d |nt |d }t |d }|d ||fd|S)zoBuild a obsfate string for a single successorset using all obsfate related function defined in obsutil s using %s, csg|]}|qSrr)r]succ formatctxrrrrer_z"obsfateprinter..s as %sT) acceptemptyrNs by %ss%Y-%m-%d %H:%M %1%2s (at %s)s (between %s and %s))quietverboserJrrjoinrusernamer~rminmaxr datestr)rrrYrCrrrnormalrr fmtsuccessorsr  currentuserdatesmin_datemax_date fmtmin_date fmtmax_daterrrobsfateprinterxs:       r&shidden revision '%s' is pruneds!hidden revision '%s' has divergeds)hidden revision '%s' was rewritten as: %ss%hidden revision '%s' was split as: %ss1hidden revision '%s' was split as: %s and %d more)rrrrsuperseded_split_severalc Cst||}t|}|dkrtd|S|dkrtd|S|dkr3t|dd}td||fS|dkrtg}|dD] }|t|q=t|dkrZd|}td||fSd|dd} t|d} || | f} td | SdS) zDreturn a human-friendly string on why a obsolete changeset is hiddenrrrrrrrNr')rrwrfilteredmsgtablerrJr~r) rchangeidrrYfatesingle_successorrnode_idfmtsuccsfirstsuccessorsremainingnumberrrrr_getfilteredreasons*        r0cCsi}i}t|j|gD](}||krq t|||}|D]}||vr'qt||vr.q||t|<qq ddt|DS)z2Compute sets of commits divergent with a given onecSsg|] \}}||dqS))divergentnodescommonpredecessorr)r]divsetbrrrresz!divergentsets..)rXr4rwrtupler iteritems)rrrrrb nsuccsetsnsuccsetrrr divergentsetss     r9c sg}|r-|D]"}d}|rd}n|rd}|dur,|dd||dq |rUtj|gt d}fdd|D}|D] }|dd |dqG| r|t |}|D]} fd d| d D} |d | d t| ddq`|S)Nsorphansobsoletes %s parent) instabilityreasonnode)rTcs(g|]}|vr|s|qSr)r{)r]prrrres"zwhyunstable..sphase-divergentsimmutable predecessorcsg|]}|qSrrrar>rrrerzr1scontent-divergents predecessorr2)r:r1r;r<) orphanrrrJrphasedivergentrXr4rw bumpedfixcontentdivergentr9) rrresultparentkindrE immutable predecessordsetsdsetdivnodesrr>r whyunstablesT    rKr)r)NN)FN); __future__rrei18nrrwrrrrr r r r utilsr rA usingsha256objectrr;rDrSrXrZr`r5rEFFECTFLAGFIELDrrrrrrrcompilerrrrrrrrlrrrrrrrrr&r(r0r9rKrrrrsr      *  z*    , i0   6