
    	^c%H                    L   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z&m'Z' dZ(dZ)h d	Z*i Z+ ej,        e+          Z,i Z- ej.        e-          Z. e.d
dd           dZ/d Z0d Z1d Z2dldZ3 ej4                    Z4 e4d          d             Z5 e4d          d             Z6d Z7 G d d          Z8 e,dddg  ed           ed          fdd g  ed!           ed          fd"d#g  ed$           ed          fd%d&d' ed(           ed          fd'd)d ed*          fd+d,d' ed-           ed.          fd/d0d ed1          fd2d3d' ed4           ed5          fd6d7d ed8          fd'd9d ed:          fd;d<d ed=          fd>d?d ed=          fd@dAd' edB          fd'dCd edD          fdEdFd edG          fdHdId edJ          fd'dKd' edL          fgej9        z   ej:        z   ej;        z    edM          e,j<        N          dO             Z=dP Z>dmdQZ?dR Z@dS ZAdT ZBdU ZCdV ZDdW ZEdX ZFdY ZGdZ ZHd[ ZId\ ZJd] ZKd^ ZLd_ ZMd` ZNda ZOdb ZPdc ZQ	 	 	 	 dndeZRdf ZSdg ZTdh ZUdi ZVdj ZWdk ZXdS )ozcommand 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
    N)_)nullrevshortwdirrev)open)	bookmarkscmdutilcommandscopiesdestutildirstateguarderror
extensions
logcmdutilmerge
mergestate	mergeutilobsoleteobsutilpatchphasespycompat	registrarrepairrevset
revsetlangrewriteutilscmutilsmartsetstateutils   -1>      -2   -3   -4   -5   devel   rebase.force-in-memory-mergeF)defaults   ships-with-hg-corec                      dS )N    r,       ./usr/lib/python3/dist-packages/hgext/rebase.py_nothingtorebaser/   T   s    1r-   c                     |                                                      dd           }|||d<   |                                                      dd           }|||d<   d S d S )N   sources   intermediate-source)extraget)ctxr2   ss      r.   
_savegraftr6   X   se    			4((A}i		.55A}()$%%% }r-   c                 4    |                                  |d<   d S )N   branch)branch)r4   r2   s     r.   _savebranchr:   a   s    zz||E)r-   c                 4    t          j        | d|d|          S )zhsmall wrapper around destmerge to pass the right extra args

    Please wrap destutil.destmerge instead.   rebaseF)action	sourcesetonheadcheck	destspace)r   	destmerge)repor>   r@   s      r.   _destrebaserC   e   s-        r-   s   _destrebasec                     d }|(t          j        | t          j        |           |          }|t          j        t          | |          g          z  S N)r   getsetr   fullreposetbasesetrC   )rB   subsetxr>   s       r.   _revsetdestrebaserK   u   sO     I}M$(<T(B(BAFF	H$k$	&B&B%CDDDDr-   s   _destautoorphanrebasec                    |                                  }|                    d          }t          j        | ||                                          }|r||v rt          j                    S t          j        | |          }t          |          dk    r&t          j        t          d          ||fz            t          j        |          S )Ns
   obsolete()r+   s8   ambiguous automatic rebase: %r could end up on any of %r)
