
    q&f3k                        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)y)#    N   )_)hex)	errormatchmerge
mergestatepathutilpycompatrequirementsscmutilutil)hashutilFc                 V    t        | dd      ry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*
 **d.?.???    c                 .   t        j                  dt        |      |      5  t               }t               }t               }d}d}|j	                  d      D ]$  }|j                         }|r|j                  d      r(|j                  d      r(|dd j                         }|sO|j                  |       a|dk(  r/|r(||k7  r#t        j                  t        d	      d
|iz        d}|}|dk(  rd}|}|s|/t        j                  t        d      ||dz  t        d            |j                         j                  d      r"| j                  t        d      ||dz         |j                  |       ' |||fcddd       S # 1 sw Y   yxY w)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    
5s3x
 ;, 555IIe$ 0	"D::<D4??40.ABx~~'LL&%7h#6++. %f-	.  #"%""?++1 '-t<	=
 9
 
 ::<**40GGK '-t<	= D!a0	"d 8+w;, ;, ;,s   BF$AF7B
FFc                 D    | j                  ||      j                         S )z1Resolve the raw content of a sparse profile file.)changeid)filectxdata)r   profiler3   s      r   readprofiler7   q   s      <<(<388::r   c                    t        |       st               t               t               fS | j                  j                  d      }|st               t               t               fS |t	        j
                  t        d            t        | j                  |d      \  }}}| |   }|rt               }|r|j                         }||v r|j                  |       	 t        | ||      }t        | j                  |d      \  }
}}|j!                  |
       |j!                  |       |j!                  |       |r|}|r|j                  d       |||fS # t        j                  $ r^ d||fz  }	| j                  j                  dd      r| j                  j                  |	       n| j                  j                  |	       Y w xY w)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   r1   r(   popr%   r7   ManifestLookupError
