
    q&fF                        d dl Z d dlZd dlZd dlZd dlmZmZmZ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 ddlmZmZ eeeeee	gsJ dZej.                  rddlmZmZmZmZmZmZ eeeeeegsJ ee e	e e e f   f   Z!d	d
ddde!fdZ"ddde!ddfdZ#	 d*dddddd
dd
de$dee   de!fdZ%	 d+ddddddddde$de	ee    ee    e!f   fd Z&d! Z'ddde fd"Z(d#d$de fd%Z)	 	 d,ddd&e$d'e$dee    fd(Z*ddd	d
de+fd)Z,y)-    N)AnyDictListOptionalSetTuple   )_)configerror	filemergepathutilphasesutil)
stringutilurlutil)    r   s   empty)context	localrepomatchscmutilsubrepouictxzcontext.changectxr   zuimod.uireturnc           
      ~    t        j                           j                         d fd	d v r d       j                  d      D ])  \  }}j                  d||j	                  d|             + i }d v rb	 t         d   j                         j                               D ]3  \  }}|j                         }|s	 |j                  dd      \  }}|||<   5 	 d	t         d
t         ffd}i }	j#                  d      D ]]  \  }}d}
|j%                  d      rLd|vrt        j                  t        d            |j                  dd      \  }
}|
dd }
|j                         }t'        j(                  |      j+                         st-        d      }|rt'        j(                  |      }t/        j0                  |j2                  xs d|      |_        t/        j4                  |j2                        |_        t!        |      } ||      }||k(  r	 ||      }n|} ||      }|j7                         |j9                  |d      |
f|	t;        j<                  |      <   ` |	S # t        $ r6 t        j                  t        d      j                  d      |dz   fz        w xY w# t        $ r Y w xY w)zreturn a state dict, mapping subrepo paths configured in .hgsub
    to tuple: (source from .hgsub, revision from .hgsubstate, kind
    (key in types dict))
    Nc                 6   | v r*	 |    j                         }j                  | |||       y t        j                  t        d      j	                  |       z        # t        $ r/ j                  t        d      j	                  |       z         Y y w xY w)Ns*   warning: subrepo spec file '%s' not found
s    subrepo spec file '%s' not found)dataFileNotFoundErrorwarnr
   pathtoparser   Abort)	fsectionsremapr   r   preadrepor   s	       7/usr/lib/python3/dist-packages/mercurial/subrepoutil.pyr(   zstate.<locals>.readP   s    81v{{} GGAtXud3++784;;q>I  % FGkk!n% s   A   5BB   .hgsub   subpaths   .hgsubstate    r	   s8   invalid subrepository revision specifier in '%s' line %dsrcr   c           	         j                  d      D ]J  \  }}t        j                  |      }t        j                  dd|      }	 t        j                  ||| d      } L | S # t        j
                  $ rK}t        j                  t        d      j                  d|      t        j                  |      fz        d }~ww xY w)Nr,   s   \\\\([0-9]+)s   \\\1r	   s#   bad subrepository pattern in %s: %s)
itemsr   	escapestrresubr   r#   r
   sourceforcebytestr)r/   patternrepler'   s       r*   r&   zstate.<locals>.remap|   s    WW[1 	MGT ''-D 66*Hd;D	ffWdC3	$ 
 88 kk<=g6"//2 s   A""C 5AB;;C r   s   hg   [   ]s!   missing ] in subrepository sourceFabort)NN)r   r)   configitemssetconfigsource	enumerater   
splitlineslstripsplit
ValueErrorr   r#   r
   r!   r   bytesr1   
startswithr   urlisabs
_abssource	posixpathjoinpathnormpathstripgetr   pconvert)r   r   rM   r/   revilrevisionr&   statekindparentjoinedremappedr'   r(   r)   s   ``            @@@r*   rV   rV   H   s   
 }}A88:D " CY^^K0 J	c	k4book4&HIJ C	!#n"5":":"<"G"G"IJ %1HHJ	%&WWT1%5NHd %D	%$5 U * EWWS\ M	c>>$3kk!$H"IJJ		$*ID#8D**,C{{3%%'E2F V,'nnV[[-?CE'00=v !=v%*C"CCj&)iik37743Et%LdmmD!"3M6 L{ " ++;  ;;~6Q@	A  ! 		s+   AJ/ I-J/ -?J,,J/ /	J<;J<r)   zlocalrepo.localrepositoryrV   c                     t        |      D cg c]!  }||   d   t        d   k7  rd||   d   |fz  # }}| j                  ddj                  |      d       yc c}w )z=rewrite .hgsubstate in (outer) repo with these subrepo statesr	   s   %s %s
r-   r   N)sorted	nullstatewwriterL   )r)   rV   sliness       r*   
writestatera      sj     8A;)A,& 	eAhqk1%%E 
 	KK5s   &Awctxzcontext.workingctxmctxactx	overwritelabelsc                     ||k(  r|j                         }|j                  }|j                  }|j                  }i }	 j                  j                  d|||fz         d fd	}
t	        j
                  |      }t        |j                               D ]  \  }}|j                  |t              }|}|j                  |      j                         r|d   |d   dz   f}||k(  r|}|j                         }||d<   ||v r||   }||k(  s||k(  r||	|<   ||k(  r1 |
|d|       |j                  |      j                  ||       ||	|<   |d   |d   k7  rk|d   |d<   |d   |d	<    j                  j                  t        d
      |z  d      s |
|d|       |j                  |      j                  ||       ||	|<   -|d   |d   k(  r2 |
|d|       |j                  |      j                  ||       ||	|<   j |
|d       |j                  |      }|j                  |d         |d<   |j                  |d         |d<    j                  j                  t        d      |z  d      }|dk(  r1|j                  |      j!                  |       ||	|<    |
|d|       |dk(  r||	|<    |
|d|       &|j                  |      j                  ||       ||	|<    |
|d|       X||k(  r* |
|d       |j                  |      j#                          |t        k(  r |
|d       ||	|<    j                  j                  t        d      |z  d      s |
|d       |j                  |      j#                           t        |j                               D ]  \  }}||v r||vr0 |
|d|       |j                  |      j                  |       ||	|<   ?|||   k7  sH|j                         }||d<    j                  j                  t        d      |z  d      dk(  s |
|d|       |j                  |      j                  |       ||	|<    t%         |	       |	S )z{delegated from merge.applyupdates: merging of .hgsubstate file
    in working context, merging context and ancestor contexts   subrepo merge %s %s %s
c                 V    |rd|z  }j                   j                  d| ||fz         y )Ns   %s:%s:%ss     subrepo %s: %s %s
)r   debug)r_   msgrr)   s      r*   ri   zsubmerge.<locals>.debug   s+    aA.!S!<=r   r   r	      +   ss   other changed, gets   los   ros    subrepository sources for %(s)s differ
you can use (l)ocal%(l)s source (%(lo)s) or (r)emote%(o)s source (%(ro)s).
what do you want to do?$$ &Local $$ &Remotes   prompt changed, gets   other side changed, gets   both sides changeds   sls   srs    subrepository %(s)s diverged (local revision: %(sl)s, remote revision: %(sr)s)
you can (m)erge, keep (l)ocal%(l)s or keep (r)emote%(o)s.
what do you want to do?$$ &Merge $$ &Local $$ &Remotes
   merge withs   keep local subrepo revisions   get remote subrepo revisions   remote removed, removes   local added, keepsz    local%(l)s changed subrepository %(s)s which remote%(o)s removed
use (c)hanged version or (d)elete?$$ &Changed $$ &Deletes   prompt removes   remote added, getsz    remote%(o)s changed subrepository %(s)s which local%(l)s removed
use (c)hanged version or (d)elete?$$ &Changed $$ &Deletes   prompt recreate)r   )p1substater   ri   r   
partextrasr\   r1   rP   r]   r4   dirtycopypromptchoicer
   shortidmergeremovera   )r)   rb   rc   rd   re   rf   s1s2sasmri   
promptssrcr_   rT   aldpromptsrk   srepooptions   `                   r*   submerger      s}    t|wwy	B	B	B	BGGMM-tT0BBC>
 %%f-Jrxxz" W%1FF1i 88A;A$!t$B4<A//#71AQw!q&1qa.29-1A!A$!"1!"177''0  
 !3Q7HHQKOOAy1BqEA!A$a3Q79-1a./!&qt!4!&qt!4--:   Q;HHQK%%a(BqE!]A.q[BqE!;Q?HHQKOOAy1BqE!;Q?1W!./HHQK )^!)*BqEww##.  	 a)*""$oW%r rxxz" 17b[!)1-HHQKOOABqE"Q%Z oo'GGDM$$2  	 
 a+Q/"138 tRIr   zcontext.workingcommitctxstatuszscmutil.statusr   zmatchmod.basematcherforcec                    g }t               }|j                  j                         }d|v r;|j                  |j                  |j
                  fD ]  }d|v s|j                  d        |j                         j                  }	t        |j                               D ]  }
 ||
      s0|