unfilteredrevsr   rF   firstr   rH   r   orphanpossibledestinationlenr   
StateErrorr   )rB   rI   rJ   unfi	obsoletedsrcdestss          r.   _revsetdestautoorphanrebaserW      s    
 ??D		-((I
-fa
(
(
.
.
0
0C  "#""!!!.tS99E
5zzA~~IJJEl
 
 	

 E"""r-   c                 ^    t          j        |                                 j        | d          S )zshort description for a contextr<   )command)r	   format_changeset_summaryrB   ui)r4   s    r.   _ctxdescr\      s-    +

sI   r-   c                       e Zd ZdZddZed             ZddZd Zd Z	d	 Z
d
 Z	 ddZd Zd Zd ZddZd Zd ZddZdS )rebaseruntimez2This class is a container for rebase runtime stateFNc                 J   |i }d| _         d| _        || _        || _        || _        d | _        t          | _        i | _        d | _	        i | _
        t                      | _        |                    dd          | _        t          j        |t#          j        |                    | _        |                    dd           | _        |                    d          }t*          g| _        |r|g| _        |                    dd          | _        |                    dd          | _        |                    dd          | _        t7          j        |j        d	          | _        i | _        t                      | _        || _         || _!        tE          j#        |d
          | _$        d S )NFcollapsedateextrafns   rewrites   backup-bundlekeepkeepbranchesr<      rebasestate)%preparedresume_repor[   opts
originalwdr   externalr    activebookmarkdestmapsetskippedr3   	collapsefr	   
logmessager   byteskwargscollapsemsgra   r6   extrafns
configboolbackupfkeepfkeepbranchesfr   skip_empty_successorskipemptysuccessorf&obsolete_with_successor_in_destination%obsolete_with_successor_in_rebase_setinmemorydryrunstatemodcmdstatestateobj)selfrB   r[   r}   r~   ri   es          r.   __init__zrebaseruntime.__init__   sp   <D 
	 
"uu*e44"-b(2Ft2L2LMMHHVT**	HHY# 	 CDM}}Z1ABBXXfe,,
!XXne<<#.#CGY$
 $
  79358UU2  )$??r-   c                 P    | j         r| j                                        S | j        S rE   )rf   rh   rM   )r   s    r.   rB   zrebaseruntime.repo   s(    = 	:((***:r-   c                     |r |                     dd| j        d           dS | j                            dd          5 }|                     |           ddd           dS # 1 swxY w Y   dS )z*Store the current status to allow recoveryre   )re   s   plain)location   wN)addfilegenerator_writestatusrB   vfs)r   trfs      r.   storestatuszrebaseruntime.storestatus   s     		%!!!	        ~t44 %!!!$$$% % % % % % % % % % % % % % % % % %s   A!!A%(A%c                    | j         }|j        J |                    || j                                                 dz              |                    d           |                    || j                                                 dz              |                    dt          | j                  z             |                    dt          | j                  z             |                    dt          | j	                  z             |                    d| j
        pdz             | j        }| j                                        D ]\  }}||                                         }|dk    r||                                         }nd|z  }|||                                                  }|                    d|||fz             |j                            d           d S )	N   
s   %d
   %s
r-   r      %ds	   %s:%s:%s
s   rebase status stored
)rB   
filternamewriterj   hexrk   intrp   rw   rx   rl   rm   r    itemsr[   debug)	r   r   rB   rm   dvoldrevnewrevdestnodes	            r.   r   zrebaseruntime._writestatus   s   y&&&	T_%))++e3444		T]#''))E1222	#dn---...	#dj//)***	#d0111222	4.5#6777,J$$&& 	@ 	@DAq!W[[]]FAvvaGAJ'++--HGGMVVX$>>????/00000r-   c                    | j                                         s't          j        | j        t          d                     |                                 }| j        j                            d           |d         | _	        |d         | _
        |d         | _        |d         | _        |d         | _        |d         | _        |d	         | _        |d
         | _        |d         | _        dS )z"Restore a previously stored statusr<   s   rebase status resumed

   originalwd   destmap   state   skipped   collapse   keep   keepbranches   external   activebookmarkN)r   existsr	   wrongtooltocontinuerB   r   _readr[   r   rj   rm   r    ro   rp   rw   rx   rk   rl   )r   datas     r.   restorestatuszrebaseruntime.restorestatus   s    }##%% 	A'	1Y<<@@@zz||	5666}-J'(^
J'k*']
!/2[)"#45r-   c           	         d| _         | j        }|j        J d d d t          d d d}d }i }i }	 |                    d          }t          |                                                                          D ]\  }}|dk    r||                                         |d<   *|dk    r|r||                                         }M|dk    r||                                         |d<   q|d	k    r t          t          |                    |d
<   |dk    r t          t          |                    |d<   |dk    r t          t          |                    |d<   |dk    rt          |          dk    rd|v s||d<   |                    d          }	||	d                                                  }
|	d         }|t          v rOt          |	          dk    r!||	d                                                  }n|}|||
<   |t          k    rt          ||
<   ||                                         ||
<   |d         !t!          j        t%          d                    ||d<   ||d<   t'                      }|d
         st'          |                                          }t+          |                                          D ]>\  }}|t          k    r||v r|                    |           |                    |           ?||d<   |j                            dd                    d t+          |          D                       pdz             |S )NT)r   r   r   r   r   r   re   r   r   r+      r      r      r      r      Q      :r   s   .hg/rebasestate is incompleter   r   r   s   computed skipped revs: %s
    c              3       K   | ]	}d |z  V  
dS r   Nr,   .0rs     r.   	<genexpr>z&rebaseruntime._read.<locals>.<genexpr>Y  s&      <<q<<<<<<r-   r-   )rf   rB   r   r   r   	enumerateread
splitlinesrevboolr   rQ   splitlegacystates
revtodostrrevtodor   Abortr   rn   valuessortedr   addr[   r   join)r   rB   r   
legacydestr    rm   r   ilargsr   r   destrevro   seenoldnews                    r.   r   zrebaseruntime._read  sN   y&&&!# 
 
 
&	;((A!!&&(("5"5"7"788 $; $;166*.q'++--D''!VV  3%)!W[[]]
!VV(,QD%%!VV(,SVVD%%!VV$(QLLDMM!VV,0QLLD))!VVSVVr\\daii /0D*++774==D!$q']..00F!!WF-- 4yy1}}"&tAw-"3"3"5"5",&-GFO++(/f )-V(8(8(:(:f (+a @AABBB"ZX%%K  	w~~''((D"5;;==11  S'>>cTkkKK$$$"Z*yy<<F7OO<<<<<CE	
 	
 	

 r-   c                      j         rdS  j                            dd          sdS  fd j        D             }t	           j        | j                  \   _         _        t           j                  }|
                     j                   t           j         j        ||           t          j         j        t          j                  rt                       _        dS  j                            d j         j                  D ]8} j                            |d            j                            |d           9dS )z<Compute structures necessary for skipping obsolete revisionsN   experimentals   rebaseskipobsoletec                 R    h | ]#}j         |                                         !|$S r,   )rB   r   )r   r   r   s     r.   	<setcomp>z8rebaseruntime._handleskippingobsolete.<locals>.<setcomp>d  s0    HHHQ	!0E0E0G0GHqHHHr-   s   descendants(%ld) and not %ld)rw   r[   ru   r    _compute_obsolete_setsrB   rm   r{   r|   rn   update_checkobsrebaser   	isenabledallowdivergenceoptrN   pop)r   obsoleteset
skippedsetr   s   `   r.   _handleskippingobsoletez%rebaseruntime._handleskippingobsolete^  sI   : 	Fw!!/3HII 	FHHHH$*HHH #49k4<HH	
76DEE
$DEEE	47KDDDdi)DEE 		,9<D666y~~/::  , ,
 
sD)))  d++++, ,r-   Tc                 $   d| _         	 |                                  |                                  t          | j        |          | _        n# t          j        $ r |rWt          | j                   t          | j                   | j        j
                            t          d                     Y dS t          d          }t          d          }t          j        ||          w xY w|r"|o| j        }|                     ||||          S d S )NTsF   rebase aborted (no revision is removed, only broken state is cleared)
r   s#   cannot continue inconsistent rebases-   use "hg rebase --abort" to clear broken statehint)backup	suppwarnsr~   confirm)rg   r   r   restorecollapsemsgrB   rs   r   RepoLookupErrorclearstatusclearcollapsemsgr[   warnr   r   rv   _abort)r   isabortr   r   r~   r   msgr   s           r.   _prepareabortorcontinuez%rebaseruntime._prepareabortorcontinuew  s@    	2   ((***1$)WEED$ 	2 	2 	2 2DI&&& +++	!!<    qq>??IJJk#D1111	2   	,F;;#	    	 	s   AA A%C)45C)c                    |st                      S t          | j        || j                  }|s5| j                            t          d                     t                      S |\  | _        | _        | _	        | j        rt          | j                                                  }t          |          dk    r!t          j        t          d                    t          t!          |                    }| j        j                            |gd          }t'          | j        | j	        |          | _        t+          t          |                                                    D ]T}| j        |         }|                                r1| j        s*| j                            t          d          |z             U|                                  | j        st          |                                          }|t          | j                  z  }|| j        z  }i }t;          j        | j        t:          j                  rddi}	 | j                             |          5  tC          j"        | j        |d	
           d d d            n# 1 swxY w Y   n4# t          j#        $ r"}	|	j$        t          d          |	_$        |	d }	~	ww xY wd| _%        d S )N   nothing to rebase
r+   s3   --collapse does not work with multiple destinationsT)	inclusives    reopening closed branch head %s
)r   s   evolution.allowdivergences   truer<   )r=   s&   use --keep to keep original changesets)&r/   
buildstaterB   rp   r[   statusr   rj   rm   r    rn   r   rQ   r   
InputErrornextiter	changelog	ancestorsexternalparentrk   r   closesbranchrx   r   rw   keysr{   r|   r   r   createmarkersoptconfigoverrider   precheckr   r   rf   )
r   rm   resultrV   r   destancestorsdest	rebaseset	overridesr   s
             r.   _preparenewrebasezrebaseruntime._preparenewrebase  s    	&#%%%DIw?? 	&GNN1344555#%%%6<3$,
> 
	Q++--..E5zzQ&LMM   4;;''G I/99	T :  M +49dj-PPDMc'.."2"23344 	O 	OG9W%D  "" O4+= Oq!EFFMNNN 	$$&&&z 	GLLNN++ITHIIIICCII!$)X-FGG CW	W++I66 Q Q(IiPPPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q;   6>HIIAF
 s<   J J9J J		J J	J K J==Kc                 F   | j         r;ddlm}  || j                  | _        | j        j                            d           n1| j        d          | _        | j        j                            d           | j        j                            dd| j         | j                    d S )Nr   )overlayworkingctxs   rebasing in memory
s   rebasing on disk
r<   s   using in-memory rebase: %r
)rebase_imm_used)r}   mercurial.contextr  rB   wctxr[   r   log)r   r  s     r.   _assignworkingcopyz rebaseruntime._assignworkingcopy  s    = 	6;;;;;;))$)44DIIL67777	$DIIL4555	+M M	 	 	
 	
 	
 	
 	
r-   c                 ,  
 |                                   | j        | j        }}| j        r| j                            dt                     | j        ryt                      }| j	        D ]c}|
                    ||                                                    t          |          dk    r!t          j        t          d                    d| j        p|j        | _        | j        rt%          j        |           |                                  |r|                     |           d | j	                                        D             }|j                            t          d          t          d          t          |                    

fd}t/          | j                  D ]9}| j                            d	|          }	|	D ]}|                     |||           :
                                 |                    t          d
                     d S )Nr   r+   s'   cannot collapse multiple named branchesc                 .    g | ]\  }}|t           k    |S r,   )r   )r   kr   s      r.   
<listcomp>z0rebaseruntime._performrebase.<locals>.<listcomp>  s!    BBBtq!Q'\\\\\r-   s   rebasings
   changesets)unittotalc                 b                         d|                                 | fz             d S )N   %d:%s)item)	incrementr   )r4   ps    r.   progressz.rebaseruntime._performrebase.<locals>.progress   s/    KKh#''))S)99K;;;;;r-   s   sort(%ld, -topo)s   rebase merging completed
)r
  rB   r[   rx   rt   insertr:   rp   rn   r    r   r9   rQ   r   r   r   rl   _activebookmarkr   
deactivater   r   makeprogress
sortsourcerm   rN   _rebasenodecompletenote)r   r   rB   r[   branchesr   candsr  rI   
sortedrevsr  s             @r.   _performrebasezrebaseruntime._performrebase  s&   !!!9dgb 	 M  K000~ 55:  CLLc!1!1!3!34448}}q((#.HII   ) #1IT5I 	' &&& 	 	! R   BBtz//11BBBG  kNN=!1!1U ! 
 
	< 	< 	< 	< 	< !.. 	4 	4F(;VDDJ! 4 4  S(33334	


/0011111r-   c           
      <   | j         }||         }||                                }| j        s@|j        t	          j        ||fd| j                                        D                       }| j        }||                                }i }|j	        
                    dd          rd|                                i}| j        D ]} |||           t          |                                t          j                  }	|	| j         d}
|j	                            |
d          5  | j        r.t)          || j        ||||                                |          }n't/          |||||                                |          }|cddd           S # 1 swxY w Y   dS )	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.Nc                     i | ]:\  }}|t           k                        |                              |          g;S r,   )r   node)r   r   r   cls      r.   
<dictcomp>z/rebaseruntime._concludenode.<locals>.<dictcomp>  sK       &(( GGFOObggfoo%6(((r-   r<   s   store-sources   rebase_source))s   phasess
   new-commit)   ui   allowemptycommit)r  r2   	commitmsgeditoruserra   )r2   r*  r+  r,  ra   )rB   descriptionrp   r   r   update_hash_refsr    r   ra   r[   ru   r   rt   maxphaser   draftrz   r   r}   commitmemorynoder  r,  
commitnode)r   r   r+  r*  rB   r4   ra   r2   c	destphaser  newnoder&  s               @r.   _concludenodezrebaseruntime._concludenode
  s   
 y3i))I ~ 
	B#4   *.**:*:*<*<   I y<88::D7i99 	2%swwyy1E 	 	AAc5MMMM		V\22	(1.2.F*F
 
	 W##Iy99 	 	} *'!   %'!   +	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   &AFFFc                    | j         | j        | j        }}}||         }t          |          }| j        |         |k    r'|                    t          d          |z             n|| j        v rHt          d          |z  }	|j                            |	           | j        	                    |           n|| j
        v r| j
        |         }
|
t          d          |z  }	n)t          ||
                   }t          d          ||fz  }	|j                            |	           | j        	                    |           t          t          ||| j        | j        | j                            }|| j        |<   n| j        |         t          k    r|                    t          d          |z              ||           t          ||| j        | j        | j        | j
                  \  }}}| j        rR| j                                                                        |k    r#|j                            d           d| _        nfd|                    d	d
          i}|                    |d          5  	 t/          |||||| j        | j                   n# t2          j        $ r | j        rt3          j        d          | j        r |                    t          d                     	 t;          j        |           n2# t2          j        $ r  tA          |           tC          |            w xY wd| _"        | #                                 tI          j%        ||         | j                   t/          |||||| j        | j                   Y nw xY wd d d            n# 1 swxY w Y   | j        s|tL          k    }t;          j'        |d          }t;          j(        dd|i|}| j        )                    ||         *                                ||         *                                           | +                    ||          }nd }|||                                         | j        |<   |                    dtY          |          z             ||         -                                r%|.                    t          d          |z             n| j        s?|.                    t          d          |z             | j        	                    |           || j        |<   |                    d|z             n8|                    t          d          ||| j        |                  fz             |s| /                                 d S d S )Ns   already rebased %s
sI   note: not rebasing %s and its descendants as this would cause divergence
s+   note: not rebasing %s, it has no successor
s4   note: not rebasing %s, already in destination as %s
s   rebasing %s
s   resuming interrupted rebase
F)r(  s
   forcemergetoolr-   r<   )r  sD   hit merge conflicts; rebasing that commit again in the working copy
)wceditforms   rebased as %s
sR   note: created empty successor for %s, its destination already has all its changes
sC   note: not rebasing %s, its destination already has all its changes
s   next revision set to %d
s   already rebased %s as %s
r,   )0rB   r[   ri   r\   r    r   r   r|   ro   r   r{   r/  
adjustdestrm   r   defineparentsrg   r  p1r   r   r3   r   
rebasenoderp   r   InMemoryMergeConflictsErrorr~   ConflictResolutionRequiredr	   bailifchangedr   r   r   r}   r
  mergemodr   r   mergeeditformgetcommiteditor
setparentsr%  r7  r   isemptyr   r   )r   r   r   
progressfnrB   r[   ri   r4   descr   succsuccdescr   r>  p2baser  mergingr;  r+  r6  s                        r.   r  zrebaseruntime._rebasenodeF  s2   DGTY$b3i}}:c?c!!IIa/00478888D>>>5  	  GNN3LS!!!!D???>sCD|GHH4O#DJ//L 8$% GNN3LS!!! 4dlDJMM D #DJsOOZ_''IIa())D0111JsOOO(
; LBD { /ty||~~1133r99>???#3TXXfc5J5JK	&&y)<< * *)"   N!%     !<   ; N"'"B9"M"MM> " "		!F   "#1$7777${ " " "'---,T222!" ).//111 RTY????"   N!%     /* * * * * * * * * * * * * * *V > -"0)DD 0KK(KdKK 	$$T"X]]__d2hmmooFFF,,S&99 ""&w-"3"3"5"5
3+eGnn<====((** GGI  	   ~ *GG5  	   L$$S)))"$
35:;;;;II/00D$tz#:O3PP    	
 	 	sP   3N 5 JN AN+L ?N /L//ANN NN  N$'N$c                    | j         | j        | j        }}}|                    dt	          j        |                    }|                                 | j        rjt          |t          | j
                  | j        | j
        | j        | j                  \  }}}|                    d          }d}	| j        r| j        }
nDd}
t!          | j
                  D ]+}|| j        vr |
d||                                         z  z  }
,d}t%          j        ||	          }t)          | j
                  }| j                            ||                                         || j                                                            |                     |||
          }|.||                                         }| j
        D ]}|| j
        |<   d	|                                v rt9          || j
        | j        fi | | j
                            | j        | j                  }|d
k     r| j        }|d |d                                          D             vr<|                    tA          d                     tC          j"        ||                    d }| j        r	| j#        s|}tI          ||| j        | j
        | j        || j#        || j%        	  	         tM          |           tO          |           |                    tA          d                     tQ          j)        |*                    d          d           | j        r9tW          | j                  }|                    tA          d          |z             |,                                 | j-        rX| j-        |j.        v rL|d                                         |j.        | j-                 k    r t_          j0        || j-                   d S d S d S d S )Nr<   edits   rebase.collapses   Collapsed revisions   
* %sT)rP  r;  )r*     qtipr   c                 6    g | ]}|                                 S r,   r   r   r4  s     r.   r  z/rebaseruntime._finishrebase.<locals>.<listcomp>  s     ???Q???r-   s0   update back to initial working directory parent
)fmr   s   rebase completed
s   undoignoremissings   %d revisions have been skipped
   .)1rB   r[   ri   	formatterr   rr   	startitemrp   r=  minr    rm   ro   r{   r3   rs   r   r-  r	   rE  r/  r  rF  r%  rk   r7  r   tagsupdatemqrj   parentsr  r   rC  r   rw   clearrebasedrv   r   r   r!   
unlinkpathsjoinrQ   endrl   
_bookmarksr   activate)r   rB   r[   ri   rU  r>  rL  _baseeditoptr;  r*  rebasedr+  
revtoreuser6  r   r   newwdcollapsedas
skippedlens                       r.   _finishrebasezrebaseruntime._finishrebase  s   DGTY$b\\)X%9$%?%?@@
> 	0)DJ
; MBE hhv&&G)H  ,		1	%dj11 M MGdl22!Yg1J1J1L1L%LL	,'HMMMFTZJI  b$t}2E2J2J2L2LMMM((Fi )  G "g**,,"j 0 0F)/DJv&&diikk!!T4:t|<<t<<< 
t@@199OE??$t**<*<*>*>?????GGAJKKLLLODK(((> 	"$* 	"!KLJLJ<
	
 
	
 
	
 
	
 	D
'(()))

7++4@@@@< 	IT\**JGGA9::ZGHHH
 	:#t66T
!!T_T5H%IIItT%899999	: 	:66IIr-   c                 Z     j         	  fd j                                        D             }fd|D             }d}|rZj                            t          d          d                    fd|D                       z  t          d                     d	}t                      }|r't          j        	                    |                    }|t          |          z
  r)j                            t          d
                     d	}|r|r d                     d|          D             }	t          |          }
|

                     j                                                   |s|s|
                     j                   d                                         |
v }|rt!          j         j                            |rt%          j        j        |	|            j        r( j        j        v rt-          j         j                   t1                     t3                     |s'j                            t          d                     nM# t1                     t3                     |s(j                            t          d                     w w xY wdS )z-Restore the repository to its original state.c                 T    g | ]$\  }}|d k    ||k    |j         |         k    "|%S r   )rm   )r   r   r5   r   s      r.   r  z(rebaseruntime._abort.<locals>.<listcomp>.  sH       Aq66a1ffdl1o)=)= )=)=)=r-   c                 H    g | ]}|                                          |S r,   )mutable)r   r   rB   s     r.   r  z(rebaseruntime._abort.<locals>.<listcomp>3  s,    EEEq47??3D3DEEEEr-   Ts-   warning: can't clean up public changesets %s
   , c              3   B   K   | ]}t          |                   V  d S rE   bytesr   r   rB   s     r.   r   z'rebaseruntime._abort.<locals>.<genexpr>8  s-       C CAtAw C C C C C Cr-   s    see 'hg help phases' for detailsr   FsD   warning: new changesets detected on destination branch, can't strip
c                 6    g | ]}|                                 S r,   )r%  rT  s     r.   r  z(rebaseruntime._abort.<locals>.<listcomp>K  s-     # # #%&# # #r-   
   roots(%ld)rX  r   s   rebase aborted
r   )rB   r    r   r[   r   r   r   rn   r   descendantsr   rm   r   r   rj   r   rC  clean_updater   striprl   rc  r   rd  r   r   )r   r   r   r~   r   rg  	immutablecleanuprz  strippointsupdateifonnodesshouldupdaterB   s   `           @r.   r   zrebaseruntime._abort%  s    y=	5
    J,,..  G
 FEEEGEEEIG  GHHjj C C C C C C CCCD>??    
  %%K G!$."<"<W"E"EFFS\\)  =      L # #*.((='*J*J# # #K #&g,,&&t|':':'<'<=== 9g 9#''888#Dz~~//?B   A)$t*?@@@  LL$FKKKK" >t':do'M'M"4)<=== T""" 5Q233444 T""" 5Q23344445qs   HI A
J()FFNrE   )TFFF)__name__
__module____qualname____doc__r   propertyrB   r   r   r   r   r   r   r  r
  r"  r7  r  rl  r   r,   r-   r.   r^   r^      sB       <</@ /@ /@ /@b   X% % % %1 1 1,6 6 6$K K KZ, , ,4 LQ       D2 2 2h
 
 
 +2 +2 +2Z: : : :xL L L\O: O: O:bB B B B B Br-   r^   r<      sr1   s5   rebase the specified changesets and their descendantss   REV   bs   bases=   rebase everything from branching point of specified changeset   rs   revs   rebase these revisions   d   destr-   s#   rebase onto the specified changesetr   s   collapse the rebased changesets   ms   messages#   use text as collapse commit messages   TEXT   es   edits    invoke editor on commit messages   ls   logfiles&   read collapse commit message from files   FILE   kr   s   keep original changesetsr   s   keep original branch names   Ds   detachs   (DEPRECATED)   is   interactive   t   tools   specify merge tools   stops   stop interrupted rebase   cs   continues   continue an interrupted rebase   as   aborts   abort an interrupted rebases   auto-orphanssL   automatically rebase orphan revisions in the specified revset (EXPERIMENTAL)s>   [[-s REV]... | [-b REV]... | [-r REV]...] [-d REV] [OPTION]...)helpcategoryc                 *   |                      dd          }t          j        |ddd          }|r0t          j        ||ddg           t          j        ||g d           t          j        |dd           t          j        |d	d
d           |s|                                d}|                    d          r|t          |          dhz
  }t          j        |d|           t          |                    |                    d                              }t          j
        d|          g|d	<   d|d<   |                    d          s|                    d          rt          | |||          S |dk    r?t          ||           }|                                5  |                                5  |                                 |j        r!t#          j        t'          d                    t)          j        |t(          j                  }|j        s2|s0t#          j        t'          d          t'          d                    t1          j        ||j                            |                                 	 ddd           ddd           dS # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS |r	 ddi}	|                     |	d          5  t;          | ||||          cddd           S # 1 swxY w Y   dS # t"          j        $ rn |                      dd          r |                     t'          d                     tA          |           tC          |           t;          | |||d          cY S w xY wt;          | |||          S )au  move 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.

    r<   s   experimental.inmemoryabortstopcontinuer   dry_run)r   sourcerM  r   r   r  rM  NFauto_orphanss   %ld and orphan()s   _destautoorphanrebase(SRC)r   s!   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 changesetsr   r   r<      singletransactionT)r}   r'   r(   s?   hit merge conflicts; re-running rebase without in-memory merge
)"ru   r	   check_at_most_one_argcheck_incompatible_argumentscurrenttransactionr3   rn   listrN   r   
formatspec_dryrunrebaser^   wlocklockr   rp   r   rR   r   r   r   allowunstableoptrw   rC  r{  rj   rl  r   	_dorebaser@  r   r   r   )
r[   rB   ri   r}   r=   disallowed_optsuserrevsrbsrtallowunstabler  s
             r.   rebaser  j  s   x }}Y(@AAH*4&*MMF 
,&9i0	
 	
 	
 	,&;;;	
 	
 	
 !$	9===!$x@@@ ((**6 xx 5d))~&66,./	
 	
 	
 		$((>":":;;<<!,-@(KKLU4Vxx	 .1dhhy11 .1Rvt444	6		dB''ZZ\\ 	 	499;; 	 	!!! P&q)M'N'NOOO$.tX5NOOMK = &2  & 
 
 
 
 !$u'7"8999!!!+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	, 
 1	E ;DAI""9i88 L L T64(KKKL L L L L L L L L L L L L L L L L L0 	E 	E 	E}}X'FGG GG     T"""RvteDDDDDD	E T64000sn   J+2C	J;J+J	J+J	J++J/2J/;L K6)L 6K::L =K:>L A:N ?N c                 $   t          || dd|          }|                    d          }|r#|                     t          d                     n"|                     t          d                     |                                5  |                                5  d}	 ddi}|                     |d          5  t          | ||||          }|t                      k    rVd}|cd d d            |r,|	                    ddd|                    d	          
           cd d d            cd d d            S 	 d d d            n# 1 swxY w Y   |ru|                     t          d                     | 
                    t          d                    s|                                 n|	                    ddd|           d}n"|                     t          d                     	 |r,|	                    ddd|                    d	          
           d d d            d d d            dS # t          j        $ rj |                     t          d                     Y |r,|	                    ddd|                    d	          
           d d d            d d d            dS t          j        $ r d} w xY w# |r-|	                    ddd|                    d	          
           w w xY w# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NT)r}   r~   ri   r   s   starting in-memory rebase