configboolr'   debugupdate)r   revr)   r+   r,   r-   ctxvisitedr6   msg	pincludes	pexcludessubprofss                r   patternsforrevrH   x   s    duceSU""
((

9
%CuceSU""
{kkDE
 	
 $/twwY#G Hh
s)C%llnG'!KK !$5 .9i.*Iy( OOI&OOI&OOH%5 8 WXx''1 ,, 
14;S>B 
 77%%i1BCGGLL%GGMM#&
s   E A-G Gc                 <   | j                   j                         D cg c],  }|| j                  k7  r| j                  j	                  |      . }}t               }t               }t               }|D ]!  }t        | |      \  }}}	||z  }||z  }||	z  }# |||fS c c}w )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	changelogrA   r!   rH   )
r   noderevsallincludesallexcludesallprofilesrA   r+   r,   r-   s
             r   activeconfigrS      s     MM))+4;; 	4 D  %K%K%K  '5dC'@$(Hxxx	  [00!s   1Bc                    | j                   }|j                  d      }|r|j                  d      }nd}||r|t        t        j                  | j
                  j                  d            j                               }||d<   |rL| j
                  j                  d      }t        t        j                  |      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   0r9   
   tempsparse   %s %s)_sparsesignaturecachegetr   r   sha1r:   r;   digest)r   includetempcache	signaturetempsignaturer)   s         r   configsignaturer`      s    
 &&E		,'I		"23[]-Bdhh&6&6y&ABIIKL	'l((""=1Cc 2 9 9 ;<M&3E"#y-000r   c                    | j                  dd      5 }t        |      D ]  }|j                  d|z          |rC|j                  d       t        |      D ]$  }|j                  |       |j                  d       & |rC|j                  d       t        |      D ]$  }|j                  |       |j                  d       & ddd       | j                  j	                          y# 1 sw Y   $xY w)z:Write the sparse config file given a sparse configuration.r9   s   wbs   %%include %s
s
   [include]
r   s
   [exclude]
N)r:   sortedwriterX   clear)r   r+   r,   r-   fhpies           r   writeconfigri      s    	)U	#  r! 	,AHH&*+	, HH^$H%    HH^$H%      	$$&!   s   B/C%%C.c                     | j                   j                  d      }|s
t               S t        |j                  d            S NrV   r   )r:   r;   r!   r"   )r   r)   s     r   readtemporaryincludesrl      s4    
((

=
)Cusyy  r   c                     | j                   j                  ddj                  t        |                   | j                  j                          y rk   )r:   rc   joinrb   rX   rd   )r   r+   s     r   writetemporaryincludesro     s4    HHNN=%**VH-=">?$$&r   c                 b    t        |       }|D ]  }|j                  |        t        | |       y N)rl   r%   ro   )r   
additionalr+   rg   s       r   addtemporaryincludesrs   	  s0    $T*H Q4*r   c                 4   t        |       r| j                  j                  d      sy | j                         }|j                  s$|j
                  s|j                  s|j                  ry t        | d      }| j                  }t        j                         }g }t        |       }|D ]N  }||v s ||      rt        d      }|j                  |t        j                   d |       |j#                  |       P t        j$                  | || d    | d   dd       |D ]  }|j'                  |dd        | j                  j)                  d       | j*                  j-                          t        d      }	| j.                  j                  |	t1        |      z         y )	NrV   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matcherrJ   mergemodmergeresultrl   r   addfilemergestatemodACTION_REMOVEappendapplyupdatesupdate_fileunlinkrX   rd   r(   r    )
r   ssparsematchrJ   mresultdroppedtempincludesfilemessagerD   s
             r   prunetemporaryincludesr     s^   d488??=#AAzzQWW		QYY$E2K}}H""$GG(.L !8K$5EFGOOD-"="=tWMNN4 	! gtDz4:u5
  GTeFG 	HHOOM"$$&
	C 	GGNN3\**+r   c                     |D cg c]  }d|df	 }}t        j                  d|      }t        j                  || g      S c c}w )zqReturns 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   5  sM     8@@G'3'@H@,,S(;N  .'!:;; As   A c           	      F   t        |       st        j                         S |r|dgk(  rO| j                  j	                         D cg c],  }|| j
                  k7  r| j                  j                  |      . }}t        | |      }d|dj                  t        t        j                  |            fz  }| j                  j                  |      }|r|S g }|D ]M  }	 t        | |      \  }	}
}|	s|
r6t        j                   | j"                  dg |	|
d      }|j%                  |       O |st        j                         }n)t)        |      dk(  r|d	   }nt        j*                  |      }|rt-        |       }t/        ||      }|| j                  |<   |S c c}w # t&        $ r Y w xY w)
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.
    Nru   rW       r   s   relpath)r   excludedefaultr   r   )r   r   alwaysrJ   rK   rL   rM   rA   r`   rn   mapr   bytestr_sparsematchercacherY   rH   r   rootr   IOErrorr    r   rl   r   )r   rO   r\   rN   r^   keyresultmatchersrA   r+   r,   r-   r   r   s                 r   r   r   =  s    d  4D6> --/
t{{" NNt$
 
  +>I
i3x/?/?+F!GH
HC%%))#.FH 	+9$+D(Hh8"..II$$& (" "	X!	!&&x0,T2$V\:$*DS!M[
:  		s   1FA
F	F F c           	      ,   t        |       sy|j                         D cg c]  }|j                          }}t        | |      }|j	                         ryt               }i }	|r*t        | |j                         j                         g      }
nt        | |j                         g      }
g }|j                         D ]  \  }}|\  }}}|j                  |        |
|      r||	|<   n|t        j                  k(  r|j                  |       ||	|<   nX|r#|j                  sJ|j                  |       ||	|<   n3|t        j                  k(  r||	|<   n||v rt        j                  ||f|	|<   |s|t        j                  k(  s|\  }}}}} |
|      r|j                  |        t        |      dkD  r:| j                   j#                  t%        d      t        |      z         t'        | |       t)        j*                         }d}| d   j-                         }|D ]A  }||v s| d   |   }|j/                  |t        j0                  |j3                         df|       C | j4                  j7                  |       5  t)        j8                  | || d   | d   dd       | j4                  }|j;                  t        j0                  g      D ]  \  }}}|j=                  |dd	        	 ddd       t?        |       d
   }||z  }|rs|sq|j-                         }|D ]\  } ||      } |