|	v r	|	|
   ||
<   |s!t        j                  t        d      |
z        |j                  |
      j                  d      }|rU| j                  dd      s t        j                  |t        d            |j!                  |
       |j#                  |
       |j                  |
      j%                         }||
   d	   |||
   d
   f||
<   |	j'                  |
d      d   |k7  s|j!                  |
        |j)                         D ]<  }|j                  D 
cg c]	  }
|
|vs|
 }}
||D 
cg c]  }
 ||
      s|
 c}
z  }> |r |d      sAd|j                         |j	                         z   v rt        j                  t        d            |j                  j+                  d	d       nVd|j
                  v rHd|v rDd|j                  |j                  z   |j
                  z   vr|j
                  j+                  d	d       |||fS c c}
w c c}
w )ay  Calculate .hgsubstate changes that should be applied before committing

    Returns (subs, commitsubs, newstate) where
    - subs: changed subrepos (including dirty ones)
    - commitsubs: dirty subrepos which the caller needs to commit recursively
    - newstate: new state dict which the caller must write to .hgsubstate

    This also updates the given status argument.
    r+   r-   s#   commit with new subrepo %s excludedTs   uis   commitsubreposs#   use --subrepos for recursive commit)hintr      )NNNr	   s$   can't commit subrepos without .hgsub)r?   ro   rr   modifiedaddedremovedrv   rn   r\   keysr   r#   r
   r4   dirtyreason