s8   starting dry-run rebase; repository will not be changed
r  r<   Fr  )r   r   r   r~   s   rebase completed successfully
s!   apply changes (yn)?$$ &Yes $$ &No)r   r   r   r   sW   dry-run rebase completed successfully; run without -n/--dry-run to perform this rebase
r   s   hit a merge conflict
r+   )r^   r3   r   r   r  r  r   _origrebaser/   r   promptchoicerl  r   rA  r   )	r[   rB   r=   ri   r  r   
needsabortr  ress	            r.   r  r  s  s   $T$TJJJEhhy!!G 

		!2334444
		JKK	
 	
 	
 
 3 3tyy{{ 3 3
1	:DAI""9i88 
 
!  *,,,,!&J
 
 
 
 
 
 
P  --  "88I..	 .   ]3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -
 
 
 
 
 
 
 
 
 
 
 
 
 
 
$  		!>??@@@q)M'N'NOO 	''))))11 $$"& '	 2    #

		B     --  "88I..	 .   ]3 3 3 3 3 3 3 3 3 3 3 3 3 3 / 	 	 	IIa1223336  --  "88I..	 .   ]3 3 3 3 3 3 3 3 3 3 3 3 3 3$ { 	 	 	J	4  --  "88I..	 .    Y3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   LK-H,8)E!H,-.K-L5H,EH,E	H,BJ9&.K-L,1J6J9.K-L$J66J991K**K--K1	1L4K1	5LL	L	c                 N    t          || ||          }t          | ||||          S )N)ri   )r^   r  )r[   rB   r=   ri   r}   r  s         r.   r  r    s.    $H4888Er4u555r-   c                    |dk    sJ |                                 5  |                                5  |                    d          rU	 t          j        d          rd}n# t
          $ r d}Y nw xY wd|z  }t          d          |z  }t          j        |          |j	        r(|j
        s!t          j        t          d                    |r|j
        r!t          j        t          d	                    |d
k    r8|                    dd          r"|                     t          d                     |dk    r3t          j                            |          }t          j        |           |                    |d
k              }	|	|	cd d d            cd d d            S n|                    d          }
t%          | ||j        |                    dd           |                    dg           |                    dg           |                    dg           |
          }|                    |          }	|	|	cd d d            cd d d            S t+          ||j	                   d }|                     dd          }|r|                    d          }t1          j        |          5  d }|r|j        st5          j        |d          }t1          j        |          5  |                    |           |j        s|                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  interactives   histeditr-   s    --config extensions.histedit=s   hg%s help -e histeditsO   interactive 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  r9  Fs   tool option will be ignored
