
    	^ck                        d dl Z ddl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 ddlmZ dZd Zd	 Zd
 Zd Zd ZddZd Zd Zd Zd Zd Zd Z d dZ!d Z"d!dZ#d Z$	 d"dZ%d!dZ&d!dZ'	 	 	 	 	 	 	 	 d#dZ(	 	 	 	 	 	 d$dZ)dS )%    N   )_)hex)	errormatchmerge
mergestatepathutilpycompatrequirementsscmutilutil)hashutilFc                 N    t          | dd          rdS t          j        | j        v S )N_has_sparseFT)getattrr   SPARSE_REQUIREMENT)repos    2/usr/lib/python3/dist-packages/mercurial/sparse.py
use_sparser   !   s.    t]E** 
 t*d.???    c                    t          j        dt          |          |          5  t                      }t                      }t                      }d}d}|                    d          D ]\}|                                }|r|                    d          r/|                    d          r4|dd                                         }|r|                    |           x|dk    r3|r,||k    r&t          j	        t          d	          d
|iz            d}|}|dk    rd}|}|r|6t          j	        t          d          ||dz  t          d                    |                                                    d          r*|                     t          d          ||dz             G|                    |           ^|||fcddd           S # 1 swxY w Y   dS )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   parseconfigr1   +   s    
5s3xx
 
 ;, ;, 555555IIe$$ 0	" 0	"D::<<D ."4??400 .".. +"ABBx~~'' 'LL&&&%% 7h#6#6+.  %f-	.   #"%%"" "?+1  '-t<<	=
 9 
 
 
 
 ::<<**400 GGK  '-t<<	=   D!!!8+w;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;, ;,s   F&GGGc                 T    |                      ||                                          S )z1Resolve the raw content of a sparse profile file.)changeid)filectxdata)r   profiler3   s      r   readprofiler7   q   s&     <<(<3388:::r   c                    t          |           s)t                      t                      t                      fS | j                            d          }|s)t                      t                      t                      fS |!t	          j        t          d                    t          | j        |d          \  }}}| |         }|rt                      }|r	|	                                }||v r|
                    |           	 t          | ||          }nl# t          j        $ rZ d||fz  }	| j                            dd          r| j                            |	           n| j                            |	           Y w xY wt          | j        |d          \  }
}}|                    |
           |                    |           |                    |           |	|}|r|
                    d           |||fS )zObtain sparse checkout patterns for the given rev.

    Returns a tuple of iterables representing includes, excludes, and
    patterns.
       sparseNs3   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   r1   r(   popr%   r7   ManifestLookupError
configboolr'   debugupdate)r   revr)   r+   r,   r-   ctxvisitedr6   msg	pincludes	pexcludessubprofss                r   patternsforrevrH   x   s    d #uuceeSUU""
(

9
%
%C #uuceeSUU""
{kDEE
 
 	
 $/twY#G#G Hh
s)C %% 	&llnnG'!!KK   !$55, 
 
 
14;S>B 
 7%%i1BCC 'GLL%%%%GMM#&&&
 .9i. .*Iy( OOI&&&OOI&&&OOH%%%5  	&8  WXx''s   D A&F Fc                       fd j                                         D             }t                      }t                      }t                      }|D ]%}t           |          \  }}}||z  }||z  }||z  }&|||fS )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.
    c                 Z    g | ]'}|j         k    j                            |          (S  nullid	changelogrA   .0noder   s     r   