configboolappendadd	basestaterP   parentsinsert)r   rb   r   r   r   subs
commitsubsnewstatecoldstater_   r   bsr'   rk   s                  r*   	precommitr   M  s     DJ}}!!#H D&,,> 	)A"(	) 779%%( 	#A8="*1+HQK++@AAE  ((1+11$7K}}U,=>++#EF  Aq!XXa[**,'{1~r8A;q>B<<#56q9R?KKN/	#4  	/AJJ<q!8*;<A<.1U1XQ..D	/ #	$**,.) kk!$K"LMMOO""1n5	fnn	$T!nOOfll*V^^;'
 NN!!!^4X%%! =.s   	KK&K4Kc                 H   | }g }t        |d      rct        j                  |j                        }|j	                  t        |             |j                         rn|j                  }t        |d      rc|j                          t        j                  | }t        j                  d      j                  } ||      rP|j                  dd      \  }}|j                  d      r|dd }d}nd}|dz   |z   t        j                   |      z   }|S t        j                   |      }|S )	zRreturn the source of this repo

    Either absolute or relative the outermost repo
_subparents   ^[a-zA-Z0-9+.\-]+:   :r	   s   //r   Nr   )hasattrr   rH   
_subsourcer   rF   rI   r   reverserK   rL   r3   compiler   rD   rG   rN   )	r)   rX   chunksr5   rM   matchschemeschemesepnormalized_paths	            r*   repo_rel_or_abs_sourcer     s	    FF
&,
'V../eFm$<<>"" &,
' NN>>6"D**34::K4zz$*??5!8DCC 4-#-	0B0B40HH  $,,T2r   c                     | }t        |d      r|j                  }t        |d      r| j                  t        t	        j
                  |j                              d S )z9return path to this (sub)repo as seen from outermost repor   N)r   r   rootlenr   normasprefix)r)   rX   s     r*   reporelpathr     sN    F