|      } |s,| r*|j3                  |      }t        j0                  |dfdf|	|<   A|sD| rGt        j                  g df|	|<   ^ |jA                  |	       yc c}w # 1 sw Y   xY w)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 checkoutFrv   rw   Try      r   )!r   rK   rA   r   r   r!   p1filemapr%   r   ACTION_MERGEr   no_opACTION_FORGETr   r    r(   r}   r   rs   r   r   manifestr   
ACTION_GETflagsrJ   changing_parentsr   
getactionsr   rS   
setactions)!r   wctxmctxbranchmerger   pctxoldrevsoldsparsematchfilesprunedactionsr   temporaryfilesr   r*   typeargsrD   f1f2famoveanctmresultr   wctxmanifestfctxrJ   r   r-   changedprofilesmfoldnews!                                    r   filterupdatesactionsr   z  s   d&*lln5dtxxz5G5T7+NEEM dTWWY]]_$56 dTXXZL1N) *f dC		$t"(M$]///!!$'"(M$::%%d+&,d#]000"(M$T\#0#>#>c"JM$ 4=#=#==$(!BBcr?%%b)5*8 >Q* .!	"	
 	T>2 ''):Dz**," 	D|#Dz$'  !,,ZZ\5)		 ]]++D1 	M!!T
T
" }}H$,$7$7))*% M eS $$Tdt$LM	M  D!!$H&O {]]_ 	MD &Cd#C3!,,EN'd#
 S'4'B'BB&Ld#	M }%W 6N	M 	Ms   N7A+N

Nc                 2   t               }|j                  |j                         |j                  |j                         |j                  |j                         t        |       }d}|D ]5  } ||      r| j                  j                  t        d      |z         | }7 |rt        j                  t        d            | j                  }| d   }	g }
g }g }|	j                         }t        |      }t        j                         }|D ]  } ||      } ||      }|r|r|r|r||vr|j                  |      }| j                   j#                  |      r5|j%                  |t&        j(                  |fd       |j+                  |       |j%                  |t&        j,                  |dfd       |
j+                  |       |r|r|r|r||v s|j+                  |       ||vs|j%                  |t&        j.                  g d        d}|D ],  }| j                  j                  t        d      |z         | }. |rt        j                  t        d            |j1                         D ]1  \  }}||vs ||      } ||      }|s|r!|j+                  |       3 t        j2                  | || d   | d   dd       |
D ]  }|j5                  |d	d	
        |D ]  }|j5                  |dd
        |D ]  }|j5                  |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 changesrv   r   sj   cannot change sparseness due to pending changes (delete the files or use --force to bring them back dirty)Nrw   Try   )rz   r{   possibly_dirty)r!   r@   r~   r   r   r   r(   r'   r   r   r&   rJ   r   r   r   r   wvfsr|   r   r   ACTION_EXECr   r   r   itemsr   r   )r   
origstatusorigsparsematchforcependingr   abortfrJ   rB   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 Ld#$ TX5E$Byy%m&?&?"Ld#-22RK T" #s348;KNN4 7"m&A&A2sK)L. E Q34t;<	 kk5
 	
  ~~' %eu}!$'Cd#C3t$% gtDz4:u5
  ETdtDE  GTeFG  
Td4 	 	

 '6!!r   c                     | |   }t        | |j                               d   }|t        |j                               z  r*| j	                         }t        |       }t        | ||d       t        |        y)z1Perform actions after a working directory commit.r   Tr   N)rH   rA   r!   r   r}   r   r   r   )r   rN   rB   r-   r   r   s         r   aftercommitr   R  sc     t*CdCGGI.q1H #ciik""[[]
!$-D*oTB4 r   c                 z   | j                         5  | j                  j                  d      }t        | j                  |d      \  }}}	| j                         }
t        |       }t        | j                        }t        j                  |v rA|r?| j                  j                  t        j                         t        j                  |        nPt        j                  |vr>| j                  j                  t        j                         t        j                  |        	 t        | |||       t        | |
||      cddd       S # t         $ rc | j                  |k7  rD| j                  j#                          | xj                  |z  c_        t        j                  |        t        | |||	        w xY w# 1 sw Y   yxY w)z5Update the sparse config and working directory state.r9   r   N)lockr:   r;   r1   r(   r}   r   r!   r   r   discardr   writereporequirementsr%   ri   r   	Exceptionrd   )r   r+   r,   r-   r   removingr)   oldincludesoldexcludesoldprofiles	oldstatusoldmatcholdrequiress                r   _updateconfigandrefreshwdirr   c  so    
 "hhy)0;GGS)1