<listcomp>z activeconfig.<locals>.<listcomp>   s@       4; 	4  r   )dirstateparentsr!   rH   )	r   revsallincludesallexcludesallprofilesrA   r+   r,   r-   s	   `        r   activeconfigrY      s       M))++  D %%K%%K%%K    '5dC'@'@$(Hxxx[00r   Tc                    | j         }|                    d          }|r|                    d          }nd}||r|t          t          j        | j                            d                                                              }||d<   |rR| j                            d          }t          t          j        |                                                    }||d<   d||fz  S )zObtain the signature string for the current sparse configuration.

    This is used to construct a cache key for matchers.
    s	   signatures   tempsignature   0Nr9   
   tempsparse   %s %s)_sparsesignaturecachegetr   r   sha1r:   r;   digest)r   includetempcache	signaturetempsignaturer)   s         r   configsignaturerf      s    
 &E		,''I 		"233[]-Bdh&6&6y&A&ABBIIKKLL	'l 	4(""=11Cc 2 2 9 9 ; ;<<M&3E"#y-000r   c                 4   |                      dd          5 }t          |          D ]}|                    d|z             |rQ|                    d           t          |          D ],}|                    |           |                    d           -|rQ|                    d           t          |          D ],}|                    |           |                    d           -ddd           n# 1 swxY w Y   | j                                         dS )z:Write the sparse config file given a sparse configuration.r9   s   wbs   %%include %s
s
   [include]
r   s
   [exclude]
N)r:   sortedwriter^   clear)r   r+   r,   r-   fhpies           r   writeconfigro      sY   	)U	#	#  r!! 	, 	,AHH&*++++ 	 HH^$$$H%%     	 HH^$$$H%%                                   	$$&&&&&s   CC44C8;C8c                     | j                             d          }|st                      S t          |                    d                    S Nr\   r   )r:   r;   r!   r"   )r   r)   s     r   readtemporaryincludesrr      sB    
(

=
)
)C uusyy   r   c                     | j                             dd                    t          |                               | j                                         d S rq   )r:   ri   joinrh   r^   rj   )r   r+   s     r   writetemporaryincludesru     sG    HNN=%**VH-=-=">">???$$&&&&&r   c                 x    t          |           }|D ]}|                    |           t          | |           d S N)rr   r%   ru   )r   
additionalr+   rm   s       r   addtemporaryincludesry   	  sE    $T**H  Q4*****r   c                 J   t          |           r| j                            d          sd S |                                 }|j        s|j        s|j        s|j        rd S t          | d          }| j	        }t          j                    }g }t          |           }|D ]W}||v rQ ||          sFt          d          }|                    |t          j        d |           |                    |           Xt          j        | || d          | d         dd           |D ]}|                    |dd           | j                            d           | j                                         t          d          }	| j                            |	t1          |          z             d S )	Nr\   Frb   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matcherrS   mergemodmergeresultrr   r   addfilemergestatemodACTION_REMOVEappendapplyupdatesupdate_fileunlinkr^   rj   r(   r    )
r   ssparsematchrS   mresultdroppedtempincludesfilemessagerD   s
             r   prunetemporaryincludesr     s   d 48??=#A#A Az QW 	 QY $E222K}H"$$GG(..L ! !8KK$5$5EFFGOOD-"=tWMMMNN4   gtDz4:u5   
  G GTeFFFFHOOM"""$$&&&
	 C 	GNN3\***+++++r   c                 p    d |D             }t          j        d|          }t          j        || g          S )zqReturns a matcher that returns true for any of the forced includes
    before testing against the actual matcher.c                     g | ]}d |dfS )s   pathr   rK   )rP   includes     r   rR   z'forceincludematcher.<locals>.<listcomp>8  s    @@@G'3'@@@r   r   )matchmodincludematcherunionmatcher)r   r+   kindpatsr   s       r   forceincludematcherr   5  s@     A@x@@@H,S(;;N .'!:;;;r   c           	          t                     st          j                    S |r|dgk    r% fd j                                        D             }t           |          }d|d                    t          t          j	        |                    fz  } j
                            |          }|r|S g }|D ]_}	 t           |          \  }}	}
|s|	r4t          j         j        dg ||	d          }|                    |           P# t           $ r Y \w xY w|st          j                    }n0t#          |          d	k    r	|d
         }nt          j        |          }|rt'                     }t)          ||          }| j
        |<   |S )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.
    Nc                 Z    g | ]'}|j         k    j                            |          (S rK   rL   rO   s     r   rR   zmatcher.<locals>.<listcomp>J  s@     
 
 
t{"" Nt$$"""r   r{   r]       r   s   relpath)r   excludedefaultr   r   )r   r   alwaysrS   rT   rf   rt   mapr   bytestr_sparsematchercacher_   rH   r   rootr   IOErrorr    r   rr   r   )r   rU   rb   rd   keyresultmatchersrA   r+   r,   r-   r   r   s   `            r   r   r   =  s    d !    
4D6>>
 
 
 
--//
 
 
  +>>>I
