
    6h,                        S SK Jr  S SKrS SKrSSKJr  SSKJrJr  SSK	J
r
  S rS rS	 rS
 rS rS r\R"                  S 5       rS rS rS rg)    )annotationsN   )_)hexshort)errorc                8  ^ ^ T R                  5       m T R                  mTR                  nUS    Vs1 s H  nTR                  U5      iM     nnUU 4S jnSnU" US   US   5      u  pxU(       d  SnU" US   US   5      u  pxTR	                  U5      n	U(       d|  [        US   5      S:X  a=  [        US   5      S:X  a+  US   US   :w  a  [        R                  " [        S5      5      e[        R                  " [        S	5      U[        U	5      4-  5      e0 n
[        R                  " U/5      n/ nU(       ay  UR                  5       nX   / :X  aX  UR                  U5        U" U5       H;  nUS
:w  d  M  X;   a  X   R                  U5        M%  U/X'   UR                  U5        M=     U(       a  My  UR                  5         [        U5      nU Vs/ s H  nUU;  d  M  UU:w  d  M  UPM     nnUS:X  d  U(       d%  U Vs/ s H  nTR	                  U5      PM     snSU4$ US-  nSnS
n[        5       nU GH7  nUU;   a#  UR!                  U
R#                  U/ 5      5        M-  X   =(       d    U/nSX'   [        U5      nUU-
  n[%        UU5      nUU:  a  X;  a  UnUnUU:X  a    OUU:  a(  X;  a#  UR!                  U
R#                  U/ 5      5        M  / nU
R#                  U/ 5       H=  nUU   (       a  ['        [        UU   U-   5      5      UU'   M,  UR                  U5        M?     U(       d  M  UR)                  S5      nU H  nUU/-   UU'   M     UR                  U5        UUU'   GM:     Uc   eTR	                  U5      nU/X4$ s  snf s  snf s  snf )a  find the next node (if any) for testing during a bisect search.
returns a (nodes, number, good) tuple.

'nodes' is the final result of the bisect if 'number' is 0.
Otherwise 'number' indicates the remaining possible candidates for
the search and 'nodes' contains the next bisect target.
'good' is True if bisect is searching for a first good changeset, False
if searching for a first bad one.
   skipc                   > [        U  Vs/ s H  nTR                  U5      PM     sn5      n[        R                  " S 5      nTR	                  SXU5       H  n/ XE'   M	     XC   c  US 4$ X44$ s  snf )Nc                     g )N r       3/usr/lib/python3/dist-packages/mercurial/hbisect.py<lambda>0bisect.<locals>.buildancestors.<locals>.<lambda>*   s    Dr   s   (%ln::%d) - (::%ln))minrevcollectionsdefaultdictrevs)badgoodnbadrev	ancestorsr   	changelogrepos         r   buildancestorsbisect.<locals>.buildancestors(   sv    41immA&45++L9	993T4HCIN I$4<   5s   A.F   bad   goodTr   s+   starting revisions are not directly relateds)   inconsistent state, %d:%s is good and badr      N)
unfilteredr   
parentrevsr   nodelenr   Abortr   r   r   dequepopleftappendsortsetupdategetr   listpop)r   state	clparentsr   skipr   r   r   r   r   childrenvisit
candidatesr   prevtotc	unskippedperfectbest_revbest_lenpoisonaxyvalue	unvisitedfirst	best_noder   s   `                            @r   bisectrG      s    ??DI$$I&+Gn5nIMM!nD5! D&uV}eGnEF*5>5=I
..
 Cf!#E'N#q(fw/++a NOPPkk:;uSz"#
 	
 Hvh'EJ
mmo>Rc"!#2:' --c2*-T* '	 % OO j/C&LJq1D=qF{JIL
axy,67Jq"J7DAAQhG HHUF&=MM(,,sB/0N#se	F!GAq	8HHw;3?MM(,,sB/0	c2&A|#C	!q(8$9:	!  #	 ' 9MM!$E A3w	! HHUO IeK N x(IK##I 6b M7s   N
NN'N Nc                   XS      R                  5       n[        U5      S:  ad  U(       a  US   nOUS   n[        U Vs1 s H  ofR                  5       iM     sn[        U5      -  5      nUS:X  a  US   R	                  US   5      $ g s  snf )Nr   r   r    r!   )parentsr'   r&   r-   ancestor)r   r2   nodesr   rI   sideinums           r   extendrangerO      s     8n$$&G
7|a=D>DW-W668W-D	9:!81:&&wqz22 .s    B
c                4   / / / / S.nU R                   R                  S5       Hq  nUS S R                  5       u  p4U R                  5       R	                  U5      nX1;  a"  [
        R                  " [        S5      U-  5      eX   R                  U5        Ms     U$ )N)   currentr!   r    r
      bisect.stater"   s   unknown bisect kind %s)	vfstryreadlinessplitr$   lookupr   r(   r   r+   )r   r2   lkindr&   s        r   
load_staterY      s    b"rBEXX""?3sV\\^
 ''-++a 9:TABB4  4 Lr   c           
        U R                  SSSS9nU R                  5          [        U5       H-  nX    H"  nUR                  SU[	        U5      4-  5        M$     M/     UR                  5         S S S 5        g ! , (       d  f       g = f)NrR      wT)
atomictemps   %s %s
)rS   wlocksortedwriter   close)r   r2   frX   r&   s        r   
save_staterb      sh    $48A	5MD
dCI%667 $ " 	
		 
s   AA88
Bc                |    U R                   R                  S5      (       a  U R                   R                  S5        gg)z+remove any bisect state from the repositoryrR   N)rS   existsunlink)r   s    r   
resetstaterf      s*    xx''( (r   c                    U S   (       a  U S   (       a  gU S   (       d  [         R                  " [        S5      5      e[         R                  " [        S5      5      e)z\check we have both 'good' and 'bad' to define a range

Raise StateError exception otherwise.r!   r    Ts'   cannot bisect (no known good revisions)s&   cannot bisect (no known bad revisions))r   
StateErrorr   )r2   s    r   
checkstateri      sI     W~%->q!KLMMq!JKLLr   c              #  d   #     S v   U/US'   [        X5        g ! U/US'   [        X5        f = f7f)NrQ   )rb   )r   r2   r&   s      r   restore_staterk      s8      !Fj4 "Fj4s   0 0-0c                `   [        U 5      nUS;   a0  [        U R                  5       R                  R                  X!   5      $ SnU R                  S5      n[        U5      S:X  a  SnSnOSnSnS	nS
XVU4-  nSX84-  n	Sn
SnSXU4-  nUS:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U	5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ [        R                  " [        S5      5      e)a  
Return a list of revision(s) that match the given status:

- ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
- ``goods``, ``bads``      : csets topologically good/bad
- ``range``              : csets taking part in the bisection
- ``pruned``             : csets that are goods, bads or skipped
- ``untested``           : csets whose fate is yet unknown
- ``ignored``            : csets ignored due to DAG topology
- ``current``            : the cset currently being bisected
)r!   r    r
   rQ   s9   ( bisect(bad)::bisect(good) | bisect(good)::bisect(bad) )s   bisect(good)::bisect(bad)r   s   bisect(good)::s   ::bisect(bad)s   ::bisect(good)s   bisect(bad)::s   bisect(skip)s   ( (%s) | (%s) | (%s) )s   ( (%s) - (%s) )s   ::bisect(bad) - ::bisect(good)s   ::bisect(good) - ::bisect(bad)s   ( ( (%s) | (%s) ) - (%s) )s   ranges   pruned   untested   ignored   goods   badss   invalid bisect state)
rY   mapr$   r   r   r   r'   r   
ParseErrorr   )r   statusr2   range_tgoodsbadsskipspruneduntestedibaigaignoreds                r   r/   r/      sP    tE774??$..22EMBB MYY34r7a<%E#D &E#D  *e5-AA &7 0//3U2CCX99U##y 99V$${"99X&&z!99W%%x99U##w99T?"""1%<#=>>r   c                   U R                   R                  U5      nU[        U S5      ;   a  [        S5      $ U[        U S5      ;   a  [        S5      $ U[        U S5      ;   a  [        S5      $ U[        U S5      ;   d  U[        U S5      ;   a  [        S5      $ U[        U S5      ;   a  [        S5      $ U[        U S5      ;   a  [        S	5      $ U[        U S
5      ;   a  [        S5      $ g )Nr!   r    r
   s   skippedrm   rQ   rn   ro   s   good (implicit)rp   s   bad (implicit))r   r   r/   r   )r   r&   r   s      r   labelr     s    
..

T
"C c$  z
c$y
c$  }
c$$$s4/D(D~
c$
##} c$!!#$$
c$  "##r   c                   UR                  5       n[        U5      S:X  a  U(       a  U R                  [        S5      5        OU R                  [        S5      5        UR	                  XS      5        [        XXE5      nUb  U R                  [        S5      U-  5        OXU(       a  U R                  [        S5      5        OU R                  [        S5      5        U H  nUR	                  X   5        M     UR                  5         g )Nr   s   The first good revision is:
s   The first bad revision is:
r   s   Not all ancestors of this changeset have been checked.
Use bisect --extend to continue the bisection from
the common ancestor, %s.
sC   Due to skipped revisions, the first good revision could be any of:
sB   Due to skipped revisions, the first bad revision could be any of:
)r$   r'   r_   r   showrO   r`   )uir   r2   	displayerrK   r   
extendnoder   s           r   printresultr   .  s    ??D
5zQHHQ789HHQ678t!H~& e:
!HHB
  HH8 HH7 ANN47# OOr   )
__future__r   r   
contextlibi18nr   r&   r   r    r   rG   rO   rY   rb   rf   ri   contextmanagerrk   r/   r   r   r   r   r   <module>r      si    #    r$j)	M    A?H>%r   