a +bH@s~dZddlmZddlZddlZddlmZddlmZm Z m Z ddl m Z ddl mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z)m*Z*dZ+d Z,hd Z-iZ.e!/e.Z/iZ0e!1e0Z1e1d d d ddZ2ddZ3ddZ4ddZ5dddZ6e!7Z7e7dddZ8e7dddZ9ddZ:Gd d!d!e;Zd?d ed@fd/dAd edBfdCdDd edEfdFdGd edEfdHdId/edJfd/dKd edLfdMdNd edOfdPdQd edRfd/dSd/edTfgej=ej>ej?edUe/j@dVdWdXZAdYdZZBdd[d\ZCd]d^ZDd_d`ZEdadbZFdcddZGdedfZHdgdhZIdidjZJdkdlZKdmdnZLdodpZMdqdrZNdsdtZOdudvZPdwdxZQdydzZRd{d|ZSd}d~ZTddZUdddZVddZWddZXddZYddZZddZ[ddZ\dS)zcommand to move sets of revisions to a different ancestor This extension lets you rebase changesets in an existing Mercurial repository. For more information: https://mercurial-scm.org/wiki/RebaseExtension )absolute_importN)_)nullrevshortwdirrev)open) bookmarkscmdutilcommandscopiesdestutil dirstateguarderror extensions logcmdutilmerge mergestate mergeutilobsoleteobsutilpatchphasespycompat registrarrepairrevset revsetlang rewriteutilscmutilsmartsetstateutils-1>s-3s-4s-2s-5develrebase.force-in-memory-mergeF)defaultsships-with-hg-corecCsdS)Nr'r'r'2/usr/lib64/python3.9/site-packages/hgext/rebase.py_nothingtorebaseVsr)cCsD|dd}|dur ||d<|dd}|dur@||d<dS)Nsourcesintermediate-source)extraget)ctxr+sr'r'r( _savegraftZs r/cCs||d<dS)Nbranch)branch)r-r+r'r'r( _savebranchcsr2cCstj|d|d|dS)zhsmall wrapper around destmerge to pass the right extra args Please wrap destutil.destmerge instead.rebaseF)action sourcesetZ onheadcheck destspace)r Z destmerge)repor5r6r'r'r( _destrebasegsr8s _destrebasecCs6d}|dur t|t||}|tt||g@SN)rgetsetrZ fullreposetbasesetr8)r7subsetxr5r'r'r(_revsetdestrebasewsr>s_destautoorphanrebasecCsp|}|d}t|||}|r0||vr8tSt||}t |dkrft t d||ft|S)Ns obsolete()r&s8ambiguous automatic rebase: %r could end up on any of %r) unfilteredrevsrr:firstrr;r Zorphanpossibledestinationlenr StateErrorr)r7r<r=unfiZ obsoletedsrcdestsr'r'r(_revsetdestautoorphanrebases    rGcCstj|j|ddS)zshort description for a contextr3)command)r Zformat_changeset_summaryr7uir-r'r'r(_ctxdescs rKc@seZdZdZd#ddZeddZd$dd Zd d Zd d Z ddZ ddZ d%ddZ ddZ ddZddZd&ddZddZdd Zd'd!d"ZdS)( rebaseruntimez2This class is a container for rebase runtime stateFNcCs|dur i}d|_d|_||_||_||_d|_t|_i|_d|_ i|_ t |_ | dd|_t|t||_| dd|_| d}tg|_|r|g|_|dd|_| dd|_| dd|_t|jd |_i|_t |_||_ ||_!t"#|d |_$dS) NFcollapsedateZextrafnsrewrites backup-bundleZkeepZ keepbranchesr3 rebasestate)%preparedresume_reporIopts originalwdrexternalr activebookmarkdestmapsetskippedr, collapsefr Z logmessager byteskwargs collapsemsgrNr/extrafns configboolbackupfkeepf keepbranchesfrZskip_empty_successorskipemptysuccessorf&obsolete_with_successor_in_destination%obsolete_with_successor_in_rebase_setinmemorydryrunstatemodZcmdstatestateobj)selfr7rIrerfrSer'r'r(__init__s>  zrebaseruntime.__init__cCs|jr|jS|jSdSr9)rPrRr?rir'r'r(r7s zrebaseruntime.repocCsV|r|jdd|jddn8|jdd}||Wdn1sH0YdS)z*Store the current status to allow recoveryrO)rOsplain)locationwN)Zaddfilegenerator _writestatusr7vfs)ritrfr'r'r( storestatusszrebaseruntime.storestatusc Cs |j}|||jd|d|||jd|dt|j|dt|j|dt|j|d|j pd|j }t |j D]V\}}||}|dkr||}nd|}|||}|d|||fq|jddS) N s%d %s r%ds %s:%s:%s srebase status stored )r7writerThexrUintrZr`rarVrWr iteritemsr rIdebug) rirrr7rWdvoldrevnewrevZdestnoder'r'r(ros"  zrebaseruntime._writestatuscCs|jst|jtd|}|jjd|d|_ |d|_ |d|_ |d|_ |d|_ |d|_|d |_|d |_|d |_d S) z"Restore a previously stored statusr3srebase status resumed originalwddestmapstateskippedcollapsekeep keepbranchesexternalactivebookmarkN)rhexistsr Zwrongtooltocontinuer7r_readrIr|rTrWr rYrZr`rarUrV)ridatar'r'r( restorestatuss         zrebaseruntime.restorestatuscCsTd|_|j}dddtddd}d}i}i}|d}t|D]N\}}|dkrh|||d<qD|dkr|r||}qD|dkr|||d<qD|d krtt ||d <qD|d krtt ||d <qD|d krtt ||d<qD|dkrt |dkr d|vs||d<qD| d} || d} | d} | t vrDqDt | dkrd|| d} n|} | || <| t krt|| <qD|| || <qD|ddurttd||d<||d<t} |d st|}t|D]2\}}|tkr||vr| |||q| |d<|jddddt| DpJd|S)NT)rrrrrrrOrrr&rrrrQ:rs.hg/rebasestate is incompleterrrscomputed skipped revs: %s  css|]}d|VqdSrwNr'.0rr'r'r( [rvz&rebaseruntime._read..rv)rPr7rrp enumerateread splitlinesrevboolrzrBsplit legacystates revtodostrrevtodorAbortrrXvaluessorteditemsaddrIr|join)rir7rZ legacydestr rWrrilargsrrdestrevrYseenoldnewr'r'r(rsv "        zrebaseruntime._readcsjr dSjddsdSfddjD}tj|j\__t j}| jt jj||t jt jrt _n6jdjjD] }j|dj|dqdS)zfrvz8rebaseruntime._handleskippingobsolete..sdescendants(%ld) and not %ld)r`rIr^r _compute_obsolete_setsr7rWrcrdrXupdate_checkobsrebaser isenabledallowdivergenceoptr@pop)riZ obsoletesetZ skippedsetrr'rlr(_handleskippingobsolete`s*   z%rebaseruntime._handleskippingobsoleteTcCsd|_z"||t|j||_Wnbtjy|rht|jt |j|jj t dYdSt d}t d}tj ||dYn0|r|o|j}|j||||dSdS)NTsFrebase aborted (no revision is removed, only broken state is cleared) rs#cannot continue inconsistent rebases-use "hg rebase --abort" to clear broken statehint)backup suppwarnsrfconfirm)rQrrrestorecollapsemsgr7r\rRepoLookupError clearstatusclearcollapsemsgrIwarnrrr__abort)riisabortrrrfrmsgrr'r'r(_prepareabortorcontinueys4   z%rebaseruntime._prepareabortorcontinuec Cs|s tSt|j||j}|s4|jtdtS|\|_|_|_ |jrt |j }t |dkrrt tdtt|}|jjj|gdd}t|j|j ||_tt | D]0}|j|}|r|js|jtd|q||jst |}|t |j8}||j8}i}t|jtjr8ddi}zD|j |"t!j"|j|d d Wdn1sp0YWnBt j#y} z&| j$durtd | _$| WYd} ~ n d} ~ 00d|_%dS) Nnothing to rebase r&s3--collapse does not work with multiple destinationsT)Z inclusives reopening closed branch head %s )rsevolution.allowdivergencestruer3)r4s&use --keep to keep original changesets)&r) buildstater7rZrIstatusrrTrWr rXrrBr InputErrornextiter changelogZ ancestorsexternalparentrUrZ closesbranchrarr`keysrcrdrrcreatemarkersoptconfigoverriderZprecheckrrrP) rirWresultrFr destancestorsdest rebaseset overridesrjr'r'r(_preparenewrebasesN     6  zrebaseruntime._preparenewrebasecCsf|jr.ddlm}||j|_|jjdn|jd|_|jjd|jjjdd|j|jddS)Nr)overlayworkingctxsrebasing in memory srebasing on disk r3susing in-memory rebase: %r )Zrebase_imm_used)reZmercurial.contextrr7wctxrIr|log)rirr'r'r(_assignworkingcopys   z rebaseruntime._assignworkingcopyc s4||j|j}}|jrn|jdt|jrnt}|j D]0}| || t |dkrrvz0rebaseruntime._performrebase..srebasings changesets)Zunittotalcsjd||fddS)N%d:%s)item)Z incrementrrJpr'r(progresssz.rebaseruntime._performrebase..progressssort(%ld, -topo)srebase merging completed )rr7rIrar]insertr2rZrXr rr1rBrrrrVZ_activebookmarkrZ deactivatersrr{Z makeprogress sortsourcerWr@ _rebasenodeZcompletenote) rirqr7rIZbranchesrZcandsrr<Z sortedrevsr'rr(_performrebases:     zrebaseruntime._performrebasec s|j}||}|dur|}|jsL|jt||fdd|jD}|j}|durb|}d| i}|j D]}|||qtt | t j} | |j d} |j| dP|jrt||j|||||d} nt||||||d} | WdS1s0YdS) zCommit the wd changes with parents p1 and p2. Reuse commit info from rev but also store useful information in extra. Return node of committed revision.Ncs,i|]$\}}|tkr||gqSr')rnode)rrrclr'r( sz/rebaseruntime._concludenode..s rebase_source))sphasess new-commit)uiallowemptycommitr3)rr+ commitmsgeditoruserrN)r+rrrrN)r7 descriptionrZrrZupdate_hash_refsr rrNryr]maxZphaserZdraftrbrIrrecommitmemorynoderr commitnode) rirrrr7r-rNr+cZ destphasernewnoder'rr( _concludenode sV       zrebaseruntime._concludenodec Cs|j|j|j}}}||}t|}|j||krJ|td|nX||jvr|td|} |j| |j |n&||j vr|j |} | durtd|} nt|| } td|| f} |j| |j |t t |||j |j|j} | |j|<n|j|tkr|td|||t|||j |j|j|j \} }}|jr|j| kr|jdd|_nd|d d i}||d zt||| |||j|jd Wntjyp|jrtd |jr|td zt|Wn(tjy.t |t!|Yn0d|_"|#t$j%|| |jdt||| |||j|jd Yn0Wdn1s0Y|js|t&k}t'|d }tj(fd|i|}|j)|| *||*|+||}nd}|durB|||j|<|dt,|||-r|.td|n>|jsh|.td||j || |j|<|d| n |td|||j|f|s|/dS)Nsalready rebased %s sInote: not rebasing %s and its descendants as this would cause divergence s+note: not rebasing %s, it has no successor s4note: not rebasing %s, already in destination as %s s rebasing %s sresuming interrupted rebase F)rs forcemergetoolrvr3)rsDhit merge conflicts; rebasing that commit again in the working copy )wceditformsrebased as %s sRnote: created empty successor for %s, its destination already has all its changes sCnote: not rebasing %s, its destination already has all its changes snext revision set to %d salready rebased %s as %s )0r7rIrSrKr rrrdrYrrcr adjustdestrWr defineparentsrQrp1rr|r,r rebasenoderZrInMemoryMergeConflictsErrorrfConflictResolutionRequiredr bailifchangedrrrrermergemodrrZ mergeeditformgetcommiteditor setparentsrrrisemptyrrs)rirqrZ progressfnr7rIrSr-ZdescrZsuccZsuccdescrrp2baserZmergingrrrr'r'r(rFs            ,     zrebaseruntime._rebasenodec Cs|j|j|j}}}|dt|}||jr&t|t |j |j |j |j |j \}}}|d}d} |jrz|j} n6d} t|j D]"} | |j vr| d|| 7} qd}tj|| d} t|j } |j||||j|j| | | d}|dur&||}|j D]}||j |<qd |vrLt||j |j fi||j |j|j}|d krn|j}|d d |dDvr|t d t!"||d}|jr|j#s|}t$|||j |j |j ||j#||j%d t&|t'||t dt(j)|*ddd|j r8t+|j }|t d||,|j-r~|j-|j.vr~|d|j.|j-kr~t/0||j-dS)Nr3editsrebase.collapsesCollapsed revisions * %sT)r r)rqtiprcSsg|] }|qSr'rrrr'r'r(rrvz/rebaseruntime._finishrebase..s0update back to initial working directory parent )fmrsrebase completed sundoZ ignoremissings%d revisions have been skipped .)1r7rIrS formatterrr[Z startitemrZrminr rWrYrcr,r\rrr rrrrrrUrrtagsupdatemqrTparentsrrrrr` clearrebasedr_rrr! unlinkpathZsjoinrBendrV _bookmarksractivate)rir7rIrSrrrZ_baseZeditoptrrrebasedrZ revtoreuserrrZnewwd collapsedasZ skippedlenr'r'r( _finishrebases            zrebaseruntime._finishrebasec sjzzfddjD}fdd|D}d}|rpjjtddfdd|Dtd d d }t}|rtj |}|t|rjtd d }|r6|rd dd|D} t|} | j |s|s| jd| v} | rtj|r6tjj| |djrZjjvrZtjWtt|sjtdn(tt|sjtd0dS)z-Restore the repository to its original state.cs2g|]*\}}|dkr||kr|j|kr|qSrrW)rrr.rlr'r(r.sz(rebaseruntime._abort..csg|]}|s|qSr')Zmutable)rr}r7r'r(r3rvTs-warning: can't clean up public changesets %s , c3s|]}t|VqdSr9bytesrr r'r(r8rvz'rebaseruntime._abort..s see 'hg help phases' for detailsrFsDwarning: new changesets detected on destination branch, can't strip cSsg|] }|qSr')rr r'r'r(rKs roots(%ld)rrsrebase aborted r)r7r rrIrrrrXr descendantsrrWrrrTrr clean_updaterstriprVrrrrr) rirrrfrrZ immutableZcleanupr&Z strippointsZupdateifonnodesZ shouldupdater')r7rir(r%sd    zrebaseruntime._abort)FFN)N)TFFF)N)TFFF)__name__ __module__ __qualname____doc__rkpropertyr7rsrorrrrrrrrrrrr'r'r'r(rLs& 1  M "4- :QrLr3sr*s5rebase the specified changesets and their descendantssREVbsbases=rebase everything from branching point of specified changesetrsrevsrebase these revisionsddestrvs#rebase onto the specified changesetrscollapse the rebased changesetsmsmessages#use text as collapse commit messagesTEXTesedits invoke editor on commit messageslslogfiles&read collapse commit message from filesFILEkrskeep original changesetsrskeep original branch namesDsdetachs (DEPRECATED)is interactivettoolsspecify merge toolsstopsstop interrupted rebasecscontinuescontinue an interrupted rebaseasabortsabort an interrupted rebases auto-orphanssLautomatically rebase orphan revisions in the specified revset (EXPERIMENTAL)s>[[-s REV]... | [-b REV]... | [-r REV]...] [-d REV] [OPTION]...)Z helpcategoryc Ks|dd}t|ddd}|rDt||ddgt||gdt|ddt|d d d |sr|d urvd }|drt|dh}t|d|t||d}t d|g|d <d|d<|ds|drt ||||S|dkrt ||}| |||jr2ttdt|tj}|jsd|sdtjtdtddt||j|Wd Wd dS1s0YWd n1s0Yn|rzzNddi} || d$t|||||dWd WS1s0YWnVtjyv|ddrB|tdt |t!|t||||d dYS0nt||||Sd S)aumove changeset (and descendants) to a different branch Rebase uses repeated merging to graft changesets from one part of history (the source) onto another (the destination). This can be useful for linearizing *local* changes relative to a master development tree. Published commits cannot be rebased (see :hg:`help phases`). To copy commits, see :hg:`help graft`. If you don't specify a destination changeset (``-d/--dest``), rebase will use the same logic as :hg:`merge` to pick a destination. if the current branch contains exactly one other head, the other head is merged with by default. Otherwise, an explicit revision with which to merge with must be provided. (destination changeset is not modified by rebasing, but new changesets are added as its descendants.) Here are the ways to select changesets: 1. Explicitly select them using ``--rev``. 2. Use ``--source`` to select a root changeset and include all of its descendants. 3. Use ``--base`` to select a changeset; rebase will find ancestors and their descendants which are not also ancestors of the destination. 4. If you do not specify any of ``--rev``, ``--source``, or ``--base``, rebase will use ``--base .`` as above. If ``--source`` or ``--rev`` is used, special names ``SRC`` and ``ALLSRC`` can be used in ``--dest``. Destination would be calculated per source revision with ``SRC`` substituted by that single source revision and ``ALLSRC`` substituted by all source revisions. Rebase will destroy original changesets unless you use ``--keep``. It will also move your bookmarks (even if you do). Some changesets may be dropped if they do not contribute changes (e.g. merges from the destination branch). Unlike ``merge``, rebase will do nothing if you are at the branch tip of a named branch with two heads. You will need to explicitly specify source and/or destination. If you need to use a tool to automate merge/conflict decisions, you can specify one with ``--tool``, see :hg:`help merge-tools`. As a caveat: the tool will not be used to mediate when a file was deleted, there is no hook presently available for this. If a rebase is interrupted to manually resolve a conflict, it can be continued with --continue/-c, aborted with --abort/-a, or stopped with --stop. .. container:: verbose Examples: - move "local changes" (current commit back to branching point) to the current branch tip after a pull:: hg rebase - move a single changeset to the stable branch:: hg rebase -r 5f493448 -d stable - splice a commit and all its descendants onto another part of history:: hg rebase --source c0c3 --dest 4cf9 - rebase everything on a branch marked by a bookmark onto the default branch:: hg rebase --base myfeature --dest default - collapse a sequence of changes into a single commit:: hg rebase --collapse -r 1520:1525 -d . - move a named branch while preserving its name:: hg rebase -r "branch(featureX)" -d 1.3 --keepbranches - stabilize orphaned changesets so history looks linear:: hg rebase -r 'orphan()-obsolete()' -d 'first(max((successors(max(roots(ALLSRC) & ::SRC)^)-obsolete())::) + max(::((roots(ALLSRC) & ::SRC)^)-obsolete()))' Configuration Options: You can make rebase require a destination if you set the following config option:: [commands] rebase.requiredest = True By default, rebase will close the transaction after each commit. For performance purposes, you can configure rebase to use a single transaction across the entire rebase. WARNING: This setting introduces a significant risk of losing the work you've done in a rebase if the rebase aborts unexpectedly:: [rebase] singletransaction = True By default, rebase writes to the working copy, but you can configure it to run in-memory for better performance. When the rebase is not moving the parent(s) of the working copy (AKA the "currently checked out changesets"), this may also allow it to run even if the working copy is dirty:: [rebase] experimental.inmemory = True Return Values: Returns 0 on success, 1 if nothing to rebase or there are unresolved conflicts. r3sexperimental.inmemoryabortstopcontinuerdry_run)rsourcer rrrAr NFZ auto_orphanss%ld and orphan()s_destautoorphanrebase(SRC)rs!cannot stop in --collapse sessions<cannot remove original changesets with unrebased descendantss^either enable obsmarkers to allow unstable revisions or use --keep to keep original changesetsrrr3singletransactionT)rer#r$s?hit merge conflicts; re-running rebase without in-memory merge )"r^r Zcheck_at_most_one_argZcheck_incompatible_argumentscurrenttransactionr,rXlistr@r formatspec _dryrunrebaserLwlocklockrrZrrCrrrZallowunstableoptr`rr'rTrr _dorebaserrrr) rIr7rSrer4Zdisallowed_optsZuserrevsrbsrtZ allowunstablerr'r'r(rebasejsx=       P8rLc Cst||dd|d}|d}|r0|tdn|td|4|d}zzddi}||d|t|||||}|tkrd}|WdWW|r|j ddd|d d WdWdSWdn1s0YWnxt j y`|td YW|rD|j ddd|d d WdWdd St j yzd}Yn0|r|td | tds|n|j ddd|dd}n|tdW|r|j ddd|d d WdWddSW|rN|j ddd|d d n |rL|j ddd|d d 0Wdn1sd0YWdn1s0YdS)NT)rerfrSrsstarting in-memory rebase s8starting dry-run rebase; repository will not be changed rBr3Fr@)rrrrfshit a merge conflict r&srebase completed successfully s!apply changes (yn)?$$ &Yes $$ &No)rrrrsWdry-run rebase completed successfully; run without -n/--dry-run to perform this rebase r)rLr,rrrHrIr _origrebaser)rrrrZ promptchoicer) rIr7r4rSrKrZ needsabortrresr'r'r(rGss  @ rGcCs t||||d}t|||||S)N)rS)rLrM)rIr7r4rSrerKr'r'r(rJsrJc Cs|r|F|drjztdr2d}WntyJd}Yn0d|}td|}t||j r|j sttd|r|j rttd|d kr|d d r| td |d krt j |}t||j|d kd} | dur| WdWdSn|d} t|||j|dd|dg|dg|dg| d} || } | dur| WdWdSt||j d} |dd} | r|d} t| td}| r|jst|d}t|*|| |js|Wdn1s$0YWdn1sD0YWdn1sd0YWdn1s0YdS)N interactiveshisteditrvs --config extensions.histedit=shg%s help -e histeditsOinteractive history editing is supported by the 'histedit' extension (see "%s")s+message can only be specified with collapses*cannot use collapse with continue or abortr=rFstool option will be ignored r?r _destspacerrAr rr6r3rC)rHrIr,rfindKeyErrorrrrr\rZr mergestatemodrrrcheckunresolvedr_definedestmaprerstorecollapsemsgr^Z transactionr!Zacceptinterventionr rrfr)rIr7r4rSrKZenablehistedithelprmsretcoder6rWrqZsingletrdsguardr'r'r(rMsv         "               rMc s|dur g}t|s$t|ddrJ|sJtjtdtddd}|rxt|} | st| tddSn|rt|} | s| tddS d | | } nt|pd g} | s| td dS|rt |}nt | |d }t |}g} i} | D]2} d ||}| |g|g| |<qd| vrV| t| D] \}}| t d||7} q` d| } | sZt| |gkr|r| td|n| tdn d| |s,|r| tddfdd| D|fn| td|n*| tddfdd| D|fdSt| vrrttdd | v}|jdd||d|r|rtt|sԈt | |d }t |}td| }d|i}|durztj ||d }Wntjyi}| D]}td!||d"<j|gd#|d$}t|}|d%krf|||<n8|d&kr|td'|nttd(|q Yn0|dur|fd)d*| D}|s| td+dS|S),z:use revisions argument to define destmap {srcrev: destrev}Ncommandsrebase.requiredestsyou must specify a destinationsuse: hg rebase -d REVrs-empty "rev" revision set - nothing to rebase s0empty "source" revision set - nothing to rebase s(%ld):: + (%ld)rs5empty "base" revision set - can't compute rebase set rRsancestor(%d, %d)schildren(%d) & ancestors(%ld)s%ld::s6nothing to rebase - %s is both "base" and destination sAnothing to rebase - working directory parent is also destination s %ld - ::%dsGnothing to rebase - "base" %s is already an ancestor of destination %s +c3s|]}t|VqdSr9r"rr r'r(r]rvz!_definedestmap..sVnothing to rebase - working directory parent is already an ancestor of destination %s s nothing to rebase from %s to %s c3s|]}t|VqdSr9r"rr r'r(rkrvscannot rebase the working copyr3s!rebasing working copy parent: %r )Zrebase_rebasing_wcps%ldsALLSRC) localaliasrwsSRCT)rr`r&rs skipping %s - empty destination s'rebase destination for %s is not uniquecsi|] }|qSr'r'r)rr'r(rrvz"_definedestmap..s&nothing to rebase - empty destination )r checkunfinishedrr^rrrrZrevrangerr@Z revsingler8r#rrAr,clearrr{rErrrrrFrrZanyrevsrBr)rIr7reZdestfZsrcfZbasefZrevfr6rrrEr rootsZbpbasebZbpbsZ rebasingwcpZallsrcaliasrWrZdestsetsizer')rr7r(rWs                 rWc Cst}t|}|D]F}||kr q||D]*}||vr,||vr,||q,q|sbtSt|dkrv|St t dt |d ddt |DfdS)zReturn the revision that should be used as the second parent when the revisions in state is collapsed on top of destancestors. Abort if there is more than one parent. r&sKunable to collapse on top of %d, there is more than one external parent: %sr!css|]}d|VqdSrr'rrr'r'r(rrvz!externalparent..N)rXrrrrrrBrrrCrrrr)r7r rrrArrr'r'r(rs& rc Csbd}d|vr|d}||j||||||d}|rL|jddsLdS||} || S)zXCommit the memory changes with parents p1 and p2. Return node of committed revision.Nr0)rNr+rr1rrr)Z_compactZtomemctxrrIr^Z commitctxZclean) r7rrr+rrNrr1ZmemctxZ commitresr'r'r(rs" rcCsvt}|jdds"t|d}|<|j|||||d}|j|||WdS1sh0YdS)zTCommit the wd changes with parents p1 and p2. Return node of committed revision.r3rC)textrrNr+rN) r!ZnullcontextmanagerrIr^r ZcommitdirstateZ setbranchr1)r7rr+rrNrr\rr'r'r(rs  rc CsN||}|r||nT|d|krL|jd||ft|n |jd|d}|j| ||}|jd||f|dur|jd|||f|j | | } tj ||dd|| gd|d } || || |rt|||nt|||| jd krJ|r@tn td dS) zFRebase a single revision rev on top of p1 using base as merge ancestorrs update to %d:%s s already in destination Ns merge against %d:%s s detach base %d:%s T)r2r*sparent of source)Z branchmergeforceancestor mergeancestorlabelsrrr3)Z isinmemoryZsetbaserrIr|rr'rjrxrDr isancestorrZ_updaterr Z graftcopiesrZunresolvedcountrrr) r7rrrr rMrZp1ctxr-rmZstatsr'r'r(rs@       rc s|fdd|D}g}|j|D]j}}|tkrd|d||} | durd|| }|kr|vr|}|tkrtd| |q2|S)aadjust rebase destination given the current rebase state rev is what is being rebased. Return a list of two revs, which are the adjusted destinations for rev's p1 and p2, respectively. If a parent is nullrev, return dest without adjustment for it. For example, when doing rebasing B+E to F, C to G, rebase will first move B to B1, and E's destination will be adjusted from F to B1. B1 <- written during rebasing B | F <- original destination of B, E | | E <- rev, which is being rebased | | | D <- prev, one parent of rev being checked | | | x <- skipped, ex. no successor or successor in (::dest) | | | C <- rebased as C', different destination | | | B <- rebased as B1 C' |/ | A G <- destination of C, different Another example about merge changeset, rebase -r C+G+H -d K, rebase will first move C to C1, G to G1, and when it's checking H, the adjusted destinations will be [C1, G1]. H C1 G1 /| | / F G |/ K | | -> K | C D | | |/ | | B | ... |/ |/ A A Besides, adjust dest according to existing rebase information. For example, B C D B needs to be rebased on top of C, C needs to be rebased on top \|/ of D. We will rebase C first. A C' After rebasing C, when considering B's destination, use C' | instead of the original C. B D \ / A cs0g|](\}}|dkr|kr|vr|qSrr')rr.r}rrWrYr'r(rTszadjustdest..smax(%ld and (::%d))Ns-rev %d should be rebased already at this time) rr parentrevsrr@rArrZProgrammingErrorappend) r7rrWr rYrArprevZadjusted candidater'rpr(rs&5 rc s^ttj}||}|rZ|sZfdd|D}td}td}tj|d|f|ddS)a Abort if rebase will create divergence or rebase is noop because of markers `rebaseobsrevs`: set of obsolete revision in source `rebaseobsskipped`: set of revisions from source skipped because they have successors in destination or no non-obsolete successor. c3s|]}t|VqdSr9r"rr r'r(ryrvz"_checkobsrebase..s+this rebase will cause divergences from: %ssJto force the rebase please set experimental.evolution.allowdivergence=True,rN)rrrrrrCr) r7rI rebaseobsrevsZrebaseobsskippedZ divergenceokZdivergencebasecandidatesZ divhashesrhr'r r(rls rccsB|jjj}t|j||gD]}||}|dur"|Vq"dS)z,yield revision numbers for successors of revN)rindexget_revr allsuccessorsobsstorer)rDrryr.rr'r'r( successorrevss  r|csfjj|}j}ttgt|||t|}tdd|ddDrjdd<n.t|D]\} | } tfddt | Dr} n| |vr|| dkr|| } tdD]R\} } | tkrqԈ| | rt} qԈ| | r| | <t} ||| || <|<q| <qrdtkrb|ddkrb | t t |kr|vrt tdftfddDrt td tfd dt |Ddkr8ddg} t|D]\}|tks|vrqt ||h}td |||}|rfd d |D}fdd |D}td|||| <qtdd| Dr8tddt| D\}|dkrtdfdd| D}t td|fdkr8tkrdd<<||d|d<|<|d}jdtdd|fS)aReturn new parents and optionally a merge base for rev being rebased The destination specified by "dest" cannot always be used directly because previously rebase result could affect destination. For example, D E rebase -r C+D+E -d B |/ C will be rebased to C' B C D's new destination will be C' instead of B |/ E's new destination will be C' instead of B A The new parents of a merge is slightly more complicated. See the comment block below. css|]}|tkVqdSr9rrr'r'r(rrvz defineparents..r&Nrc3s|]}|VqdSr9r')rr=)rFrror'r(rrvs>cannot rebase %d:%s without moving at least one of its parentsc3s |]}|tko|VqdSr9r}rh)rorr'r(rrv!source is ancestor of destinationc3s"|]}|tkr|vrdVqdS)r&Nr})rrd)newpsr'r(rrvs(%ld %% (%d+%d))cs$g|]\}}|dkr|vr|qSrr')rrr}) obsskippedr'r(rsz!defineparents..cs"g|]}|dtkr|qS)r&)rqrrrr'r(rss%ld - (::%ld) - %ldcss|]}|duVqdSr9r'rr@r'r'r(rrvcss&|]\}}|durt||fVqdSr9)rB)rrr@r'r'r(r ss or c3s.|]&}|durdfdd|DVqdS)Nr!c3s|]}d||fVqdS)rNr'rr r'r(r+rvz*defineparents...)rrr r'r(r*ss4rebasing %d:%s will include unwanted changes from %ss future parents are %d and %d )r isancestorrevrqrrrEallranyr|reverserXrrrsumr@rrrrIr|tuple)r7rrWr rYrrZoldpsbasesrZnpjr=Zunwantedr  other_basesZsiderevsrZmergesrZ unwanteddescr')rrFrrorrr7rr(rs                  rcCs<tj|jj|}tt|dD]}|dr"dSq"dS)z/Return true if the given patch is in git formatsrbs diff --gitTF)ospathrmqrZ linereaderr startswith)r7 patchnameZmqpatchliner'r'r( isagitpatchFs  rc sBi}|jjdd}tjD]T}||j}||vrl|jd||jf|jt ||jf||<q$ |jq$|r> || t |ddD]p}||vr||\}} |jtd||||||fj|d|| d||gdq ||d qfd d |D} | jdd<d_dS) z9Update rebased mq patches - finalize and then import themNs.revision %d is an mq patch (%s), finalize it. T)rsupdating mq patch %s to %d:%s r'rw)rgitrrcs&g|]}j|ddvr|qS)r&r)Zguard_rerrr.rZskippedpatchesr'r(r{szupdatemq..)rZ fullseriesrXappliedrrrIr|namerrZfinishrrrrZqimportZ seriesdirtyZ savedirty) r7r rYrSZmqrebaseZoriginal_seriesrrrZisgitZ newseriesr'rr(rOsL     rcCs.|pd}|dd}|d||dS)z,Store the collapse message to allow recoveryrvlast-message.txtrnruN)rprxclose)r7r\rrr'r'r(rXs rXcCs|jjddddS)zRemove collapse message filerTrN)rprr r'r'r(rsrc Csrz"|d}|}|WnJtyl}z2|jtjkr@|rJd}ntt dWYd}~n d}~00|S)z*Restore previously stored collapse messagerrvs'missing .hg/last-message.txt for rebaseN) rpreadliner(rIOErrorerrnoENOENTrrr)r7rrrr\errr'r'r(rs    $rcCs*|}|r|d|jjddddS)zRemove the status filesrOTrN)rDZremovefilegeneratorrpr)r7rqr'r'r(rs rccsbt|}|r^t|}g}|D]}|||vr||q|sJttd|t|8}|VqdS)ayield source revisions in an order that we only rebase things once If source and destination overlaps, we should filter out revisions depending on other revisions which hasn't been rebased yet. Yield a sorted list of revisions each time. For example, when rebasing A to B, B to C. This function yields [B], then [A], indicating B needs to be rebased first. Raise if there is a cycle so the rebase is impossible. s#source and destination form a cycleN)rXrrrrrr)rWZsrcsetZsrclistrrr'r'r(rs    rcs|}d}dvrTfddjjD}t||@rTtt dt t |}|srt t dt d|d}|st t dd d }t ||d }t|tt|d k} |D]} || } | | } | | krt t d | | krvd} | | kr.| | k}n| | k}|sv|rv| | vrv| | <jdqd} jd| | fq| rdSt D]B}ddj|D}|rtfdd|Dr||<q||fS)zlDefine which revisions are going to be rebased and where repo: repo destmap: {srcrev: destrev} rr csh|]}|jqSr')rrrr r'r(rrvzbuildstate..s&cannot rebase onto an applied mq patchsno matching revisionsr$rcSs|Sr9r )rr'r'r(revofszbuildstate..revof)keyr&r~Ns!source is a child of destination Fs rebase onto %s starting from %s cSsg|]}|tkr|qSr'r}rhr'r'r(rrvzbuildstate..c3s|]}||kVqdSr9)r,rh)r r'r(rrvzbuildstate..)rrrrrrXrrrCrrErrrdictfromkeysrrBrlrr1rrIr|rrqr)r7rWrMrrTZ mqappliedZ sortedsrcrcrZ emptyrebaserootrZ commonbaserZ samebranchrrr')r7r r(rsN           rTc sZ|jj} i} i} t|tj } g} t|D]~\}}|dkr0||kr0| |}|pZ| |}|| |<d}||vr| s||sd}n|r| |n|f}|dur0|| |f<q0| r|f| t| <|r8|j |j }|j }i}t | D]4\}}|D]&}|fdd|Ddd||<qq||dd d }|j|d |rBi} tj|| d | |d dS)a~dispose of rebased revision at the end of the rebase If `collapsedas` is not None, the rebase was a collapse whose result if the `collapsedas` node. If `keepf` is not True, the rebase has --keep set and no nodes should be removed (but bookmarks still need to be moved). If `backup` is False, no backup will be stored when stripping rebased revisions. rNr'csg|] }|qSr'r')rnZhfr'r(r=rvz clearrebased..snode)rsoldnodesnewnodes)rvalue) nodechangesr3r%)rrrrrrrrrrZhexfuncZ formatlistZ formatdictrr{rrZ cleanupnodes)rIr7rWr rYrr`rrZtonodeZ replacementsZmovesZ stripcleanupZcollapsednodesrrZoldnoderZsuccsZflfdZchangesZoldnsZnewnZoldnrr'rr(r sD   & rc Os |dr|ddr6td}td}tj||d||T|drh|d=|dtj |d d tj |td dt |}t j }d d } | t _ z"|||g|Ri|} W|t _ n|t _ 0t |} | |krd|vr|d=d|vr|d=t|jj|d} | |d<zt||fi|Wnbtjyt|\} }}| |dkrr|tdn|tdt ||Yn0Wdn1s0YWdn1s0Yn2|drttd|||g|Ri|} | S)zCCall rebase after pull if the latter has been invoked with --rebaserLr]r^s,rebase destination required by configurations)use hg pull followed by hg rebase -d DESTrrsC--update and --rebase are not compatible, ignoring the update flag T)Z skipmergesCcannot pull with rebase: please commit or shelve your changes firstc_sdSr9r')rkwargsr'r'r(_dummyaszpullrebase.._dummyrrA)startrQrrs%nothing to rebase - updating instead Nrs%--tool can only be used with --rebase)r,r^rrrrHrIr|r rarrBr Z postincomingrErr@rLZNoMergeDestAbortr Z destupdaterrr)ZorigrIr7rrSrrZ revsprepullZorigpostincomingrretZ revspostpullr6rZ_aZ_br'r'r( pullrebaseEsZ    T rc si}t}|j}|jjt|d}|D]}||}tt|j|g} | |fdd| D} | d| r| |rd||<q*|} | D]} | | | r| ||<q*q||vst fdd| Dr*||q*||fS)aiFigure out what to do about about obsolete revisions `obsolete_with_successor_in_destination` is a mapping mapping obsolete => successor for all obsolete nodes to be rebased given in `rebaseobsrevs`. `obsolete_with_successor_in_rebase_set` is a set with obsolete revisions, without a successor in destination, that would cause divergence. s extinct()csh|] }|qSr'r'r)ryr'r(rrvz)_compute_obsolete_sets..Nc3s|]}|vVqdSr9r'rrr'r(rrvz)_compute_obsolete_sets..)rXrrxryr@rrrzr{removediscardissubsetrrr) r7rvrWrcrdrZ extinctrevsZsrcrevZsrcnodeZ successorsZsuccrevsZdstrevZsuccrevr')rWryr(rs.       rc Csj|N|&t||}|jddWdn1s>0YWdn1s\0YdS)NTrP)rHrIrLr)rIr7rKr'r'r( abortrebases rc Cs||vt||}tj|}t||jdd}|durh|WdWdS| d| Wdn1s0YWdn1s0YdS)NFrP) rHrIrLrUrrrrVrrr)rIr7rKrZr[r'r'r(continuerebases      rcCs|jdsdSzt||i}||j}Wn(tjyVtd}||YdS0t ddt |D}|td| tdd|| tdd t ||fdS) NrOs8rebase: (use "hg rebase --abort" to clear broken state) cSsg|]}|dkr|qSrr')rrr'r'r(rrvzsummaryhook..s#rebase: %s, %s (rebase --continue) s %d rebasedsrebase.rebaseds %d remainingsrebase.remaining) rprrLrr rrrrxrBrZ itervaluesZlabel)rIr7rKr rZ numrebasedr'r'r( summaryhooks(     rcCslttjdt}|ddddtdf|ddddtdftj dt t j dd d d t td dS) Nspullr&rvr3s'rebase working directory to branch headr9r:sspecify merge tool for rebaserOT)fnameZstopflagZ continueflagZ abortfuncZ continuefunc)rZ wrapcommandr tablerrrrr Z summaryhooksrrrgZ addunfinishedrr)rIentryr'r'r(uisetupsr)N)F)NFNT)]r,Z __future__rrrZmercurial.i18nrZmercurial.noderrrZmercurial.pycompatrZ mercurialrr r r r r rrrrrrrUrrrrrrrrrrrrrr rgr!rrrZcmdtablerHZ configtableZ configitemZ testedwithr)r/r2r8Zrevsetpredicater>rGrKobjectrLZ dryrunoptsZ formatteroptsZ confirmoptsZCATEGORY_CHANGE_MANAGEMENTrLrGrJrMrWrrrrrrr|rrrrXrrrrrrrrrrrrr'r'r'r(s   p!       L9:;<A I? N"2N ; 6 I <E-