i3x/?+F+F!G!GH
HC%))#..F H  	+9$+D+D(Hh 	)8 	)".I$$&   ((( 	 	 	D	  1""	X!		!&x00 ;,T22$V\::$*DS!Ms   :AD
DDc           	         t          |           sdS d |                                D             }t          | |          }|                                rdS t	                      }i }|r6t          | |                                                                g          }	n#t          | |                                g          }	g }
|                                D ]\  }}|\  }}}|                    |            |	|          r|||<   n{|t          j
        k    r|
                    |           |||<   nP|r"|j        s|
                    |           |||<   n,|t          j        k    r|||<   n||v rt          j        ||f||<   |r8|t          j
        k    r(|\  }}}}} |	|          s|
                    |           t          |
          dk    ra| j                            t%          d          t          |
          z             t'          | |
           t)          j                    }d}| d                                         }|
D ]J}||v rD| d         |         }|                    |t          j        |                                df|           K| j                                        5  t)          j        | || d         | d         dd           | j        }|                    t          j        g          D ]\  }}}|                    |d	d	
           	 ddd           n# 1 swxY w Y   t?          |           d         }||z  }|ru|ss|                                }|D ]\} ||          } |	|          }|s,|r*|                    |          }t          j        |dfdf||<   F|r|st          j        g df||<   ]|                     |           dS )zAFilter updates to only lay out files that match the sparse rules.Nc                 6    g | ]}|                                 S rK   )rA   )rP   pctxs     r   rR   z(filterupdatesactions.<locals>.<listcomp>  s     555dtxxzz555r   r   sC   temporarily included %d file(s) in the sparse checkout for merging
s%   temporarily adding to sparse checkoutFr|   r}   Tr      r   )!r   rT   r   r   r!   p1rA   filemapr%   r   ACTION_MERGEr   no_opACTION_FORGETr   r    r(   r   r   ry   r   r   manifestr   
ACTION_GETflagsrS   parentchanger   
getactionsr   rY   
setactions) r   wctxmctxbranchmerger   oldrevsoldsparsematchfilesprunedactionsr   temporaryfilesr   r*   typeargsrD   f1f2famoveanctmresultr   wctxmanifestfctxrS   r   r-   changedprofilesmfoldnews                                    r   filterupdatesactionsr   z  s   d 55dllnn555GT7++N EEEM 2 dTWWYY]]__$566 dTXXZZL11N)) * *f dC		$;t 	K"(M$]///!!$'''"(M$ 	K: -%%d+++&,d#]000"(M$T\\#0#>c"JM$  	*4=#===$(!BBc;r?? *%%b)))
>Q*  .!!	"	
 	
 	
 	T>222 ')):Dz**,," 	 	D|##Dz$'  !,ZZ\\5)	   ]'')) 	M 	M!T
T
"    }H$,$7$7)*% % M M eS $$Tdt$LLLLM	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M  D!!!$H&O  M{ M]]__ 	M 	MD .&&C+d##C M3 M!,EN'd##
  MS M'4'BB&Ld#}%%%%%s   .A-L((L,/L,c                    t                      }|                    |j                   |                    |j                   |                    |j                   t          |           }d}|D ]:} ||          s-| j                            t          d          |z             | };|r!t          j
        t          d                    | j        }| d         }	g }
g }g }|	                                }t          |          }t          j                    }|D ]} ||          } ||          }|r|r|r|r||vr|                    |          }| j                            |          r9|                    |t&          j        |fd           |                    |           |                    |t&          j        |dfd           |
                    |           |r|r|sA|s?||v r;|                    |           ||vr"|                    |t&          j        g d           d}|D ]/}| j                            t          d          |z             | }0|r!t          j
        t          d                    |                                D ]8\  }}||vr/ ||          } ||          }|r|s|                    |           9t          j        | || d         | d         dd           |
D ]}|                    |d	d	
           |D ]}|                    |dd
           |D ]}|                    |d	d	d	           |
