o ]LbH@sdZddlmZddlZddlZddlmZddlmZm 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~ZTddZU   dddZVddZWddZXddZYddZZddZ[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>-2-3-4-5develrebase.force-in-memory-mergeF)defaultsships-with-hg-corecCsdS)Nr+r+r+./usr/lib/python3/dist-packages/hgext/rebase.py_nothingtorebaseVr-cCsH|dd}|dur||d<|dd}|dur"||d<dSdS)Nsourcesintermediate-source)extraget)ctxr0sr+r+r, _savegraftZs r4cCs||d<dS)Nbranch)branch)r2r0r+r+r, _savebranchcsr7cCstj|d|d|dS)zhsmall wrapper around destmerge to pass the right extra args Please wrap destutil.destmerge instead.rebaseF)action sourceset onheadcheck destspace)r destmerge)repor:r<r+r+r, _destrebasegsr?s _destrebasecCs6d}|durt|t||}|tt||g@SN)rgetsetr fullreposetbasesetr?)r>subsetxr:r+r+r,_revsetdestrebasewsrFs_destautoorphanrebasecCsp|}|d}t|||}|r||vrtSt||}t |dkr3t t d||ft|S)Ns obsolete()r*s8ambiguous automatic rebase: %r could end up on any of %r) unfilteredrevsrrAfirstrrCr orphanpossibledestinationlenr StateErrorr)r>rDrEunfi obsoletedsrcdestsr+r+r,_revsetdestautoorphanrebases     rQcCstj|j|ddS)zshort description for a contextr8)command)r format_changeset_summaryr>uir2r+r+r,_ctxdescs rVc@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|duri}d|_d|_||_||_||_d|_t|_i|_d|_ i|_ t |_ | dd|_t|t||_| dd|_| d}tg|_|rO|g|_|dd|_| dd|_| dd|_t|jd |_i|_t |_||_ ||_!t"#|d |_$dS) NFcollapsedateextrafnsrewrites backup-bundlekeep keepbranchesr8 rebasestate)%preparedresume_reporTopts originalwdrexternalr activebookmarkdestmapsetskippedr1 collapsefr logmessager byteskwargs collapsemsgrYr4extrafns configboolbackupfkeepf keepbranchesfrskip_empty_successorskipemptysuccessorf&obsolete_with_successor_in_destination%obsolete_with_successor_in_rebase_setinmemorydryrunstatemodcmdstatestateobj)selfr>rTrurvraer+r+r,__init__s>  zrebaseruntime.__init__cCs|jr|jS|jSr@)r^r`rGrzr+r+r,r>s zrebaseruntime.repocCsZ|r|jdd|jdddS|jdd}||WddS1s&wYdS)z*Store the current status to allow recoveryr])r]splain)locationwN)addfilegenerator _writestatusr>vfs)rztrfr+r+r, storestatuss  "zrebaseruntime.storestatusc Cs|j}|jdus J|||jd|d|||jd|dt|j|dt|j|dt|j |d|j pLd|j }t |jD]+\}}||}|dkrm||}nd|}|||}|d|||fqX|jddS) N s%d %s r%ds %s:%s:%s srebase status stored )r> filternamewriterbhexrcintrhrorprdrer iteritemsr rTdebug) rzrr>redvoldrevnewrevdestnoder+r+r,rs$  zrebaseruntime._writestatuscCs|jst|jtd|}|jjd|d|_ |d|_ |d|_ |d|_ |d|_ |d|_|d |_|d |_|d |_d S) z"Restore a previously stored statusr8srebase status resumed originalwddestmapstateskippedcollapsekeep keepbranchesexternalactivebookmarkN)ryexistsr wrongtooltocontinuer>r_readrTrrbrer rgrhrorprcrd)rzdatar+r+r, restorestatuss         zrebaseruntime.restorestatuscCsRd|_|j}|jdus Jdddtddd}d}i}i} |d}t|D]\}}|dkr;|||d<q*|dkrH|rG||}q*|dkrU|||d<q*|d krbt t ||d <q*|d krot t ||d <q*|d kr|t t ||d<q*|dkrt |dkrd|vs||d<q*| d} || d} | d} | t vrq*t | dkr|| d} n|} | || <| tkrt|| <q*|| || <q*|ddurttd||d<||d<t} |d st|}t|D]\}}|tkr||vr| |||q| |d<|jddddt| Dp$d|S)NT)rrrrrrr]rrr*rrrrQ:rs.hg/rebasestate is incompleterrrscomputed skipped revs: %s  cs|]}d|VqdSrNr+.0rr+r+r, [z&rebaseruntime._read..r)r^r>rrr enumerateread splitlinesrevboolrrKsplit legacystates revtodostrrevtodorAbortrrfvaluessorteditemsaddrTrjoin)rzr>r legacydestr rerilargsrrdestrevrgseenoldnewr+r+r,rs|           zrebaseruntime._readcsjrdSjddsdSfddjD}tj|j\__t j}| jt jj||t jt jrFt _dSjdjjD]}j|dj|dqPdS)zrrr}r+r, fsz8rebaseruntime._handleskippingobsolete..sdescendants(%ld) and not %ld)rorTrmr _compute_obsolete_setsr>rersrtrfupdate_checkobsrebaser isenabledallowdivergenceoptrHpop)rz obsoleteset skippedsetrr+r}r,_handleskippingobsolete`s,   z%rebaseruntime._handleskippingobsoleteTcCsd|_z||t|j||_Wn/tjyC|r4t|jt |j|jj t dYdSt d}t d}tj ||dw|rT|oJ|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 suppwarnsrvconfirm)r_rrrestorecollapsemsgr>rkrRepoLookupError clearstatusclearcollapsemsgrTwarnrrrn_abort)rzisabortrrrvrmsgrr+r+r,_prepareabortorcontinueys8   z%rebaseruntime._prepareabortorcontinuec Cs|stSt|j||j}|s|jtdtS|\|_|_|_ |jrRt |j }t |dkr9t tdtt|}|jjj|gdd}t|j|j ||_tt | D]}|j|}|rr|jsr|jtd|qZ||jst |}|t |j8}||j8}i}t|jtjrddi}z!|j |t!j"|j|d d Wdn1swYWnt j#y} z | j$durtd | _$| d} ~ wwd|_%dS) Nnothing to rebase r*s3--collapse does not work with multiple destinationsT) inclusives reopening closed branch head %s )rsevolution.allowdivergencestruer8)r9s&use --keep to keep original changesets)&r- buildstater>rhrTstatusrrbrer rfrrKr InputErrornextiter changelog ancestorsexternalparentrcr closesbranchrprrokeysrsrtrrcreatemarkersoptconfigoverriderprecheckrrr^) rzreresultrPr destancestorsdest rebaseset overridesr{r+r+r,_preparenewrebasesX        zrebaseruntime._preparenewrebasecCsf|jrddlm}||j|_|jjdn |jd|_|jjd|jjjdd|j|jddS)Nr)overlayworkingctxsrebasing in memory srebasing on disk r8susing in-memory rebase: %r )rebase_imm_used)rumercurial.contextrr>wctxrTrlog)rzrr+r+r,_assignworkingcopys    z rebaseruntime._assignworkingcopyc s2||j|j}}|jr7|jdt|jr7t}|j D]}| || t |dkr6t tdq|jp<|j|_|jrFt|||rQ||ddt|j D}|jjtdtdt |dfd d }t|jD]}|jd |} | D] }||||qqv|td dS) Nrr*s'cannot collapse multiple named branchescSsg|] \}}|tkr|qSr+)r)rkrr+r+r, z0rebaseruntime._performrebase..srebasings changesets)unittotalcsjd||fddS)N%d:%s)item) incrementrrUpr+r,progresssz.rebaseruntime._performrebase..progressssort(%ld, -topo)srebase merging completed )rr>rTrprlinsertr7rhrfr rr6rKrrrrd_activebookmarkr deactivaterrr makeprogress sortsourcererH _rebasenodecompletenote) rzrr>rTbranchesrcandsrrD sortedrevsr+rr,_performrebases>     zrebaseruntime._performrebasec s|j}||}|dur|}|js&|jt||fdd|jD}|j}|dur1|}d| i}|j D]}|||q:t | t j} | |j d} |j| d(|jrkt||j|||||d} n t||||||d} | WdS1swYdS) 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, s z/rebaseruntime._concludenode..s rebase_source))sphasess new-commit)uiallowemptycommitr8)rr0 commitmsgeditoruserrY)r0rrrrY)r> descriptionrhrrupdate_hash_refsr rrYrrlmaxphaserdraftrrrTrrucommitmemorynoderr commitnode) rzrrrr>r2rYr0c destphasernewnoder+rr, _concludenode sX       $zrebaseruntime._concludenodec Cs|j|j|j}}}||}t|}|j||kr%|td|n||jvr>td|} |j| |j |n||j vr|j |} | durStd|} nt|| } td|| f} |j| |j |t t |||j |j|j} | |j|<nH|j|tkr|td|||t|||j |j|j|j \} }}|jr|j| kr|jdd|_nd|d d i}||d nzt||| |||j|jd WnVtjy0|jrtd |jr|td zt|Wntjyt |t!|wd|_"|#t$j%|| |jdt||| |||j|jd YnwWdn 1srTrarVr rrrtrgrrsr adjustdestrer defineparentsr_rp1rrr1r rebasenoderhrInMemoryMergeConflictsErrorrvConflictResolutionRequiredr bailifchangedrrrrurmergemodrr mergeeditformgetcommiteditor setparentsrr'risemptyrr)rzrr progressfnr>rTrar2descrsuccsuccdescrr-p2basermergingr*rr&r+r+r,r Fs             +     zrebaseruntime._rebasenodec Cs~|j|j|j}}}|dt|}||jrt|t |j |j |j |j |j \}}}|d}d} |jr<|j} nd} t|j D]} | |j vrT| d|| 7} qCd}tj|| d} t|j } |j||||j|j| | | d}|dur||}|j D]}||j |<qd |vrt||j |j fi||j |j|j}|d kr|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 rt+|j }|t d||,|j-r9|j-|j.vr;|d|j.|j-kr=t/0||j-dSdSdSdS)Nr8editsrebase.collapsesCollapsed revisions * %sT)r>r*)rqtiprcSg|]}|qSr+rrr$r+r+r,rz/rebaseruntime._finishrebase..s0update back to initial working directory parent )fmrsrebase completed sundo ignoremissings%d revisions have been skipped .)1r>rTra formatterrrj startitemrhr,minr rergrsr1rkrrr r4rrr5rrcr'rtagsupdatemqrbparentsrrr2rro clearrebasedrnrrr! unlinkpathsjoinrKendrd _bookmarksractivate)rzr>rTrarDr-r;_baseeditoptr*rrebasedr revtoreuser&rrnewwd collapsedas skippedlenr+r+r, _finishrebases           zrebaseruntime._finishrebasec sjzfddjD}fdd|D}d}|r7jjtddfdd|Dtd d d }t}|rDtj |}|t|rTjtd d }|r|rcd dd|D} t|} | j |sy|sy| jd| v} | rtj|rtjj| |djrjjvrtjWtt|sjtddStt|sψjtdww)z-Restore the repository to its original state.cs2g|]\}}|dkr||kr|j|kr|qSrre)rrr3r}r+r,r.s z(rebaseruntime._abort..csg|] }|s|qSr+)mutable)rrr>r+r,r3rTs-warning: can't clean up public changesets %s , c3|] }t|VqdSr@bytesrr_r+r,r8z'rebaseruntime._abort..s see 'hg help phases' for detailsrFsDwarning: new changesets detected on destination branch, can't strip cSr@r+)rrBr+r+r,rKs roots(%ld)rGrsrebase aborted r)r>r rrTrrrrfr descendantsrrerrrbrr2 clean_updaterstriprdrRrrSrr) rzrrrvrrV immutablecleanuprg strippointsupdateifonnodes shouldupdater+)r>rzr,r%sh    zrebaseruntime._abort)FFNr@)TFFF)__name__ __module__ __qualname____doc__r|propertyr>rrrrrrrrrr'r r[rr+r+r+r,rWs( 1   M "4 -:QrWr8sr/s5rebase the specified changesets and their descendantssREVbsbases=rebase everything from branching point of specified changesetrsrevsrebase these revisionsddestrs#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]...) helpcategoryc Ks|dd}t|ddd}|r"t||ddgt||gdt|ddt|d d d |s9|d ur;d }|dret|dh}t|d|t||d}t d|g|d <d|d<|dso|drvt ||||S|dkrt ||}| V|A||jrttdt|tj}|js|stjtdtddt||j| Wd Wd dS1swYWd d S1swYd S|r:z(ddi} || dt|||||dWd WS1swYWd Stjy9|ddr|tdt |t!|t||||d dYSwt||||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. r8sexperimental.inmemoryabortstopcontinuerdry_run)rsourcer<rrrr<NF 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 changesetsrrr8singletransactionT)rur'r(s?hit merge conflicts; re-running rebase without in-memory merge )"rmr check_at_most_one_argcheck_incompatible_argumentscurrenttransactionr1rflistrHr formatspec _dryrunrebaserWwlocklockrrhrrLrrrallowunstableoptror2rhrbr[r _dorebaser/rrr) rTr>rarur9disallowed_optsuserrevsrbsrt allowunstablerr+r+r,rebasejs~ =      P* rc CsPt||dd|d}|d}|r|tdn|td||d}zzRddi}||d>t|||||}|tkrnd}|WdWW|r_|j ddd|d d WdWdSWdn1sxwYWn7t j y|td YW|r|j ddd|d d WdWdd St j yd}w|r|td | tds|n |j ddd|dd}n|tdW|r|j ddd|d d WdWddS|r |j ddd|d d ww1swYWddS1s!wYdS)NT)rurvrarsstarting in-memory rebase s8starting dry-run rebase; repository will not be changed rr8Fr)rrrrvshit 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)rWr1rrrrr _origrebaser-rrr0r promptchoicer[) rTr>r9rarr needsabortrresr+r+r,rss  (   ,8rcCs t||||d}t|||||S)N)ra)rWr)rTr>r9rarurr+r+r,rsrc Cs|dksJ|<||dr;z tdrd}Wn ty+d}Ynwd|}td|}t||j rH|j sHttd|r|j rTttd |d kre|d d re| td |dkrtt j |}t||j|d kd} | dur| WdWdSnA|d} t|||j|dd|dg|dg|dg| d} || } | dur| WdWdSt||j d} |dd} | r|d} t| 8d}| r|jst|d}t||| |js|Wdn 1swYWdn 1s"wYWdn1s2wYWddSWddS1sKwYdS)Nr interactiveshisteditrs --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 abortrr(Fstool option will be ignored rr _destspacerrr<rr<r8r)rrr1rfindKeyErrorrrrrkrhr mergestatemodrrrcheckunresolvedr_definedestmaprurstorecollapsemsgrm transactionr!acceptinterventionr rrvr[)rTr>r9rarenablehistedithelprmsretcoder<rersingletrdsguardr+r+r,rs        "       5       Trc s|durg}t|st|ddr%|s%tjtdtddd}|r;t|} | s:| tddSn|rVt|} | sN| tddS d | | } nt|p]d g} | sj| td dS|rst |}n t | |d }t |}g} i} | D]} d ||}| |g|g| |<qd| vr| t| D]\}}| t d||7} q d| } | s*t| |gkr|r| td|dS| tddS d| |s|r| tddfdd| D|fdS| td|dS| tddfdd| D|fdSt| vr6ttdd | v}|jdd||d|rW|rWtt|sgt | |d }t |}td| }d|i}|durz tj ||d }WnPtjyi}| D]@}td!||d"<j|gd#|d$}t|}|d%kr|||<q|d&kr|td'|qttd(|Ynw|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)rGs5empty "base" revision set - can't compute rebase set rsancestor(%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 +c3rar@rbrr_r+r,r]rdz!_definedestmap..sVnothing to rebase - working directory parent is already an ancestor of destination %s s nothing to rebase from %s to %s c3rar@rbrr_r+r,rkrdscannot rebase the working copyr8s!rebasing working copy parent: %r )rebase_rebasing_wcps%ldsALLSRC) localaliasrsSRCT)rrr*rs skipping %s - empty destination s'rebase destination for %s is not uniquecsi|]}|qSr+r+r)rr+r,rsz"_definedestmap..s&nothing to rebase - empty destination )r checkunfinishedr1rmrrrrrevrangerrH revsingler?rcrrIr1clearrrrrrrrrrranyrevsrKr)rTr>rudestfsrcfbasefrevfr<rrrOr<rootsbpbasebbpbs rebasingwcpallsrcaliasrerdestsetsizer+)rr>r,rs     &          rc Cst}t|}|D]#}||krq ||D]}||vr+||vr+||qq |s1tSt|dkr;|St t dt |d ddt |Df)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`csrrr+rrr+r+r,rrz!externalparent..)rfrJrMrrrrKrrrLrrrr)r>r rrMrrrr+r+r,rs* rc Csbd}d|vr |d}||j||||||d}|r&|jdds&dS||} || S)zXCommit the memory changes with parents p1 and p2. Return node of committed revision.Nr5)rYr0rr6rrr)_compacttomemctxr6rTrm commitctxclean) r>rrr0rrYrr6memctx commitresr+r+r,r"s" r"cCsvt}|jddst|d}||j|||||d}|j|||WdS1s4wYdS)zTCommit the wd changes with parents p1 and p2. Return node of committed revision.r8r)textrrYr0rN) r!nullcontextmanagerrTrmr commitdirstate setbranchr6)r>rr0rrYrrr&r+r+r,r#s  $r#c CsF||}|r||n*|d|kr&|jd||ft|n|jd|d}|j| ||}|jd||f|durV|jd|||f|j | | } tj ||dd|| gd|d } || || |rt|||n t|||| jd kr|rttd dS) zFRebase a single revision rev on top of p1 using base as merge ancestorrGs update to %d:%s s already in destination Ns merge against %d:%s s detach base %d:%s T)rxr/sparent of source) branchmergeforceancestor mergeancestorlabelsr)rr8) isinmemorysetbaserrTrr2rhrrrr isancestorr_updater5r graftcopiesr-unresolvedcountrr/r0) r>rr-r;r<rXrp1ctxr2rstatsr+r+r,r.sB      r.c s|fdd|D}g}|j|D]5}}|tkr2|d||} | dur2|| }|krI|vrI|}|tkrItd| |q|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|qSr\r+)rr3rrrergr+r,rTs zadjustdest..smax(%ld and (::%d))Ns-rev %d should be rebased already at this time) rr parentrevsrrHrIrrProgrammingErrorappend) r>rrer rgrrprevadjusted candidater+rr,r+s&5 r+c sbttj}||}|r-|s/fdd|D}td}td}tj|d|f|ddSdS)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. c3rar@rbrr_r+r,ryrdz"_checkobsrebase..s+this rebase will cause divergences from: %ssJto force the rebase please set experimental.evolution.allowdivergence=True,rN)rrrrrrLr) r>rT rebaseobsrevsrebaseobsskipped divergenceokdivergencebasecandidates divhashesrhr+r_r,rls rccsR|jdusJ|jjj}t|j||gD] }||}|dur&|VqdS)z,yield revision numbers for successors of revN)rrindexget_revr allsuccessorsobsstorer)rMrrr3rr+r+r, successorrevss rcsjdusJjj|}j}ttgt|||t|}tdd|ddDr;dd<nt|D]_\} | } t fddt | DrZ} n| |vrh|| dkrh|| } tdD])\} } | tkryqp| | rt} qp| | r| | <t} ||| || <|<qp| <q?dtkr|ddkrt dkrt |dksJ | t t |kr|vrttdft fd dDrttd tfd dt |Ddkrddg} t|D]E\}|tks|vrqt ||h}td |||}|rKfd d|D}fdd|D}td|||| <qt dd| Drtddt| D\}|dkrtdfdd| D}ttd|fdkrtkrdd<<||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. Ncss|]}|tkVqdSr@rrr+r+r,rrz defineparents..r*rc3s|] }|VqdSr@r+)rrE)rPrrr+r,rrs>cannot rebase %d:%s without moving at least one of its parentsc3s"|] }|tko |VqdSr@rr)rrr+r,rs !source is ancestor of destinationc3s$|] }|tkr|vrdVqdS)r*Nr)rr)newpsr+r,rs"s(%ld %% (%d+%d))cs$g|]\}}|dkr|vr|qSr\r+)rrr) obsskippedr+r,rsz!defineparents..cs"g|] }|dtkr|qS)r*)rrrrr+r,rss%ld - (::%ld) - %ldcss|]}|duVqdSr@r+rrHr+r+r,rrcss(|]\}}|durt||fVqdSr@)rK)rrrHr+r+r,r s s or c3s0|]}|durdfdd|DVqdS)Nr`c3s |] }d||fVqdS)rNr+rr_r+r,r+sz*defineparents...)rrr_r+r,r*ss4rebasing %d:%s will include unwanted changes from %ss future parents are %d and %d )rr isancestorrevrrr+rallranyrrKreverserfrrrsumrHrrJrrTrtuple)r>rrer rgrroldpsbasesrnpjrEunwantedr< other_basessiderevsrmergesr unwanteddescr+)rrPrrrrr>rr,r,s               r,cCs<tj|jj|}tt|dD] }|drdSqdS)z/Return true if the given patch is in git formatsrbs diff --gitTF)ospathrmqr linereaderr startswith)r> patchnamemqpatchliner+r+r, isagitpatchFs  rc sDi}|jjdd}tjD]*}||j}||vr6|jd||jf|jt ||jf||<q |jq|r || t |ddD]8}||vr|||\}} |jtd||||||fj|d|| d||gdqM ||d qMfd d |D} | jdd<d_dSdS) 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+r)rgitrrcs&g|]}j|ddvr|qS)r*r)guard_rerrr3r skippedpatchesr+r,r{s zupdatemq..)r  fullseriesrfappliedrrrTrnamerrfinishrrrrqimport seriesdirty savedirty) r>r rgramqrebaseoriginal_seriesrrrisgit newseriesr+rr,rLOsN     rLcCs.|pd}|dd}|d||dS)z,Store the collapse message to allow recoveryrlast-message.txtrrN)rrclose)r>rkrr+r+r,rs  rcCs|jjddddS)zRemove collapse message filer#TrEN)rrOr_r+r+r,rsrc Csrz|d}|}|W|Sty8}z|jtjkr!|r&d}ntt dWYd}~|Sd}~ww)z*Restore previously stored collapse messager#rs'missing .hg/last-message.txt for rebaseN) rreadlinerir$IOErrorerrnoENOENTrrr)r>rrrkerrr+r+r,rs      rcCs*|}|r |d|jjddddS)zRemove the status filesr]TrEN)rremovefilegeneratorrrO)r>rr+r+r,rs rccsjt|}|r3t|}g}|D] }|||vr||q|s&ttd|t|8}|V|sdSdS)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)rfrrrrr)resrcsetsrclistrrr+r+r,r s     r cs|}d}dvr*fddjjD}t||@r*tt dt t |}|s9t t dt d|d}|sLt t dd d }t ||d }t|tt|d k} |D]^} || } | | } | | kr~t t d | | krd} | | kr| | k}n| | k}|s|r| | vr| | <jdqdd} jd| | fqd| rdSt D]}ddj|D}|rtfdd|Dr||<q||fS)zlDefine which revisions are going to be rebased and where repo: repo destmap: {srcrev: destrev} rGr?csh|] }|jqSr+)rrrr_r+r,rszbuildstate..s&cannot rebase onto an applied mq patchsno matching revisionsrercSs|Sr@rA)rr+r+r,revofszbuildstate..revof)keyr*rNs!source is a child of destination Fs rebase onto %s starting from %s cSsg|]}|tkr|qSr+rrr+r+r,rzbuildstate..c3s|] }||kVqdSr@)r1r)r r+r,rrzbuildstate..)rrrKr rrfrrrLrrr rrdictfromkeysrrKrr-r6rMrTrrrr)r>rerXrrb mqapplied sortedsrcrr- emptyrebaserootr commonbaser samebranchrrMr+)r>r r,rsP           rTc sV|jj} i} i} t|tj } g} t|D]?\}}|dkrW||krW| |}|p-| |}|| |<d}||vrC| s@||sBd}n |rK| |n|f}|durW|| |f<q| ra|f| t| <|r|j |j }|j }i}t | D]\}}|D]}|fdd|Ddd||<qyqs||dd d }|j|d |ri} 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+)rnhfr+r,r=rCz clearrebased..snode)rsoldnodesnewnodes)r.value) nodechangesr8rf)rrrrrrrrrhexfunc formatlist formatdictrrrr cleanupnodes)rTr>rer rgrYrorDrtonode replacementsmoves stripcleanupcollapsednodesrroldnoder&succsflfdchangesoldnsnewnoldnr<r+r9r,rN sJ   $ rNc Os |dr|ddrtd}td}tj||d|||dr1|d=|dtj |d d tj |td dt |}t j }d d } | t _ z|||g|Ri|} W|t _ n|t _ wt |} | |krd|vrt|d=d|vr{|d=t|jj|d} | |d<z t||fi|Wn/tjyt|\} }}| |dkr|tdn |tdt ||YnwWdn1swYWd| SWd| S1swY| S|drttd|||g|Ri|} | S)zCCall rebase after pull if the latter has been invoked with --rebaserrrs,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) skipmergesCcannot pull with rebase: please commit or shelve your changes firstc_sdSr@r+)rkwargsr+r+r,_dummyar.zpullrebase.._dummyrr)startrrGrs%nothing to rebase - updating instead Nr(s%--tool can only be used with --rebase)r1rmrrrrrrr rr1rKr postincomingrrrHrNoMergeDestAbortr destupdaterrr)origrTr>rrarr revsprepullorigpostincomingrPret revspostpullr<r_a_br+r+r, pullrebaseEsl    (: :: r\c si}t}|j}|jjt|d}|D]Y}||}tt|j|g} | |fdd| D} | d| r@| |rEd||<q|} | D]} | | | rY| ||<nqK||vsit fdd| Drn||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)rr+r,rrCz)_compute_obsolete_sets..Nc3s|]}|vVqdSr@r+rr]r+r,rrz)_compute_obsolete_sets..)rfrrrrHrrrrremovediscardissubsetrrr) r>rrersrtr extinctrevssrcrevsrcnode successorssuccrevsdstrevsuccrevr+)rerr,rs2       rc Cs||0|t||}|jddWdn1swYWddSWddS1s7wYdS)NTr)rrrWr)rTr>rr+r+r, abortrebases Prgc Cs|X|;t||}tj|}t||jdd}|dur4|WdWdS| d| Wdn1sGwYWddSWddS1s_wYdS)NFr) rrrWrrrrrrrr[)rTr>rrrr+r+r,continuerebases      PrhcCs|jdsdSzt||i}||j}Wntjy+td}||YdSwt ddt |D}|td| tdd|| tdd t ||fdS) Nr]s8rebase: (use "hg rebase --abort" to clear broken state) cSsg|]}|dkr|qSr\r+)rrr+r+r,rr/zsummaryhook..s#rebase: %s, %s (rebase --continue) s %d rebasedsrebase.rebaseds %d remainingsrebase.remaining) rrrWrr rrrrrKr itervalueslabel)rTr>rr r numrebasedr+r+r, summaryhooks*     rlcCslttjdt}|ddddtdf|ddddtdftj dt t j dd d d t td dS) Nspullr*rr8s'rebase working directory to branch headrrsspecify merge tool for rebaser]T)fnamestopflag continueflag abortfunc continuefunc)r wrapcommandr tabler\rrr summaryhooksrrlrw addunfinishedrgrh)rTentryr+r+r,uisetups rwr@)F)NFNT)]rr __future__rr'r mercurial.i18nrmercurial.noderrrmercurial.pycompatr mercurialrr r r r r rrrrr2rrrrrrrrrrrrrrrr rwr!rrrcmdtablerR configtable configitem testedwithr-r4r7r?revsetpredicaterFrQrVobjectrW dryrunopts formatteropts confirmoptsCATEGORY_CHANGE_MANAGEMENTrrrrrrr"r#r.r+rrr,rrLrrrrr rrNr\rrgrhrlrwr+r+r+r,s   p!       L9:;< AI ?N"2N ; 6 I <E-