-[+ KKM	4=$++, **k9h%%l&E&EF))$/,,K?!!,"A"AB))$/		h(;tYF7" "8  	  K/!!'')!![0!--d3k;D	9" "s   D
F1EA,F..F11F:c           	         | j                         5  | j                  j                  |       5  | j                  j	                  d      }t        | j                  |d      \  }}}|s|s	 ddd       ddd       yt        | t               t               ||       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)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   )	wlockrJ   r   r:   r;   r1   r(   r   r!   )r   r   r)   r+   r,   r-   s         r   
clearrulesr     s     
 Ot}}55d; Ohhy)'2477C'K$(HO O O 	$D#%NO O O O O Os.   B7<B+)B7: B+B7+B4	0B77C c                    | j                         5  | j                  j                  |       5  | j                  j	                  d      }t        | j                  |d      \  }}}t        |       \  }}	}
d}|D ]  }t        j                  t        j                  |      d      5 }|j                         }ddd       t        | j                  |d      \  }}}t        |      t        |      z   t        |      z   }|j                  ||z
         |j                  ||	z
         |j                  ||
z
         t        |      t        |      z   t        |      z   |kD  sd} dx}x}}d}|rHt        ||
z
        }t        ||z
        }t        ||	z
        }t        t        t        | ||||	            }t!        | j                  ||||g|  ddd       ddd       y# 1 sw Y   ,xY w# 1 sw Y   xY w# 1 sw Y   yxY w)
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   rJ   r   r:   r;   r1   r(   rS   r   	posixfile
expandpathreadr    r@   r   r   printchanges)r   optspathsr   r)   r+   r,   r-   	aincludes	aexcludes	aprofileschangedrf   re   	iincludes	iexcludes	iprofilesoldsizeprofilecountincludecountexcludecountfcountss                         r   importfromfilesr    s    
 (
t}}55d; (
hhy)'2477C'K$(H*6t*<'	9i  	A 2?  2ggi  /:i/+Iy) (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+(HheG 	GGT<|	
FM	
M(
 (
 (
   (
 (
 (
 (
sC   G8A7G,$G	5B(G,A0G,G8G)$G,,G5	1G88Hc
                 4   	  j                         5   j                         5   j                  j                         5   j                  j                  d      }
t         j                  |
d      \  }}}|rt               }t               }t               }n!t        |      }t        |      }t        |      } 	fd} ||      } ||      } ||      } ||      } ||      }|j                  |       |j                  |       |j                  |       |j                  |       |j                  |       |j                  |       t        ||z
        t        ||z
        z
  }t        ||z
        t        ||z
        z
  }t        ||z
        t        ||z
        z
  }t        t        t         |||||            }t         j                  ||||g|  ddd       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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                  j                         }}g }| D ]s  }t        j                  |d       \  }}|t        j                  v s|3|r|dz   ndt        j                  |||      z   }|j                  |       c|j                  |       u |S )Nc              3   Z   K   | ]#  }t         j                  j                  |       % y wrq   )ospathisabs).0pats     r   	<genexpr>z7updateconfig.<locals>.normalize_pats.<locals>.<genexpr>  s     6#277==%6s   )+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kk!$?"@AA 		4;;=#DG ,$..w=	c8;;;t|)-$+3(:L:Lc3; B NN2&NN7+, Nr   )r   r   N)r   r   rJ   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
tyy{ I
DMM$B$B4$H I
hhy).9GGS)/
+
J 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I
 I
 I
 I
 I
 I
 I
 I
 I
s;   HH FG6H%H6G?;HH	HHc                 f   | j                  d|      5 }|j                          |j                  | j                  dt	        d      |       |j                  | j                  dt	        d      |       |j                  | j                  dt	        d      |       |j                         su|j                  | j                  dt	        d	      |       |j                  | j                  d
t	        d      |       |j                  | j                  dt	        d      |       ddd       y# 1 sw Y   yxY w)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	& $"

JJ'(		
 	JJ",-		
 	JJ",-		
 zz|LL

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

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

$,-	?$ $ $s   DD''D0)T)NT)F)FF) r.  Fr.  r.  r.  FF)r   r   r   r   r   r   )*r  i18nr   rN   r    r   r   r   r   r   r	   r   r
   r   r   r   r   utilsr   enabledr   r1   r7   rH   rS   r`   ri   rl   ro   rs   r   r   r   r   r   r   r   r   r  r%  r   r.  r   r   <module>r3     s    
  
 
 
  @B,L;9(x1214'*!'
+",J<:zp&fb"J!$ ?D&RO .
h 

Y
~ 
/r   