||fS )a  Refreshes 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 changesr|   r   sj   cannot change sparseness due to pending changes (delete the files or use --force to bring them back dirty)Nr}   Tr   )r   r   possibly_dirty)r!   r@   r   r   r   r   r(   r'   r   r   r&   rS   r   r   r   r   wvfsr   r   r   ACTION_EXECr   r   r   itemsr   r   )r   
origstatusorigsparsematchforcependingr   abortfrS   rB   r   lookupr   r   r   r   r   r   r   flstates                        r   refreshwdirr     s    eeGNN:&'''NN:#$$$NN:%&&&$--KE  {1~~ 	GLL7881<===IE 
kCDD
 
 	

 }H
t*CEFG	BGGE"$$G L Lod##k$  	L 	L 	L 	LTX5E5E$By%% #m&?"LLLd####-2RK   T""""  	L# 	Ls 	L3 	L48;K;KNN4   7""m&A2sKKK E  Q344t;<<<	 
k5 
 
 	
  ~~'' % %eu}}!/$''C+d##C %3 %t$$$gtDz4:u5   
  E ETdtDDDD G GTeFFFF 
 
Td4 	 	
 	
 	
 	
 '6!!r   c                 8   | |         }t          | |                                          d         }|t          |                                          z  r6|                                 }t          |           }t          | ||d           t          |            dS )z1Perform actions after a working directory commit.r   Tr   N)rH   rA   r!   r   r   r   r   r   )r   rQ   rB   r-   r   r   s         r   aftercommitr   R  s     t*CdCGGII..q1H #ciikk""" C[[]]
!$--D*oTBBBB4     r   c                 p   |                                  5  | j                            d          }t          | j        |d          \  }}}	|                                 }
t          |           }t          | j                  }t          j	        |v r;|r9| j        
                    t          j	                   t          j        |            nFt          j	        |vr8| j                            t          j	                   t          j        |            	 t          | |||           t          | |
||          cddd           S # t           $ r\ | j        |k    r=| j                                         | xj        |z  c_        t          j        |            t          | |||	            w xY w# 1 swxY w Y   dS )z5Update the sparse config and working directory state.r9   r   N)lockr:   r;   r1   r(   r   r   r!   r   r   discardr   writereporequirementsr%   ro   r   	Exceptionrj   )r   r+   r,   r-   r   removingr)   oldincludesoldexcludesoldprofiles	oldstatusoldmatcholdrequiress                r   _updateconfigandrefreshwdirr   c  s    
 " "hy))0;GS)1
 1
-[+ KKMM	4==$+,, *k99h9%%l&EFFF)$////,K??!!,"ABBB)$///		h(;;;tYFFF7" " " " " " " "8  	 	 	 K//!'')))!![0!!-d333k;DDD	9" " " " " " " " " "s%   C;F+$EA&F((F++F/2F/c           	         |                                  5  | j                                        5  | j                            d          }t          | j        |d          \  }}}|s|s	 ddd           ddd           dS t          | t                      t                      ||           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 )zClears include/exclude rules from the sparse config.

    The remaining sparse config only has profiles, if defined. The working
    directory is refreshed, as needed.
    r9   Nr   )	wlockrS   r   r:   r;   r1   r(   r   r!   )r   r   r)   r+   r,   r-   s         r   
clearrulesr     s    
 O Ot}1133 O Ohy))'247C'K'K$(H 	 	O O O O O O O O O O O O O O 	$D#%%NNNNO O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O Os@   C:B9)C,B9-C9B=	=C B=	CCCc                    |                                  5  | j                                        5  | j                            d          }t          | j        |d          \  }}}t          |           \  }}	}
d}|D ]}t          j	        t          j
        |          d          5 }|                                }ddd           n# 1 swxY w Y   t          | j        |d          \  }}}t          |          t          |          z   t          |          z   }|                    ||z
             |                    ||	z
             |                    ||
z
             t          |          t          |          z   t          |          z   |k    rd}dx}x}}d}|r]t          ||
z
            }t          ||z
            }t          ||	z
            }t          t          t          | ||||	                    }t!          | j        ||||g|R   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 )
zImport sparse config rules from files.

    The updated sparse config is written out and the working directory
    is refreshed, as needed.
    r9   Fs   rb)modeNTr   )r   r   r   r   )r   rS   r   r:   r;   r1   r(   rY   r   	posixfile
expandpathreadr    r@   r   r   printchanges)r   optspathsr   r)   r+   r,   r-   	aincludes	aexcludes	aprofileschangedrl   rk   	iincludes	iexcludes	iprofilesoldsizeprofilecountincludecountexcludecountfcountss                         r   importfromfilesr    s    
 (
 (
t}1133 (
 (
hy))'247C'K'K$(H*6t*<*<'	9i  	 	A 2 2???  2ggii                              /:i/ /+Iy) (mmc(mm3c(mmCGOOI	1222OOI	1222OOI	12228}}s8}},s8}}<wFF5666|l 
	x)344Lx)344Lx)344L+(Hhe   G 	GT<|	
FM	
 	
 	
 	
M(
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
 (
sZ   H;A7H#&C	;H#CH#CEH#H;#H'	'H;*H'	+H;;H?H?rK   c
                 
   	                                   5                                   5   j                                        5   j                            d          }
t           j        |
d          \  }}}|r+t                      }t                      }t                      }n-t          |          }t          |          }t          |          } 	fd} ||          } ||          } ||          } ||          } ||          }|	                    |           |	                    |           |	                    |           |
                    |           |
                    |           |
                    |           t          ||z
            t          ||z
            z
  }t          ||z
            t          ||z
            z
  }t          ||z
            t          ||z
            z
  }t          t          t           |||||                    }t           j        ||||g|R   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 )zuPerform a sparse config update.

    The new config is written out and a working directory refresh is performed.
    r9   c                    t          d | D                       r!t          j        t          d                    	r| S j                                        }}g }| D ]u}t          j        |d           \  }}|t          j        v s|6|r|dz   ndt          j
        |||          z   }|                    |           `|                    |           v|S )Nc              3   T   K   | ]#}t           j                            |          V  $d S rw   )ospathisabs)rP   pats     r   	<genexpr>z7updateconfig.<locals>.normalize_pats.<locals>.<genexpr>  s0      66#27==%%666666r   s   paths cannot be absolute   :r   )anyr   r&   r   r   getcwdr   	_patsplitcwdrelativepatternkindsr
   	canonpathr   )
patsr   cwdabspatskindpatkindr  apr   usereporootpathss
           r   normalize_patsz$updateconfig.<locals>.normalize_pats  s    6666666 Bk!$?"@"@AAA  	4;;==#DG , ,$.w==	c8;;;t|)-6$++3(:Lc3; ; B NN2&&&&NN7++++Nr   )r   r   N)r   r   rS   r   r:   r;   r1   r(   r!   difference_updater@   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     
 I
 I
tyy{{ I
 I
DM$>$>$@$@ I
 I
hy)).9GS)/
 /
+
J  	+JJ%%KKZJZJk**K	 	 	 	 	 	* !.)) .))'''77&}55$$V,,,$$V,,,%%n555'"""=)))'""";455+%9
 9
 
 :
233c#7
 7
 
 :
233c#7
 7
 
 '  

 

 	GT<|	
FM	
 	
 	
 	
O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
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
 I
sY   I8I G7I	=I 	II II I8 I$	$I8'I$	(I88I<?I<c                    |                      d|          5 }|                                 |                    | j        dt	          d          |           |                    | j        dt	          d          |           |                    | j        dt	          d          |           |                                s~|                    | j        dt	          d	          |           |                    | j        d
t	          d          |           |                    | j        dt	          d          |           ddd           dS # 1 swxY w Y   dS )z/Print output summarizing sparse config changes.r9   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	&	& $"

J'((		
 	
 	
 	J",--		
 	
 	
 	J",--		
 	
 	
 zz|| 	LL
NA.B,C,CU   LL
,a0F.G.G   LL
$,--	  ?$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   D%E		EE)T)NT)F)FF)rK   rK   FrK   rK   rK   FF)r   r   r   r   r   r   )*r  i18nr   rQ   r    r   r   r   r   r   r	   r   r
   r   r   r   r   utilsr   enabledr   r1   r7   rH   rY   rf   ro   rr   ru   ry   r   r   r   r   r   r   r   r   r  r-  r   rK   r   r   <module>r:     s|   
			            
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       @ @ @B, B, B,L; ; ;9( 9( 9(x1 1 121 1 1 14' ' '*! ! !' ' '
+ + +", ", ",J< < <: : : :zp& p& p&fb" b" b" b"J! ! !$ ?D& & & &RO O O O .
 .
 .
 .
h 

Y
 Y
 Y
 Y
~ 
/ / / / / /r   