&,
'"" &,
'99S..v{{;<>??r   r4   zsubrepo.abstractsubrepoc                     | j                   S )z7return path to this subrepo as seen from outermost repo)_relpath)r4   s    r*   
subrelpathr     s    <<r   pushr=   c                 z   t        | d      rt        j                  | j                        }|j	                         rt        |      S t        j                  |j                        |_        t        | j                  |d      }|rt        j                  t        j                  |            }t        j                  |j                  xs d|j                        |_        t        j                  |j                        |_        t        |      S d}t        | d      r| j                  }n|r9| j                  j!                  dd      r| j                  j!                  dd      }nr| j                  j!                  dd	      r| j                  j!                  dd	      }n9| j#                         r)t$        j                  j'                  | j(                        S |rAt        j*                  |      r*t-        |      d
k(  s|d
d dvrt        j.                  |      }|S |rt1        j2                  t5        d            y)zreturn pull/push path of repo - either based on parent repo .hgsub info
    or on the top repo config. Abort or return None if no source found.r   Fr<   r   N_subtoppaths   pathss   default-pushs   defaultr      s   \/s(   default path for subrepository not found)r   r   rH   r   rI   rF   rK   rN   rM   rJ   r   r   rQ   rL   r   r   r   sharedosdirname
sharedpathhasdriveletterr   abspathr   r#   r
   )r)   r   r=   r5   rX   rM   s         r*   rJ   rJ     s    t\"T__-<<>= ((5DOOT?[[v!67F#..);V[[IFK#,,V[[9FK= 4'##DdggnnX?77>>(O<DWW^^Hj177>>(J7D[[] 77??4??33 %%d+t9>T!AYf%<<<-DKkk!GHII r   c                 z   t        j                  |       }t        |dd       }|s|S | j                  dd      }|dvr!t	        j
                  t        d      |z        |dk(  r|S t         j                  }d }t        |      D ]4  }|j                  |      }|j                  ||   d         }	||	k  s1|	}|}6 ||k  r}|dk(  rFt	        j
                  t        d	      t         j                  |   t         j                  |   |fz        | j                  t        d
      t         j                  |   |fz         |S |S )Nro   s   phasess   checksubrepos)   ignores   follow   aborts.   invalid phases.checksubrepos configuration: %sr   r	   r   s=   can't commit in %s phase conflicting %s from subrepository %ssA   warning: changes are committed in %s phase from subrepository %s
)r   newcommitphasegetattrr   r   r#   r
   publicr\   r4   phase
phasenamesr    )
r   r   commitphasero   checkmaxphasemaxsubr_   r4   subphases
             r*   r   r     sf   ''+KsJ-HIIi!12E44kk?@5H
 	
 	}}HFH ggaj99Xa[^,hHF XH++=
 %%k2%%h/	
 
 	5   *F3	4	
 r   )N)F)FT)-r   rK   r3   typingr   r   r   r   r   r   i18nr
    r   r   r   r   r   r   utilsr   r   r]   TYPE_CHECKINGr   r   r   matchmodr   r   r   uimodrF   SubstaterV   ra   boolr   r   r   r   r   rJ   intr    r   r*   <module>r      s&   
  	     	   !		  	   uUE50112e" e
 ex eP60 6 6d 6  !P
%P
P P 	P
 P SMP Pp I&I&
$I& I& "	I&
 I& 4;E
H,-I&X:@1 @e @- %  1J
%1J
1J 1J e_	1Jh)z )(; ) )r   