o ]LbWx@sddZddlmZddlZddlmZddlmZddlm Z m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z m!Z!m"Z"Gd d d ej#Z$iZ%e&e%Z&d Z'iZ(e)e(Z)e)d d dde)d dddGddde*Z+Gddde*Z,Gddde*Z-ddZ.ddZ/e&d dddededfdd ged!ed"fd#d$ded%fd&d'ged(ed"fd)d*ged+ed"fdd,ded-ed"fd.d/d0ed1fddded2fdd3d0ed4fd5d6ded7fdd ded8ed9fg ed:e&j0d;dd?Z2d@dAZ3e4Z4e4dBdCdDZ5e6Z6e6dEdFhdGdHdIZ7dJdKZ8e5e7gZ9dS)LaVcommand to transplant changesets from another branch This extension allows you to transplant changes to another parent revision, possibly in another repository. The transplant is done using 'diff' patches. Transplanted patches are recorded in .hg/transplant/transplants, as a map from a changeset hash to its hash in the source repository. )absolute_importN)_)open)binhexshort) bundlerepocmdutilerrorexchangehg logcmdutilmatchmergepatchpycompat registrarrevsetsmartsetstateutilvfs)procutil stringutilurlutilc@s eZdZdS)TransplantErrorN)__name__ __module__ __qualname__rr2/usr/lib/python3/dist-packages/hgext/transplant.pyr4srsships-with-hg-core transplantfilter)defaultlogc@seZdZddZdS)transplantentrycCs||_||_dSN)lnodernode)selfr'r(rrr __init__Ps ztransplantentry.__init__N)rrrr*rrrr r%Os r%c@s>eZdZdddZddZddZdd Zd d Zd d ZdS) transplantsNcCs<||_||_||_|st|j|_i|_d|_|dSNF)pathtransplantfileopenervfsmodrr+dirtyread)r)r-r.r/rrr r*Vs ztransplants.__init__cCsztj|j|j}|jr7tj|r9|j|jD]}tt | d\}}|j |g}| t||qdSdSdS)N:)osr-joinr.existsr/r2 splitlinesmaprsplitr+ setdefaultappendr%)r)abspathliner'r(listrrr r2asztransplants.readcCs|jrB|jrBtj|jst|j||jd}t|j D]}|D]}t t |j |j f\}}||d|dq$q |d|_dS)Nwr3 F)r1r.r4r-isdirmkdirr/r itervaluesr+r8rr'r(writeclose)r)fpr>tlrrrr rDis   ztransplants.writecCs|j|pgSr&)r+get)r)r(rrr rJuztransplants.getcCs(|j|g}|t||d|_dSNT)r+r:r;r%r1)r)r'r(r>rrr setxs ztransplants.setcCs,|j|j}|r|||=d|_dSdSrL)r+rJr(indexr1)r) transplantr>rrr remove}s   ztransplants.remove)NNN) rrrr*r2rDrJrMrPrrrr r+Us    r+c@seZdZddZddZd#ddZdd Z d$d d Zd dZddZ ddZ ddZ ddZ ddZ ddZd%ddZddZdd Zd!d"ZdS)& transplantercsT||_|_jd|_t|j|_t|jd|jd|_fdd}||_dS)Nr!s transplants)r/cs*tdd}tjdd|itS)Nr!editformr)r mergeeditformgetcommiteditorr strkwargs)rRoptsreporr rTs z.transplanter.__init__..getcommiteditor) uirXrr5r-r0r/r+rT)r)rYrXrWrTrrVr r*s  ztransplanter.__init__c Cst||r |j|}t||r&|j|}|jj|g|dd}||vr&dS|j|D]'}t||js=|j|dS|j|j}||jj|g|ddvrSdSq,dS)zmreturns True if a node is already an ancestor of parent or is parent or has already been transplantedT) inclusiveF)hasnode changelogrev ancestorsr+rJr'rP) r)rXnodeparent parentrevr] reachablerGlnoderevrrr applieds(      ztransplanter.appliedNc Cs|duri}t|}|j}g}t|j|} d| _d} } z|} |d} |D]J} || } d| t | f}| || |rM|j t d|q,|j | }|ds|ds|d|krk|| | }q,|r||kr{tj|||d t||d |j}g}d }| |vrd}t|| stj||| gd d }|d |jkr|d s|jt d| t | fd}n||d }||vrtt dt |t | fn|d}|rd}n%tjdd\}}t|d}tj ||| | d}|D]}|!|q|"|| =|s|rwzXz|j#|| |j $| |||d|dd}Wn t%y:| "w|rP|rP|j&t d|t |fn|rc|j&t dt | t |fW|rlt'|q,|rvt'|wwq,| "|rtj|||d t||d W|(|||j)!| r| *| r| *dSdS|(|||j)!| r| *| r| *ww)z:apply the revisions in revmap one by one in revision orderNTr!s%d:%ss%skipping already applied revision %s r"r$r)headsFparentsskipping merge changeset %d:%s %s is not a parent of %shg-transplant-prefixwb)rW)rlogfilters%s merged at %s s%s transplanted to %s )+sorteddirstatep1rdifffeatureoptsrYgitlock transactionrrdwarnrr\parentsrJr;r pullpeerrupdater[nullidnotelookupr Abortrmkstempr4fdopendiffrDrEapplyoner2rstatusunlink saveseriesr+release)r)rXsourcerevmapmergesrWrevsrrpullsdiffoptsrutrr]r_revstrrxdomerge skipmerger` patchfilefdrFgenchunknrrr applys                         ztransplanter.applyc Cs |jtd||d|d|d}}}tjdd\}} t|d} | d| d || d || |d | z6|jj d |t | t |f|dt |d t jtddd|t| ddd\}}}Wt| nt| w|||fS)z0arbitrarily rewrite changeset before applying its filtering %s rgrjrkrms# HG changeset patch # User %s s # Date %d %d r@s%s %s %s)sHGUSERs HGREVISIONs filter failedstransplant_filter)environonerr errprefix blockedtagsrb)rYrrrrr4rrDrEsystemr shellquoterr rparselogrr) r)ror_r\ruserdatemsgr headerfilerFrrr ro$s6    ztransplanter.filterFc Cs|dd\}} \} } } } d| | f}d|i}|r$|||||\} }} |r.| dt|7} |jtdt||jd| || f|sP|sPttd|rzt } t j |j||| dd t | } WnDt y}z6t j|jd }t j|rt ||j}|}|j| || |||d |jt|d ttd d}~wwd} |r|j}|||t}nt| }|j| | ||||d}|s|jtdt|dS|s|j |||S)z>apply the patch in patchfile to the repository as a transplantNs%d %dtransplant_sources (transplanted from %s)s applying %s s %s %s %s s"can only omit patchfile if merging)fileseolmodeseries)rr@s=fix up the working directory and run hg transplant --continue)extrareditorsskipping emptied changeset %s )!rorrYrrrr}r rrMrr> Exceptionr4r-r5r6rrqrrrnrDr forcebytestrr setparentsralwaysexactcommitrTrwr+)r)rXr_clrrrnromanifestrtimetimezonermessagerrinst seriespathrrp2mrrrr rGsf         ztransplanter.applyonecCstjtj|jdSNjournal)r4r-r6r5r)rrr canresumesztransplanter.canresumec Cstjtj|jdr5||||\}}|r(|jtdt|t|fn |jtdt|ftj|jd}tj|sJ|j dS| \}}i} |D] }|| |j |<qTt||||| ||dS)z7recover last transaction and apply remaining changesetsrs%s transplanted as %s s%s skipped due to empty diff rN)r4r-r6r5recoverrYrrrr+rD readseriesr\r]rr) r)rXrrWrr_rnodesrrrrr resumes&    ztransplanter.resumecCsd|\}}}}}d} |r|r|r|dsttd|d} t|dkrH|drF||d} | |vrEttdt| t|fnd} d|i} zd|j } | | krattd t | | rk| | |d| } | j | j| j| jf\}}}}| s|s|s|s|r|j|||| |d }|sttd | s|j||nd }|||fWSw) z/commit working directory using journal metadataFrstransplant log file is corruptrgrhriTrs-working directory not at transplant parent %s)rrs commit failedN)readlogr rrlenrJr~rrqrrrrrmodifiedaddedremoveddeletedrrTr+rMunlog)r)rXrrWr_rrrrxrr`rrrstrrrrrrrr rsd    ztransplanter.recovercCsV|r)|d}t||td|td|dd|dSdS)z'logic to stop an interrupted transplant.s#stopped the interrupted transplant sworking directory is now at %s N r)rr clean_updaterrrr)r)rYrXstartctxrrr stops ztransplanter.stopcCsHg}g}|}|jdD]}|dr|}q|t|q||fS)Nrs# Merges)r/r2r7 startswithr;r)r)rrcurr=rrr rs ztransplanter.readseriescCs|sdStj|jst|j|dd}t|D] }|t||dq|r>|d|D] }|t|dq2|dS)Nrr?r@s # Merges ) r4r-rArBr/rprDrrE)r)rrseriesr]rrrr rs     ztransplanter.saveseriesc Csg}g}|jj}d}d}d}|D]M}|r||q|dr*|dd}q|dr6|dd}q|drDt|dd}q|drU|t|ddq|d sad }||qd||fvrott d |||d ||fS) NFs# User s# Date s # Node ID # Parent s# Ts,filter corrupted changeset (no user or date)r@) rXr|r2r7r;rrr rrr5) r)rFrxrr_inmsgrrr=rrr rs4        ztransplanter.parselogcCstj|js t|j|dd}|d||d||dt||dt|d|rB|dt|d||d|dS) z,journal changelog metadata for later recoverrr?rs # Date %s s # Node ID %s rr@N) r4r-rArBr/rDrrstriprE)r)rrrrrrrrFrrr rns   ztransplanter.logcCs||dSr)rr/rrrr r-rKztransplanter.readlogcCs.tj|jd}tj|rt|dSdS)zremove changelog journalrN)r4r-r5r6r)r)absdstrrr r0s ztransplanter.unlogcsfdd}|S)Ncs`|r dSj|djkrdSj|d}|d}|r.|r.dSdS)NFrgrrT)rdr\rxr|r2rJ)r_rcnoderXrootr)rrr matchfn7s z.transplanter.transplantfilter..matchfnr)r)rXrrrrrr transplantfilter6s ztransplanter.transplantfilterr&)FFN)F)rrrr*rdrrorrrrrrrrrnrrrrrrr rQs$ v$ ?;    rQcCs*z |j|duWStjyYdSwr,)r\r]r StorageError)rXr_rrr r[Es r[cCs&t|||}g}g}td}|D]y}|||d} | sf||} d| | d} | dkrG||dD] \} } |d| | fq6d} n| dkrd|j|d} t || |D]}||qZd} | r| d krp| |q| d krz| |q| d krn | d krd }d }nq| ||fS)z#interactively transplant changesetssapply changeset? [ynmpcq?]:$$ &yes, transplant this changeset$$ &no, skip this changeset$$ &merge at this changeset$$ show &patch$$ &commit selected changesets$$ &quit and cancel transplant$$ &? (show this help)Nsynmpcq?rg?s%s: %s prymcqr) r changesetdisplayerrshow promptchoiceextractchoicesrDr\rxrrr;rE)rYrXrrW displayerr+rpromptr_actionchoicecrGr`rrrr browserevsLsF     rssourcestransplant changesets from REPOsREPObbranchs!use this source changeset as headsREVaalls0pull all changesets up to the --branch revisionsrprunes skip over REVrmerges merge at REVrhs)parent to choose when transplanting mergeeseditFs invoke editor on commit messagess%append transplant info to log messagestopsstop interrupted transplantrcontinues7continue last transplant session after fixing conflictss!filter changesets through commandsCMDsChg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] [-m REV] [REV]...) helpcategorycOsD|t||g|Ri|WdS1swYdS)atransplant changesets from another branch Selected changesets will be applied on top of the current working directory with the log of the original changeset. The changesets are copied and will thus appear twice in the history with different identities. Consider using the graft command if everything is inside the same repository - it will use merges and will usually give a better result. Use the rebase extension if the changesets are unpublished and you want to move them instead of copying them. If --log is specified, log messages will have a comment appended of the form:: (transplanted from CHANGESETHASH) You can rewrite the changelog message with the --filter option. Its argument will be invoked with the current changelog message as $1 and the patch as $2. --source/-s specifies another repository to use for selecting changesets, just as if it temporarily had been pulled. If --branch/-b is specified, these revisions will be used as heads when deciding which changesets to transplant, just as if only these revisions had been pulled. If --all/-a is specified, all the revisions up to the heads specified with --branch will be transplanted. Example: - transplant all changes up to REV on top of your current revision:: hg transplant --branch REV --all You can optionally mark selected transplanted changesets as merge changesets. You will not be prompted to transplant any ancestors of a merged transplant, and you can merge descendants of them normally instead of transplanting them. Merge changesets may be transplanted directly by specifying the proper parent changeset by calling :hg:`transplant --parent`. If no merges or revisions are provided, :hg:`transplant` will start an interactive changeset browser. If a changeset application fails, you can fix the merge by hand and then resume where you left off by calling :hg:`transplant --continue/-c`. N)wlock _dotransplant)rYrXrrWrrr rOxs j$rOc sftjfdd}tjfdd}dd}t|}||||ds)|dd|d<|d s6|dd |d <t|||}|j}t |d krS||j krSt t d |d rd|sct t d n |drz|stt t d|||St|t||d} | rtd||| d } t||| } t| j|dd} t| } |D]}z | | |Wqt jyYqwtj||| t| dd\}}n|tj|dd} d}z|d r| ||W|r|dSdS|!|||drfddt"#|dDfdd}n}tj|dd}i}|rFt"#|D] }|$|t%|<q7nC|dsO|s|kr\|||d}n||| |d}|drm|}nt&|||\}}|'||D] }||j()|<q}|D] }||j()|<q|*||||W|r|dSdS|r|ww)Ncss|D] }||r |VqdSr&r)rXcsetsrr_rrr incwalks z_dotransplant..incwalkcssf|s|}g}||}|D]}||||q|j||dD] }||r0|Vq'dS)zYield all nodes that are ancestors of a head but not ancestors of dest. If no heads are specified, the heads of repo will be used.rN)rer;ancestorr_r\ nodesbetween)rXdestrerr^ctxheadr_rrr transplantwalksz%_dotransplant..transplantwalkcSs|drt|dgddS|dr t|dgddS|ds8|s8|ds8|ds8ttd|drR|dsIttd |rTttd dSdS) Nr)rrrrrrrs9no source URL, branch revision, or revision list providedrs --all requires a branch revisions*--all is incompatible with a revision list)rJr check_incompatible_argumentsr rr)rWrrrr checkoptss@      z _dotransplant..checkoptsr$r!r"rsno revision checked outrsno transplant to continuersno interrupted transplant foundrrrT) onlyheadsforcercsh|]}|qSr)r_.0rI)rrr Ms z _dotransplant..cs|o|vSr&r)x)prunetfrr Qsz_dotransplant..rr)r)+rrr byteskwargsrJconfigrQrqrrrr|r rrr StateErrorrr checkunfinished bailifchangedrget_unique_pull_pathr rzmaplistr~rMadd RepoErrorrgetremotechangesrprrr revranger_intrextendr\r]r)rYrXrrWrrr tprr sourcerepourzretargetrIr cleanupfnrrralltransplants newmergesr)rrrr rs             #        rcCsF|t||i}|||iWdS1swYdS)zAlogic to resume an interrupted transplant using 'hg continue'N)rrQr)rYrXr rrr continuecmdps   $r'stransplanted([set])cs0|r t||}n|}tfdd|DS)z?Transplanted changesets in set, or all transplanted changesets.cs"g|] }|dr|qS)r)rrJr rXrr s"z&revsettransplanted..)rgetsetrbaseset)rXsubsetrsrr(r revsettransplanted{s r.s transplantedctx)requirescCs*||d}|d}|rt|pdS)zEString. The node identifier of the transplanted changeset if any.r/rr)resourcerrJr)contextmappingrrrrr kwtransplanteds r4cCs"tjdddttdtdddS)Nr!stransplant/journalTsMTo continue: hg transplant --continue To stop: hg transplant --stops8use 'hg transplant --continue' or 'hg transplant --stop')fname clearable continuefunc statushintcmdhint)statemod addunfinishedr'r)rYrrr extsetups r<):__doc__ __future__rr4mercurial.i18nrmercurial.pycompatrmercurial.noderrr mercurialrr r r r r rrrrrrrrr:rrr0mercurial.utilsrrrrrcmdtablecommand testedwith configtable configitemobjectr%r+rQr[rCATEGORY_CHANGE_MANAGEMENTrOrr'revsetpredicater.templatekeywordr4r< i18nfunctionsrrrr s   H  /D,/ 77