r  r   
_destspacer   r  rM  r   r@   r<   r  )r  r  r3   r   findKeyErrorr   r   r   rs   rp   r   mergestatemodr   r   r   checkunresolvedr   _definedestmapr}   r  storecollapsemsgru   transactionr!   acceptinterventionr   r"  r~   rl  )r[   rB   r=   ri   r  enablehistedithelpr   msretcoder@   rm   r   singletrdsguards                  r.   r  r    sg   V	 I* I*tyy{{ I* I*88M"" 	(C?;// )%(N C C C!BC+n<D9  	  "3''' 	U_ 	"@AA    	6 &CDD     TXXfe%<%< :;;<<<##"-22488)"---33Vw=N3PPG"GI* I* I* I* I* I* I* I* I* I* I* I* I* I* I*D #
 ..I$&&2&&$$###	 	 	G --g66G"iI* I* I* I* I* I* I* I* I* I* I* I* I* I* I*j T5#4555==,@AA 	-!!),,B
 $R(( 		* 		* G G G'5dIFF(11 * *$$R(((| *'')))* * * * * * * * * * * * * * *		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		*AI* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I* I*s   M&M	A M A/,M.A//DM
M&#BM=M&AM.5L7#1L 	L7 L$$L7'L$(L7+M7L;;M>L;?MM&M	M&M	M&&M*-M*c           	      v   |g }t          j                   |st          j                   |                     dd          r2|s0t	          j        t          d          t          d                    d}|r=t          j        |          }	|	s$| 	                    t          d                     dS n|rTt          j        |          }
|
s$| 	                    t          d                     dS 
                    d	|
|
          }	nt          j        |pd
g          }|s$| 	                    t          d                     dS |rt          j        |          }n't          ||                   }t          |          }g }i }|D ]Z}
                    d||                                                                          }|                    |g           |gz   ||<   [d|v r|                                 |                                D ],\  }}|t'          
                    d||                    z  }-
                    d|          }	|	sRt'          |          |                                gk    rL|r'| 	                    t          d          |z             n| 	                    t          d                     nމ
                    d||                                          so|rG| 	                    t          d          d                    fd|D                       |fz             nl| 	                    t          d          |z             nF| 	                    t          d          d                    fd|D                       |fz             dS t*          |	v r!t	          j        t          d                    d
                                         |	v }|                     dd||           |r*|r(t          j                   t          j                   |s't          |	|                   }t          |          }t/          j        d|	          }d|i}|	 t3          j        ||          }n# t          j        $ r i }|	D ]}t/          j        d |          |d!<                       |gd"|#          }t9          |          }|d$k    r|                                ||<   `|d%k    r,|                     t          d&          |         z             t	          j        t          d'          |         z            Y nw xY w|"|                                fd(|	D             }|s$| 	                    t          d)                     dS |S )*z:use revisions argument to define destmap {srcrev: destrev}N   commands   rebase.requiredests   you must specify a destinations   use: hg rebase -d REVr   s-   empty "rev" revision set - nothing to rebase
s0   empty "source" revision set - nothing to rebase
s   (%ld):: + (%ld)rX  s5   empty "base" revision set - can't compute rebase set
r  s   ancestor(%d, %d)s   children(%d) & ancestors(%ld)s   %ld::s6   nothing to rebase - %s is both "base" and destination
sA   nothing to rebase - working directory parent is also destination
s
   %ld - ::%dsG   nothing to rebase - "base" %s is already an ancestor of destination %s
   +c              3   B   K   | ]}t          |                   V  d S rE   rt  rv  s     r.   r   z!_definedestmap.<locals>.<genexpr>]  s-      $B$BU47^^$B$B$B$B$B$Br-   sV   nothing to rebase - working directory parent is already an ancestor of destination %s
s    nothing to rebase from %s to %s
c              3   B   K   | ]}t          |                   V  d S rE   rt  rv  s     r.   r   z!_definedestmap.<locals>.<genexpr>k  s-       > >AtAw > > > > > >r-   s   cannot rebase the working copyr<   s!   rebasing working copy parent: %r
)rebase_rebasing_wcps   %lds   ALLSRC)
localaliasr   s   SRCT)r,  r  r+   r   s    skipping %s - empty destination
s'   rebase destination for %s is not uniquec                     i | ]}|S r,   r,   )r   r   r   s     r.   r'  z"_definedestmap.<locals>.<dictcomp>  s    111!1g111r-   s&   nothing to rebase - empty destination
)r	   checkunfinishedrB  ru   r   r   r   r   revranger   rN   	revsinglerC   ru  r   rO   r3   clearr   r  r   r   r	  r   r  r   r   anyrevsrQ   r  )r[   rB   r}   destfsrcfbasefrevfr@   r   r  rU   rM  rootsbpbasebbpbsrebasingwcpallsrcaliasrm   r   destsetsizer   s    `                      @r.   r  r    s   |
 D!!! $d###	}}["788 
 
/00+,,
 
 
 	

 D T'd33	 	IIaIJJKKK4	 
 O!$-- 	IIaLMMNNN4II0#s;;		"44&99 	IIOPP   4 	 'e44DDD$)DDDED$KKE 	2 	2A.488::>>DDFFBB++qc1F2JJ6>> LLNNNllnn 	O 	OFBT$))$Db"MMNNNEEIIh..	 ,	 Dzzdhhjj\)) II2  	    II<     YY}dDHHJJ??  II$ 
  99$B$B$B$BT$B$B$BBBDIJ    II< 
     		:;;yy > > > > > > >>>EF   4)q!BCCDDDt*..""i/KFF-'	      $K $%%%d### Ki9EEEFd"6955FE|	$T5UCCCDD$ 	 	 	G   * 5eQ ? ?f ,,wTe,LL7||199!(GAJJQYYGGABCCd1gMNNNN*DEEQO   	$ ((**1111y111 
		!>??@@@tNs   R CU,+U,c           
      N   t                      }t          |          }|D ]y}||k    r	| |                                         D ]U}|                                |vr=|                                |vr'|                    |                                           Vz|st
          S t          |          dk    r|                                S t          j	        t          d          t          |          d                    d t          |          D                       fz            )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+   sK   unable to collapse on top of %d, there is more than one external parent: %srr  c              3       K   | ]	}d |z  V  
dS r   r,   r   r  s     r.   r   z!externalparent.<locals>.<genexpr>  s&      )M)M%!))M)M)M)M)M)Mr-   )rn   r[  r^  r   r   r   rQ   r   r   rR   r   r/  r   r   )rB   r    r   r^  r  r   r  s          r.   r   r     s%   
 eeGZZF % %&==c""$$ 	% 	%Auuwwe##}(D(DAEEGG$$$	%  
7||q{{}}

	,	
 	
 }uzz)M)MVG__)M)M)MMM
N		O  r-   c                 4   d}d|v r|d         }|                                  |                    ||||||          }|                                r| j                            dd          sdS |                     |          }	|                                 |	S )zXCommit the memory changes with parents p1 and p2.
    Return node of committed revision.Nr8   )ra   r2   r,  r9   r+  r(  r)  )_compacttomemctxrG  r[   ru   	commitctxclean)
rB   r  r+  r2   r,  ra   r*  r9   memctx	commitress
             r.   r2  r2    s    
 FEy!
 	MMOOO]]   F ~~  2 25:M N N tv&&IJJLLLr-   c                 \   t          j                    }| j                            dd          st	          j        | d          }|5  |                     |||||          }| j                            | |                                                    |cddd           S # 1 swxY w Y   dS )zTCommit the wd changes with parents p1 and p2.
    Return node of committed revision.r<   r  )textr,  ra   r2   r+  N)	r!   nullcontextmanagerr[   ru   r   commitdirstate	setbranchr9   )rB   r+  r2   r,  ra   r*  r  r6  s           r.   r3  r3    s     %''G7i)=>> ?-dI>>	  ++Df  
 
 	W 4 4 6 6777                 s   AB!!B%(B%c           
         | |         }|                                 r|                    |           n| d                                         |k    r4| j                            d||fz             t          j        |           n| j                            d           | d         }| j                            | 	                                           | |         }| j                            d||fz             |%| j                            d|| |         fz             | j
                            |                                |                                          }	t          j        | |dd||	g d|	          }
|                    |                                | |                                                    |rt          j        |||           n(t          j        |||                                           |
j        d
k    r;|                                 rt'          j                    t'          j        d          dS )zFRebase a single revision rev on top of p1 using base as merge ancestorrX  s    update to %d:%s
s    already in destination
Ns    merge against %d:%s
s      detach base %d:%s
T)r  r1   s   parent of source)branchmergeforceancestormergeancestorlabelsr:  r   r<   )
isinmemorysetbaser   r[   r   rC  r{  r  r   r  r   
isancestorr%  _updaterF  r   graftcopiesr>  unresolvedcountr   r@  rA  )rB   r   r>  rL  rM  r`   r  p1ctxr4   r  statss              r.   r?  r?    s     HE 7U:>>r!!GMM/2u+=>>>!%((((GMM6777 DzD3355666
s)CGMM+sCj8999/4d2DDEEE N--ejjllCHHJJGGM#888	 	 	E 	OOEJJLL$r(--//222 04e,,,,
 	4cffhh///q  ?? 	>355529===	 ! r-   c                   
 |         

fd|                                 D             }g }| j                            |          D ]}
}|t          k    r3|                     d||                                          }	|	||	         }|
k    r.
|v r*|
         }|t          k    rt          j        d
z            |	                    |           |S )a  adjust 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
    c                 F    g | ]\  }}|d k    |         k    |v|S ro  r,   )r   r5   r   r   rm   ro   s      r.   r  zadjustdest.<locals>.<listcomp>T  sH       Aqq55WQZ4''AW,<,< 	
,<,<,<r-   s   max(%ld and (::%d))Ns-   rev %d should be rebased already at this time)
r   r   
parentrevsr   rN   rO   r   r   ProgrammingErrorappend)rB   r   rm   r    ro   r  r   prevadjusted	candidater   s     ` `     @r.   r<  r<    s   j 3<D     KKMM  F F))#..    7??		"8&$GGMMOOI$ +tT{H7"",DtK   	hMr-   c                     t          j         t           j                  }||z
  }|r[|s[ fd|D             }t          d          }t          d          }t	          j        |d                    |          fz  |          dS dS )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.
    c              3   B   K   | ]}t          |                   V  d S rE   rt  rv  s     r.   r   z"_checkobsrebase.<locals>.<genexpr>y  s-      FFU47^^FFFFFFr-   s+   this rebase will cause divergences from: %ssJ   to force the rebase please set experimental.evolution.allowdivergence=True   ,r   N)r   r   r   r   r   rR   r   )	rB   r[   rebaseobsrevsrebaseobsskippeddivergenceokdivergencebasecandidates	divhashesr   hs	   `        r.   r   r   l  s     %dH,GHHL,/?? F FFFFF-EFFF	>??;
 
 sdii	&:&:%<<1EEEEF F F Fr-   c              #      K   | j         J | j        j        j        }t	          j        | j        | |                                         g          D ]} ||          }||V  dS )z,yield revision numbers for successors of revN)r   r   indexget_revr   allsuccessorsobsstorer%  )rS   r   r  r5   r   s        r.   successorrevsr    sv      ?"""n"*G"4=49>>3C3C2DEE  GAJJ=GGG r-   c           	      
	     j         J  j        j        |         } j                                      }t          t          gt           |||          t          |          }t          d |dd         D                       rd         d<   nt          |          D ]\  }	|	}
t          fdt           |	          D                       r	         }
n|	|v r||	         dk    r||	         }
t          d                   D ]T\  }}|t          k    r |
|          rt          }
% ||
          r#|
|<   t          }
|         ||         c||<   |<   U|
<   ŉd         t          k    rb|d         d         k    rPt                    dk    rt          |          dk    sJ                                  |                                 t                    t          |          k    r0|vr,t          j        t!          d                    fz            t          fdD                       r!t          j        t!          d	                    t#          fd
t          |          D                       dk    rddg}t          |          D ]\  }|t          k    s|v rt          |          |hz
  }t                               d|||                    }|rVfd|                                D             }fd|D             }t                               d|||                    |<   t          d |D                       rt)          d t          |          D                       \  }|dk    r[t!          d                               fd|D                       }t          j        t!          d                    |fz            dk    r?         t          k    r         d         cd<   <   |         |d         c|d<   |<   |d         } j                            dt1                    z             d         d         |fS )a  Return 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.
    Nc              3   ,   K   | ]}|t           k    V  d S rE   r   r   s     r.   r   z defineparents.<locals>.<genexpr>  s&      
+
+A1<
+
+
+
+
+
+r-   r+   r   c              3   <   K   | ]} |                   V  d S rE   r,   )r   rJ   rV   r   r  s     r.   r   z defineparents.<locals>.<genexpr>  s3      KKq::aq**KKKKKKr-   r   s>   cannot rebase %d:%s without moving at least one of its parentsc              3   F   K   | ]}|t           k    o |          V  d S rE   r  )r   r  r  r   s     r.   r   z defineparents.<locals>.<genexpr>  s8      
>
>11<.JJsA..
>
>
>
>
>
>r-   !   source is ancestor of destinationc              3   :   K   | ]}|t           k    |vd V  dS )r+   Nr  )r   r  newpss     r.   r   z defineparents.<locals>.<genexpr>  s/      
D
DALLQe^^1^^^^
D
Dr-   s   (%ld %% (%d+%d))c                 .    g | ]\  }}|d k    |v|S ro  r,   )r   r   r   
obsskippeds      r.   r  z!defineparents.<locals>.<listcomp>  s6       !Q1q55Qj=P=PA=P=P=Pr-   c                 \    g | ](}                     |          d          t          k    &|)S )r+   )r  r   )r   r   r&  s     r.   r  z!defineparents.<locals>.<listcomp>  s;       BMM!,<,<Q,?7,J,JA,J,J,Jr-   s   %ld - (::%ld) - %ldc              3      K   | ]}|d uV  	d S rE   r,   )r   rN   s     r.   r   z defineparents.<locals>.<genexpr>  s'      55Dt4555555r-   c              3   B   K   | ]\  }}|t          |          |fV  d S rE   )rQ   )r   r   rN   s      r.   r   z defineparents.<locals>.<genexpr>   sB        At# TA#### r-   s    or c              3   ^   K   | ]'}|d                     fd|D                       V  (d S )Nrr  c              3   2   K   | ]}d ||         fz  V  dS )r  Nr,   rv  s     r.   r   z*defineparents.<locals>.<genexpr>.<genexpr>+  s0      "I"Iq8q$q'l#:"I"I"I"I"I"Ir-   )r   )r   rN   rB   s     r.   r   z defineparents.<locals>.<genexpr>*  sV         + 

"I"I"I"ID"I"I"III++++ r-   s4   rebasing %d:%s will include unwanted changes from %ss    future parents are %d and %d
)r   r   isancestorrevr  r   r<  r  allr   anyr  rQ   reversern   r   r   r   sumrN   r   r[  r   r[   r   tuple)rB   r   rm   r    ro   r"  r   oldpsbasesr  npjrJ   unwantedrM  other_basessiderevsr  mergesr   unwanteddescr&  rV   r   r  r   s   ``   `               @@@@@r.   r=  r=    s]     ?"""	B!J3<DN%%c**EgEtS'5'::EKKE

+
+qrr
+
+
+++ F8a0 e$$ 	 	DAqBKKKKKKM$4J4JKKKKK 1Xea11X "%),, < <1<<:b!$$ < BBZ2&& <!E!H B */q58&E!HeAhE!HH
 8w58uQx#7#7u::??s5zzQMMOOOMMOOO u::U##E(9(9":  S	"	#   
>
>
>
>
>
>
>
>>> Hq!EFFGGG" 
D
D
D
Dc%jj
D
D
DDDqHH$< '' 	 	GAtw$%-- e**v-K		-{D$GG H     "'++--  	   (   #II.&)   55H55555 	8  (22    DAq 1uu zz   $,      &MNNDI|45   Avv8w&&).q58&E!HeAh%*1XuQx"a%( 8DGMM4uU||CDDD8U1Xt##r-   c                     t           j                            | j        j        |          }t	          j        t          |d                    D ]}|                    d          r dS dS )z/Return true if the given patch is in git formats   rbs
   diff --gitTF)ospathr   mqr   
linereaderr   
startswith)rB   	patchnamemqpatchlines       r.   isagitpatchr@  F  sd    gll47<33G gu!5!566  ??=)) 	44	5r-   c           
         i }| j         j        dd         }t                      j        D ]}| |j                                                 }||v rD| j                            d||j        fz             |j        t          | |j                  f||<   i
                    |j                   |r                    | |                                           t          |d          D ]}||vro||         \  }}	| j                            t          d          |||         | ||                  fz                                 | d||	d||         z  g           u
                    ||         d	                    fd
|D             }
|
j        dd<   d_                                         dS dS )z9Update rebased mq patches - finalize and then import themNs.   revision %d is an mq patch (%s), finalize it.
T)r+  s   updating mq patch %s to %d:%s
r,   r   )r=  gitr   r   c                 Z    g | ]'}j                             |d           d         v%|(S )r+   r   )guard_rer   )r   r5   r:  skippedpatchess     r.   r  zupdatemq.<locals>.<listcomp>{  sE     
 
 
{  A&&q)?? ???r-   )r:  
fullseriesrn   appliedr%  r   r[   r   namer@  r   finishr   r   r  r   qimportseriesdirty	savedirty)rB   r    ro   ri   mqrebaseoriginal_seriesr  r   rH  isgit	newseriesr:  rE  s              @@r.   r]  r]  O  s   H	BmAAA&OUUNZ 
' 
'16l  %<<GMMB-    V[qv%>%>?HSMM qv&&&&  
		$((( (D111 	5 	5C'!!&sme899U3ZeCj)9:;   

"s+,      ""8C=#34444

 
 
 
 
$
 
 
	
 %aaa
A   r-   c                     |pd}|                      dd          }|                    d|z             |                                 dS )z,Store the collapse message to allow recoveryr-      last-message.txtr   r   N)r   r   close)rB   rs   r   s      r.   r  r    sH    $K$d++AGGGk!"""GGIIIIIr-   c                 >    | j                             dd           dS )zRemove collapse message filerR  TrV  N)r   r`  )rB   s    r.   r   r     s$    H+4@@@@@r-   c                    	 |                      d          }|                                                                }|                                 n6# t          $ r) |rd}n!t          j        t          d                    Y nw xY w|S )z*Restore previously stored collapse messagerR  r-   s'   missing .hg/last-message.txt for rebase)r   readliner|  rS  FileNotFoundErrorr   r   r   )rB   r   r   rs   s       r.   r   r     s    	MHH())jjll((**					 M M M 	MKK+a JKKLLL KM s   AA 0BBc                     |                                  }|r|                    d           | j                            dd           dS )zRemove the status filesre   TrV  N)r  removefilegeneratorr   r`  )rB   r   s     r.   r   r     sR     
	 	 	"	"B	 /
~...Hd;;;;;r-   c              #     K   t          |           }|rrt          |          }g }|D ]!}| |         |vr|                    |           "|s!t          j        t          d                    |t          |          z  }|V  |pdS dS )a  yield 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)rn   r   r  r   r   r   )rm   srcsetsrclistr   r   s        r.   r  r    s       \\F
 	.. 	! 	!Aqz''a    	N"1%K#L#LMMM#f++  	 	 	 	 	r-   c                 j    |                                 } d                                         }d                                 v r] fd j        j        D             }t          |                                          |z  r!t          j        t          d                    t          t          |                    }|s!t          j        t          d                    t                               d|d                             }|s!t          j        t          d                    d }t          ||	          }t                              |t                     t#          |          d
k    }	|D ]Z}
 ||
                                                  }|
                    |          }||
k    r!t          j        t          d                    ||k    rԉ d         }||                                k    r+|
                                |                                k    }n*|
                                |                                k    }|s]|r[||
                                v rE|
                                |
                                <    j                            d           9d}	 j                            d||
fz             \|	rdS t                    D ]H}d  j                            |          D             }|r t5          fd|D                       r||<   I||fS )zlDefine which revisions are going to be rebased and where

    repo: repo
    destmap: {srcrev: destrev}
    rX  rQ  c                 N    h | ]!}|j                                                  "S r,   )r%  r   )r   r5   rB   s     r.   r   zbuildstate.<locals>.<setcomp>  s+    AAAAT!&\%%''AAAr-   s&   cannot rebase onto an applied mq patchs   no matching revisionsrx  r   c                 *    |                                  S rE   rS  )r   s    r.   revofzbuildstate.<locals>.revof  s    uuwwr-   )keyr+   r  Ns!   source is a child of destination
Fs    rebase onto %s starting from %s
c                 (    g | ]}|t           k    |S r,   r  r  s     r.   r  zbuildstate.<locals>.<listcomp>   s    MMMW1r-   c              3   J   K   | ]}                     |          |k    V  d S rE   )r3   )r   r  r    s     r.   r   zbuildstate.<locals>.<genexpr>  s2      ??!EIIaLLA-??????r-   )r   r   r\  r:  rG  rn   r   r   rR   r   r  r  r   r   dictfromkeysr   rQ   r  r>  r9   r^  r[   r   r   r  r)  )rB   rm   r`   r  rj   	mqapplied	sortedsrcr  r`  emptyrebaserootr   
commonbaser  
samebranchr   r^  r    s   `                @r.   r   r     s    Id!!J
 $))++AAAAAAA	w~~  9, 	Q"1%N#O#OPPP Z(())I <q!9::;;; -16677E <q!9::;;;   5e$$$EMM)W--Ei..A%K K KGDHHJJ'(]]4((
"1%I#J#JKKK:Dtwwyy  ![[]]dkkmm;

![[]]dkkmm;
 
 tt||~~/E/E %)HHJJdhhjj!CDDD:dD\IJJJJ te}}  MMdn77<<MMM 	s????w???@@ 	E#Jw%%r-   Tc	                    |j         j        }	i }
i }t          j        |t          j                   }g }t          |                                          D ]v\  }}|dk    rk||k    re |	|          }|p
 |	|          }|||<   d}||v r|s||                                         sd}n|r|                    |           n|f}|||
|f<   w|r|f|
t          |          <   |r|j	        |j
        }|j        }i }|
                                D ]/\  }}|D ]'} |fd|D             d          | |          <   (0 ||dd	          }|                    |
           |ri }
t          j        ||
d||           dS )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.
    r   Nr,   c                 &    g | ]} |          S r,   r,   )r   nhfs     r.   r  z clearrebased.<locals>.<listcomp>;  s!    '<'<'<!1'<'<'<r-   s   node)rH  s   oldnodes   newnodes)ra  value)nodechangesr<   ry  )r   r%  r   r   r   r   r   r  r-  hexfunc
formatlist
formatdictr   r   cleanupnodes)r[   rB   rm   r    ro   rj  rw   rU  r   tonodereplacementsmovesstripcleanupcollapsednodesr   r   oldnoder6  succsflfdchangesoldnsnewnoldnrq  ro  s                             @r.   r_  r_    s   , ^ FLE)$0IJJJLNekkmm,, 1 1VQ;;6S==fSkkG!3VVF^^G$E'NEg~~ tCy'9'9';'; E #%%g.... 
 +0gZ( =/:nU>**+	 	)Z]]'--// 	L 	LKE4 L L$&B'<'<'<'<t'<'<'<7$K$K$K4!!LbjDDD
K((( |YfMMMMMMr-   c                    |                     d          rd|                    dd          r4t          d          }t          d          }t          j        ||          |                                5  |                                5  |                     d          r|d= |                    d           t          j	        |d	
           t          j
        |t          d                     t          |          }t          j        }d }	|	t          _        	  | ||g|R i |}
|t          _        n# |t          _        w xY wt          |          }||k    rd|v r|d= d|v r|d= t          |j                            |                    }||d<   	 t#          ||fi | n# t          j        $ r t'          j        |          \  }}}||d                                         k    r#|                    t          d                     n7|                    t          d                     t          j        ||           Y nw xY wddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   nC|                     d          r!t          j        t          d                     | ||g|R i |}
|
S )zCCall rebase after pull if the latter has been invoked with --rebaser  r  r  s,   rebase destination required by configurations)   use hg pull followed by hg rebase -d DESTr   r   sC   --update and --rebase are not compatible, ignoring the update flag
T)	skipmergesC   cannot pull with rebase: please commit or shelve your changes firstc                      d S rE   r,   )r   kwargss     r.   _dummyzpullrebase.<locals>._dummy_  s    r-   r   r  )startr  rX  r   s%   nothing to rebase - updating instead
Nr9  s%   --tool can only be used with --rebase)r3   ru   r   r   r   r  r  r   r	   r  rB  rQ   r
   postincomingr  r   rN   r  NoMergeDestAbortr   
destupdater   r   r   )origr[   rB   r   ri   r   r   revsprepullorigpostincomingr  retrevspostpullr@   r   _a_bs                   r.   
pullrebaser  C  s   xx >,==&;<< 	3CDDCABBD"3T2222ZZ\\ 4	2 4	2499;; 4	2 4	2xx!! N)  
 #DD9999!B     d))K'4   %+H!9d2t3d333d33(8%%(8%8888t99Lk)) D==U t##X !4!4;!4!G!GHH	%.\"22t,,t,,,,- 	2 	2 	2"*"5d";";KCRd4jnn....		!$:";";<<<<		!$M"N"NOOO !D111	2W4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2 4	2l 88F 	P"1%M#N#NOOOd2t+d+++d++Jsu   5I/
BID6)I6EAIF'&I'BI	II		II/I	I/I	 I//I36I3c                    i }t                      }| j        }|j        j        t          |                     d                    }|D ]}|                    |          }t          t          j        | j        |g                    }	|		                    |           fd|	D             }
|

                    d           |	r|
                    |          rd||<   |         }|
D ]}|                    ||          r|||<    n5 ||v st          fd|
D                       r|                    |           ||fS )ai  Figure 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()c                 &    h | ]} |          S r,   r,   )r   r5   r  s     r.   r   z)_compute_obsolete_sets.<locals>.<setcomp>  s!    3331GGAJJ333r-   Nc              3       K   | ]}|v V  	d S rE   r,   )r   r5   rm   s     r.   r   z)_compute_obsolete_sets.<locals>.<genexpr>  s'      /O/OW/O/O/O/O/O/Or-   )rn   r   r  r  rN   r%  r   r  r  removediscardissubsetr(  r*  r   )rB   r  rm   r{   r|   r&  extinctrevssrcrevsrcnode
successorssuccrevsdstrevsuccrevr  s     `          @r.   r   r     s    .0*,/EE)	BhGdii--..K F F''&//.t}wiHHII
'"""3333
333 	FX..{;; 	F=A26::V_F# 	F 	F##GV44 EL:6BE [((C/O/O/O/Oh/O/O/O,O,O(9==fEEE 	/- r-   c                    |                                 5  |                                5  t          ||           }|                    d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NTr  )r  r  r^   r   )r[   rB   r  s      r.   abortrebaser    s    	 4 4tyy{{ 4 4dB''%%d%3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s4   A5'AA5A!	!A5$A!	%A55A9<A9c                    |                                 5  |                                5  t          ||           }t          j                            |          }t          j        |           |                    d          }||cd d d            cd d d            S |	                    d            |
                                 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NFr  )r  r  r^   r  r   r   r   r  r   r"  rl  )r[   rB   r  r  r  s        r.   continuerebaser    s   	  tyy{{  dB''%**400!"%%%///>>               	T"""                                sA   C-ACC- )C	C-C	C-C	C--C14C1c           	      b   |j                             d          sd S 	 t          || i           }|                                 |j        }n:# t
          j        $ r( t          d          }|                     |           Y d S w xY wt          d |
                                D                       }|                     t          d          |                     t          d          d          |z  |                     t          d          d          t          |          |z
  z  fz             d S )	Nre   s8   rebase: (use "hg rebase --abort" to clear broken state)
c                     g | ]
}|d k    |S ro  r,   )r   r   s     r.   r  zsummaryhook.<locals>.<listcomp>  s    :::A166a666r-   s#   rebase: %s, %s (rebase --continue)
s
   %d rebaseds   rebase.rebaseds   %d remainings   rebase.remaining)r   r   r^   r   r    r   r   r   r   rQ   r   label)r[   rB   r  r    r   
numrebaseds         r.   summaryhookr    s8   8??>** dB++    LMM
	
 :::::;;JHH	
122HHQ}%%'899JFHHQ'')<==5zzJ&(
	
    s   ,A 3BBc                    t          j        t          j        dt                    }|d                             ddd t          d          f           |d                             dddt          d          f           t          j        	                    dt                     t          j        dd	d
d
t          t                     d S )Ns   pullr+   r-   r<   s'   rebase working directory to branch headr  r  s   specify merge tool for rebasere   T)fnamestopflagcontinueflag	abortfunccontinuefunc)r   wrapcommandr
   tabler  r  r   r	   summaryhooksr   r  r   addunfinishedr  r  )r[   entrys     r.   uisetupr    s    "8>7JGGE	!HOO	iq!KLLM   
!HOOT7C+K)L)LMNNNY444#     r-   rE   )F)NFNT)Yr  r8  mercurial.i18nr   mercurial.noder   r   r   mercurial.pycompatr   	mercurialr   r	   r
   r   r   r   r   r   r   r   rC  r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r   r   r   cmdtablerY   configtable
configitem
testedwithr/   r6   r:   rC   revsetpredicaterK   rW   r\   r^   
dryrunoptsformatteroptsconfirmoptsCATEGORY_CHANGE_MANAGEMENTr  r  r  r  r  r   r2  r3  r?  r<  r   r  r=  r@  r]  r  r   r   r   r  r   r_  r  r   r  r  r  r  r,   r-   r.   <module>r     s;    
			               
 $ # # # # #                                                       B 
 ,++
)
H
%
%!Y!+..
 

#    #
  * * *$ $ $
 
 
 
 ,)+--   
E 
E ! 
E )**# # +*#,  F F F F F F F FR 	 AFGGAfII	
 ANOOAfII	
 
vr116776CA455AfII	
 
k5!!$F"G"GHA455AgJJ	
 
wqq!DEEFA788AgJJ	
 
wqq!<==>	ouaa(E&F&FG	y%?!3!34	~uaa&8&89	wQQ4556	guaa :;;<	{E11%F#G#GH	x"@ A ABA: 		
_8r s9t u:v w;x AGHH3@ @ @BE1 E1C@ @BE1P< < <~6 6 6 6
K* K* K*\^ ^ ^B  4  8   /> /> />dK K K\F F F,  w$ w$ w$t  3 3 3l  A A A
  < < <  4@& @& @&R 
9N 9N 9N 9NxB B BJ* * *Z4 4 4	 	 	  0    r-   