
    6hk                    (   S SK Jr  S SKrSSKJr  SSKJr  SSKJrJ	r
JrJrJrJrJrJrJr  SSKJr  SrS	 rS
 rS rS rS rSS jrS rS rS rS r S r!S r"SS jr#S r$S S jr%S r& S!S jr'S S jr(S S jr)        S"S jr*      S#S jr+g)$    )annotationsN   )_)hex)	errormatchmerge
mergestatepathutilpycompatrequirementsscmutilutil)hashutilFc                b    [        U SS5      (       a  g[        R                  U R                  ;   $ )N_has_sparseFT)getattrr   SPARSE_REQUIREMENT)repos    2/usr/lib/python3/dist-packages/mercurial/sparse.py
use_sparser   "   s-    t]E**
 **d.?.???    c                   [         R                  " S[        U5      U5         [        5       n[        5       n[        5       nSnSnUR	                  S5       GHO  nUR                  5       nU(       a  UR                  S5      (       a  M3  UR                  S5      (       a/  USS R                  5       nU(       a  UR                  U5        Mv  Mx  US:X  a6  U(       a)  Xc:w  a$  [        R                  " [        S	5      S
U0-  5      eSnUnM  US:X  a  SnUnM  U(       d  M  Uc,  [        R                  " [        S5      X(S.-  [        S5      S9eUR                  5       R                  S5      (       a"  U R                  [        S5      X(S.-  5        GM>  UR                  U5        GMR     X4U4sSSS5        $ ! , (       d  f       g= f)zParse sparse config file content.

action is the command which is trigerring this read, can be narrow, sparse

Returns a tuple of includes, excludes, and profiles.
z+sparse.parseconfig(ui, %d bytes, action=%s)NF   
   #s	   %include 	   s	   [include]s5   %(action)s config cannot have includes after excludes   actionTs	   [exclude]s4   %(action)s config entry outside of section: %(line)s)r   s   lines<   add an [include] or [exclude] line to declare the entry type)hint   /sP   warning: %(action)s profile cannot use paths starting with /, ignoring %(line)s
)r   timedcmlensetsplitstrip
startswithaddr   Abortr   warn)	uirawactionincludesexcludesprofilescurrenthavesectionlines	            r   parseconfigr2   ,   s    
5s3x
 555IIe$D::<D4??400..ABx~~'LL& %7#6++. %f-	.  #"%""?++1 '-<	=
 9
 
 ::<**400GGK '-<	= D!a %d 8+w
 
 
s   C9F7BF77
Gc                <    U R                  XS9R                  5       $ )z1Resolve the raw content of a sparse profile file.)changeid)filectxdata)r   profiler4   s      r   readprofiler8   r   s     <<<388::r   c                   [        U 5      (       d  [        5       [        5       [        5       4$ U R                  R                  S5      nU(       d  [        5       [        5       [        5       4$ Uc  [        R
                  " [        S5      5      e[        U R                  US5      u  p4nX   nU(       a  [        5       nU(       a  UR                  5       nX;   a  M  UR                  U5         [        XU5      n[        U R                  US5      u  pnUR!                  U
5        UR!                  U5        UR!                  U5        U(       a  M  UnU(       a  UR                  S5        X4U4$ ! [        R                   ac    SX4-  n	U R                  R                  SS5      (       a  U R                  R                  U	5        OU R                  R                  U	5         GM&  f = f)zObtain sparse checkout patterns for the given rev.

Returns a tuple of iterables representing includes, excludes, and
patterns.
   sparses3   cannot parse sparse patterns from working directorys?   warning: sparse profile '%s' not found in rev %s - ignoring it
s   missingwarnings   .hg*)r   r"   vfstryreadr   r'   r   r2   r)   popr&   r8   ManifestLookupError
configboolr(   debugupdate)r   revr*   r,   r-   r.   ctxvisitedr7   msg	pincludes	pexcludessubprofss                r   patternsforrevrI   y   s    duceSU""
((

9
%CuceSU""
{kkDE
 	
 $/twwY#G H
)C%llnG!KK !$5 .9i.*I( OOI&OOI&OOH%5 h8 Wx''1 ,, 
14;>B 
 77%%i1BCCGGLL%GGMM#&
s   .E. .A2G%$G%c                >   U R                   R                  5        Vs/ s H/  nXR                  :w  d  M  U R                  R	                  U5      PM1     nn[        5       n[        5       n[        5       nU H  n[        X5      u  pxn	X7-  nXH-  nXY-  nM     X4U4$ s  snf )zDetermine the active sparse config rules.

Rules are constructed by reading the current sparse config and bringing in
referenced profiles from parents of the working directory.
)dirstateparentsnullid	changelogrB   r"   rI   )
r   noderevsallincludesallexcludesallprofilesrB   r,   r-   r.   s
             r   activeconfigrT      s     MM))++D;; 	!4 + 	  %K%K%K'5d'@$H	  [00!s
   BBc                   U R                   nUR                  S5      nU(       a  UR                  S5      nOSnUb
  U(       a  Uc  [        [        R                  " U R
                  R                  S5      5      R                  5       5      nX2S'   U(       aL  U R
                  R                  S5      n[        [        R                  " U5      R                  5       5      nXBS'   SX44-  $ )zwObtain the signature string for the current sparse configuration.

This is used to construct a cache key for matchers.
s	   signatures   tempsignature   0r:   
   tempsparse   %s %s)_sparsesignaturecachegetr   r   sha1r;   r<   digest)r   includetempcache	signaturetempsignaturer*   s         r   configsignaturera      s    
 &&E		,'I		"23[]-Bdhh&6&6y&ABIIKL	'l((""=1Cc 2 9 9 ;<M&3"#y000r   c                   U R                  SS5       n[        U5       H  nUR                  SU-  5        M     U(       aE  UR                  S5        [        U5       H%  nUR                  U5        UR                  S5        M'     U(       aE  UR                  S5        [        U5       H%  nUR                  U5        UR                  S5        M'     SSS5        U R                  R	                  5         g! , (       d  f       N)= f)z:Write the sparse config file given a sparse configuration.r:   s   wbs   %%include %s
s
   [include]
r   s
   [exclude]
N)r;   sortedwriterY   clear)r   r,   r-   r.   fhpies           r   writeconfigrj      s    	)U	#r!AHH&*+ " HH^$H% & HH^$H% & 
$  	$$&! 
$	#s   B?C55
Dc                    U R                   R                  S5      nU(       d
  [        5       $ [        UR                  S5      5      $ NrW   r   )r;   r<   r"   r#   )r   r*   s     r   readtemporaryincludesrm      s4    
((

=
)Cusyy  r   c                    U R                   R                  SSR                  [        U5      5      5        U R                  R                  5         g rl   )r;   rd   joinrc   rY   re   )r   r,   s     r   writetemporaryincludesrp     s4    HHNN=%**VH-=">?$$&r   c                d    [        U 5      nU H  nUR                  U5        M     [        X5        g N)rm   r&   rp   )r   
additionalr,   rh   s       r   addtemporaryincludesrt   
  s)    $T*HQ 4*r   c           	     x   [        U 5      (       a   U R                  R                  S5      (       d  g U R                  5       nUR                  (       d3  UR
                  (       d"  UR                  (       d  UR                  (       a  g [        U SS9nU R                  n[        R                  " 5       n/ n[        U 5      nU HW  nXs;   d  M
  U" U5      (       a  M  [        S5      nUR                  U[        R                   S U5        UR#                  U5        MY     [        R$                  " XU S    U S   SSS9  U H  nUR'                  USSS9  M     U R                  R)                  S5        U R*                  R-                  5         [        S5      n	U R.                  R                  U	[1        U5      -  5        g )	NrW   Fr]   s*   dropping temporarily included sparse files   .wantfiledata
p1_tracked
wc_trackedsA   cleaned up %d temporarily added file(s) from the sparse checkout
)r   r;   existsstatusmodifiedaddedremoveddeletedmatcherrK   mergemodmergeresultrm   r   addfilemergestatemodACTION_REMOVEappendapplyupdatesupdate_fileunlinkrY   re   r)   r!   )
r   ssparsematchrK   mresultdroppedtempincludesfilemessagerE   s
             r   prunetemporaryincludesr     sW   d488??=#A#AAzzQWW		QYY$E2K}}H""$GG(.LK$5$5EFGOOD-"="=tWMNN4 	  tDz4:u5
 TeF  	HHOOM"$$&
	C 	GGNN3\**+r   c                    U Vs/ s H  nSUS4PM
     nn[         R                  " SU5      n[         R                  " X@/5      $ s  snf )zmReturns a matcher that returns true for any of the forced includes
before testing against the actual matcher.s   pathr   )matchmodincludematcherunionmatcher)r   r,   includekindpatsr   s        r   forceincludematcherr   6  sL     8@@xG'3'xH@,,S(;N  .!:;; As   Ac           
        [        U 5      (       d  [        R                  " 5       $ U(       a  US/:X  aT  U R                  R	                  5        Vs/ s H/  nX0R
                  :w  d  M  U R                  R                  U5      PM1     nn[        XS9nSUSR                  [        [        R                  U5      5      4-  nU R                  R                  U5      nU(       a  U$ / nU HV  n [        X5      u  pnU	(       d  U
(       a6  [        R                   " U R"                  S/ U	U
SS9nUR%                  U5        MV  MX     U(       d  [        R                  " 5       nO+[)        U5      S:X  a  US	   nO[        R*                  " U5      nU(       a  [-        U 5      n[/        Xm5      nX`R                  U'   U$ s  snf ! [&         a     M  f = f)
zObtain a matcher for sparse working directories for the given revs.

If multiple revisions are specified, the matcher is the union of all
revs.

``includetemp`` indicates whether to use the temporary sparse profile.
Nrv   rX       r   s   relpath)r   excludedefaultr   r   )r   r   alwaysrK   rL   rM   rN   rB   ra   ro   mapr   bytestr_sparsematchercacherZ   rI   r   rootr   OSErrorr!   r   rm   r   )r   rP   r]   rO   r_   keyresultmatchersrB   r,   r-   r.   r   r   s                 r   r   r   >  s    d  4D6> --/
/{{" %DNNt$/ 	 
  >I
i3x/?/?+F!GH
HC%%))#.FH	+9$+D(H8"..II$$& ( $	 " "	X!	!&&x0,T2$V:$*S!M[
:  		s   F6'F6+AF;;
G	G	c           
        [        U 5      (       d  gUR                  5        Vs/ s H  oUR                  5       PM     nn[        X5      nUR	                  5       (       a  g[        5       n0 n	U(       a)  [        XR                  5       R                  5       /5      n
O[        XR                  5       /5      n
/ nUR                  5        GH   u  pUu  pnUR                  U5        U
" U5      (       a  XU'   OU[        R                  :X  a  UR                  U5        XU'   OaU(       a'  UR                  (       d  UR                  U5        XU'   O3U[        R                  :X  a  XU'   OX;   a  [        R                  UU4X'   U(       d  M  U[        R                  :X  d  M  Uu  nnnnnU
" U5      (       a  M  UR                  U5        GM     [        U5      S:  Ga;  U R                   R#                  [%        S5      [        U5      -  5        ['        X5        [(        R*                  " 5       nSnU S   R-                  5       nU HE  nUU;   d  M  U S   U   nUR/                  U[        R0                  UR3                  5       S4U5        MG     U R4                  R7                  U 5         [(        R8                  " U UU S   U S   SSS9  U R4                  nUR;                  [        R0                  /5       H  u  nnnUR=                  USSS	9  M     SSS5        [?        U 5      S
   nUU-  nU(       a  U(       d  UR-                  5       nU Hr  nU" U5      nU
" U5      n U(       d1  U (       a*  UR3                  U5      n[        R0                  US4S4X'   MK  U(       d  MT  U (       a  M]  [        R                  / S4X'   Mt     URA                  U	5        gs  snf ! , (       d  f       N= f)zAFilter updates to only lay out files that match the sparse rules.Nr   sC   temporarily included %d file(s) in the sparse checkout for merging
s%   temporarily adding to sparse checkoutFrw   rx   Trz      r   )!r   rL   rB   r   r   r"   p1filemapr&   r   ACTION_MERGEr   no_opACTION_FORGETr   r!   r)   r~   r   rt   r   r   manifestr   
ACTION_GETflagsrK   changing_parentsr   
getactionsr   rT   
setactions)!r   wctxmctxbranchmerger   pctxoldrevsoldsparsematchfilesprunedactionsr   temporaryfilesr   r+   typeargsrE   f1f2famoveanctmresultr   wctxmanifestfctxrK   r   r.   changedprofilesmfoldnews!                                    r   filterupdatesactionsr   {  ss   d&*lln5ndxxznG5T+NEEM dWWY]]_$56 dXXZL1N) C		$t"($]///!!$'"($::%%d+&,d#]000"($\#0#>#>c"JM ;4=#=#==$(!BBcr??%%b)5 *8 >Q* .!	"	
 	T2 ''):Dz**,"D|#Dz$'  !,,ZZ\5)	 # ]]++D1!!T
T
" }}H$,$7$7))*% eS $$Tdt$L% 2  D!!$H&O {]]_D &Cd#C3!,,EN'#
 SS'4'B'BB&L#  }%W 6N 21s   O(A(O
O&c           	         [        5       nUR                  UR                  5        UR                  UR                  5        UR                  UR                  5        [        U 5      nSnU H@  nU" U5      (       a  M  U R                  R                  [        S5      U-  5        U(       + nMB     U(       a  [        R                  " [        S5      5      eU R                  nU S   n	/ n
/ n/ nU	R                  5       n[        U5      n[        R                  " 5       nU GH8  nU" U5      nU" U5      nU(       a  U(       a  U(       a  U(       a  UU;  a  UR                  U5      nU R                   R#                  U5      (       a6  UR%                  U[&        R(                  U4S5        UR+                  U5        M  UR%                  U[&        R,                  US4S5        U
R+                  U5        M  U(       a  U(       a  U(       a  M  U(       a  M  UU;   d  M  UR+                  U5        UU;  d  GM  UR%                  U[&        R.                  SS5        GM;     SnU H1  nU R                  R                  [        S5      U-  5        U(       + nM3     U(       a  [        R                  " [        S5      5      eUR1                  5        HA  u  nnUU;  d  M  U" U5      nU" U5      nU(       d  M'  U(       a  M0  UR+                  U5        MC     [        R2                  " XU S   U S   SSS9  U
 H  nUR5                  US	S	S
9  M     U H  nUR5                  USSS
9  M     U H  nUR5                  US	S	S	S9  M     XU4$ )zRefreshes working directory by taking sparse config into account.

The old status and sparse matcher is compared against the current sparse
matcher.

Will abort if a file with pending changes is being excluded or included
unless ``force`` is True.
Fs   pending changes to '%s'
s2   could not update sparseness due to pending changesrw   r   Nsj   cannot change sparseness due to pending changes (delete the files or use --force to bring them back dirty)rx   Trz   )r{   r|   possibly_dirty)r"   rA   r   r   r   r   r)   r(   r   r   r'   rK   r   r   r   r   wvfsr}   r   r   ACTION_EXECr   r   r   itemsr   r   )r   
origstatusorigsparsematchforcependingr   abortfrK   rC   r   lookupr   r   r   r   r   r   r   flstates                        r   refreshwdirr     s    eGNN:&&'NN:##$NN:%%&$-KE1~~GGLL781<=IE 
 kkCD
 	

 }}H
t*CEFG	BGE""$Gd#$ TX5E$Byy%%m&?&?"Ld#-22RK T" #ss3348;KNN4 7"m&A&A4M) . EQ34t;<	  kk5
 	
  ~~'eu}!$'Cd#Cs33t$ ( tDz4:u5
 TdtD  TeF  Td4 	 	
  6!!r   c                    X   n[        XR                  5       5      S   nU[        UR                  5       5      -  (       a&  U R	                  5       n[        U 5      n[        XUSS9  [        U 5        g)z1Perform actions after a working directory commit.r   Tr   N)rI   rB   r"   r   r~   r   r   r   )r   rO   rC   r.   r   r   s         r   aftercommitr   S  s]     *CdGGI.q1H #ciik""[[]
!$-DoTB4 r   c                   U R                  5          U R                  R                  S5      n[        U R                  US5      u  pxn	U R                  5       n
[        U 5      n[        U R                  5      n[        R                  U;   aF  U(       a?  U R                  R                  [        R                  5        [        R                  " U SS9  OR[        R                  U;  a>  U R                  R                  [        R                  5        [        R                  " U SS9   [        XX#5        [        X
XS9sSSS5        $ ! [          ab    U R                  U:w  aD  U R                  R#                  5         U =R                  U-  sl        [        R                  " U SS9  [        XX5        e f = f! , (       d  f       g= f)z5Update the sparse config and working directory state.r:   F)maywritestorer   N)wlockr;   r<   r2   r)   r~   r   r"   r   r   discardr   writereporequirementsr&   rj   r   	Exceptionre   )r   r,   r-   r.   r   removingr*   oldincludesoldexcludesoldprofiles	oldstatusoldmatcholdrequiress                r   _updateconfigandrefreshwdirr   d  s\    
hhy)0;GGS)1
-+ KKM	4=$++, **k9h%%l&E&EF))$eD,,K?!!,"A"AB))$eD		;tF7 
8  	  K/!!'')!![0!--d%H;D	9 
s   DF2$EA,F//F22
G c           
        U R                  5          U R                  R                  U 5         U R                  R	                  S5      n[        U R                  US5      u  p4nU(       d  U(       d   SSS5        SSS5        g[        U [        5       [        5       XQS9  SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zClears include/exclude rules from the sparse config.

The remaining sparse config only has profiles, if defined. The working
directory is refreshed, as needed.
r:   Nr   )	r   rK   r   r;   r<   r2   r)   r   r"   )r   r   r*   r,   r-   r.   s         r   
clearrulesr     s     
t}}55d;hhy)'2477C'K$H < 	$D#%N <;;s/   CAB02CB0C0
B>	:C
Cc                   U R                  5          U R                  R                  U 5         U R                  R	                  S5      n[        U R                  US5      u  pVn[        U 5      u  pn
SnU H  n[        R                  " [        R                  " U5      SS9 nUR                  5       nSSS5        [        U R                  US5      u  pn[        U5      [        U5      -   [        U5      -   nUR                  X-
  5        UR                  X-
  5        UR                  UU
-
  5        [        U5      [        U5      -   [        U5      -   U:  d  M  SnM     S=n=nnSnU(       a@  [        Xz-
  5      n[        XX-
  5      n[        Xi-
  5      n[        [        [        XXgUS	95      n[!        U R                  UUUU/UQ76   SSS5        SSS5        g! , (       d  f       GN/= f! , (       d  f       N)= f! , (       d  f       g= f)
zImport sparse config rules from files.

The updated sparse config is written out and the working directory
is refreshed, as needed.
r:   Fs   rb)modeNTr   )r   r   r   r   )r   rK   r   r;   r<   r2   r)   rT   r   	posixfile
expandpathreadr!   rA   r   r   printchanges)r   optspathsr   r*   r,   r-   r.   	aincludes	aexcludes	aprofileschangedrg   rf   	iincludes	iexcludes	iprofilesoldsizeprofilecountincludecountexcludecountfcountss                         r   importfromfilesr    s    
t}}55d;hhy)'2477C'K$H*6t*<'	i A 2?2ggi @ /:i/+I) (mc(m3c(mCGOOI12OOI12OOI	128}s8},s8}<wF  6766|lx34Lx34Lx34L+HeG 	GGT<|	
FM	
M < @? <;sC   G=A4G,!G	2B$G,A/G,	G=
G)$G,,
G:	6G==
Hc
                  ^ ^	 T R                  5          T R                  R                  T 5         T R                  R	                  S5      n
[        T R                  U
S5      u  pnU(       a  [        5       n[        5       n[        5       nO![        U5      n[        U5      n[        U5      nU U	4S jnU" U5      nU" U5      nU" U5      nU" U5      nU" U5      nUR                  U5        UR                  U5        UR                  U5        UR                  U5        UR                  U5        UR                  U5        [        UU-
  5      [        UU-
  5      -
  n[        X-
  5      [        X-
  5      -
  n[        X-
  5      [        X-
  5      -
  n[        [        [        T UUUUUS95      n[        T R                  UUUU/UQ76   SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zmPerform a sparse config update.

The new config is written out and a working directory refresh is performed.
r:   c                  > [        S U  5       5      (       a  [        R                  " [        S5      5      eT	(       a  U $ TR                  TR                  5       p!/ nU  H}  n[        R                  " US 5      u  pVU[        R                  ;   d  Uc9  U(       a  US-   OS[        R                  " XU5      -   nUR                  U5        Ml  UR                  U5        M     U$ )Nc              3  `   #    U  H$  n[         R                  R                  U5      v   M&     g 7frr   )ospathisabs).0pats     r   	<genexpr>7updateconfig.<locals>.normalize_pats.<locals>.<genexpr>  s      6#277==%%s   ,.s   paths cannot be absolute   :r   )anyr   r'   r   r   getcwdr   	_patsplitcwdrelativepatternkindsr   	canonpathr   )
patsr   cwdabspatskindpatkindr  apr   usereporootpathss
           r   normalize_pats$updateconfig.<locals>.normalize_pats  s    6666kk!$?"@AA 		4;;=#G$..w=	8;;;t|)-$+3(:L:L3; B NN2&NN7+   Nr   )r   r   N)r   rK   r   r;   r<   r2   r)   r"   difference_updaterA   r!   r   r   r   )r   r   r   r   resetdeleteenableprofiledisableprofiler   r  r*   
oldinclude
oldexcluder   
newinclude
newexcludenewprofilesr  r   r  r  r  s   `        `            r   updateconfigr(    s     
t}}55d;hhy).9GGS)/
+
 JJ%KZJZJk*K	* !) )''7&}5$$V,$$V,%%n5'"=)'";45+%9
 
 :23c#7
 
 :23c#7
 
 '

 	GGT<|	
FM	
O <;;s#   G,FG
G,
G)	%G,,
G:c                z   U R                  SU5       nUR                  5         UR                  U R                  S[	        S5      U5        UR                  U R                  S[	        S5      U5        UR                  U R                  S[	        S5      U5        UR                  5       (       du  UR                  U R                  S[	        S	5      U5        UR                  U R                  S
[	        S5      U5        UR                  U R                  S[	        S5      U5        SSS5        g! , (       d  f       g= f)z/Print output summarizing sparse config changes.r:   s   profiles_addeds   Profiles changed: %d
s   include_rules_addeds   Include rules changed: %d
s   exclude_rules_addeds   Exclude rules changed: %d
s   files_addeds   Files added: %d
s   files_droppeds   Files dropped: %d
s   files_conflictings   Files conflicting: %d
N)	formatter	startitem	condwriteverboser   isplain)	r)   r   r   r  r  r   r   conflictingfms	            r   r   r   *  s    
i	&"

JJ'(		
 	JJ",-		
 	JJ",-		
 zz||LL

NA.B,CU LL

,a0F.G LL

$,-	? 
'	&	&s   DD,,
D:)T)NT)F)FF) r1  Fr1  r1  r1  FF)r   r   r   r   r   r   ),
__future__r   r  i18nr   rO   r    r   r   r   r	   r   r
   r   r   r   r   r   r   utilsr   enabledr   r2   r8   rI   rT   ra   rj   rm   rp   rt   r   r   r   r   r   r   r   r   r  r(  r   r1  r   r   <module>r7     s    # 	  
 
 
  @B,L;9(x1214'*!'
+",J<:zp&fb"J!$ ?D&RO .
h 

Y
~ 
/r   