
    6h                    R   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
JrJrJrJrJ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J r J!r!J"r"  SSK#J$r$  \RJ                  S\RL                  S	\RN                  S
0r(\RJ                  S\RL                  S\RN                  S0r)      SFS jr*SGS jr+SHSIS jjr,SJS jr-SKS jr. SL   SMS jjr/      SNS jr0SOS jr1SPS jr2 SQ   SRS jjr3SSS jr4STS jr5SJS jr6 " S S5      r7S r8Sr9Sr:Sr;SUS jr<S  r= " S! S"5      r>S# r?S$ r@SVS% jrAS& rBS' rCS( rD " S) S*\ R                  5      rF " S+ S,\ R                  5      rHSWS- jrISWS. jrJ    SXS/ jrK\R                  S0 5       rM " S1 S25      rNSYS3 jrO\\P   rQ\\P\\R   \Q4   rS " S4 S55      rT " S6 S75      rU " S8 S95      rV " S: S;5      rW " S< S=\W5      rX        SZS> jrY\WS4             S[S? jjrZS\S@ jr[SJSA jr\        S]SB jr]S^SC jr^SKSD jr_SJSE jr`g)_    )annotationsN)CallableIterableIteratorOptionalSetTupleType   )_)
repository)	bookmarksbundle2	cacheutilerror
narrowspecphasespycompatrequirementsscmutilstoretransactionutil)nodemap      i   i  @l        c                d    [        U 5      nU[        R                  -    UR                  U5        U$ )zdetermine the final set of requirement for a new stream clone

this method combine the "default" requirements that a new repository would
use with the constaint we get from the stream clone content. We keep local
configuration choice when possible.
)setrequirementsmodSTREAM_IGNORABLE_REQUIREMENTSupdate)default_requirementsstreamed_requirementsr   s      7/usr/lib/python3/dist-packages/mercurial/streamclone.pynew_stream_clone_requirementsr%   C   s2     +,L?@@@-.    c                @    U R                   [        R                  -
  nU$ )zthe set of requirement the new clone will have to support

This is used for advertising the stream options and to generate the actual
stream content.)r   r   r    )reporequiredformatss     r$   r#   r#   S   s%     	OIII  r&   c                \   U R                   nU R                  nU R                  nUc  UR                  S5      nU(       d  g[	        U5      (       a  gU R
                  (       a  gSnU R                  (       ab  [        R                  " USS9n[        UR                  S/ 5      5      n[        U R                  R                  S/ 5      5      n[        Xx-  5      nU(       a  U(       d  gU(       a  U(       d  g[        5       n	UR                  S5      (       a#  U	R                  [        R                  5        SU	4$ UR                  S5      n
U
(       d/  U R                   R                   R#                  [%        S5      5        g[        U
R'                  S	5      5      n
XR(                  -
  nU(       ax  U R                   R                   R#                  [%        S
5      SR+                  [-        U5      5      -  5        U R                   R                   R#                  [%        S5      5        gU
n	SU	4$ )a  Whether it is possible to perform a streaming clone as part of pull.

``bundle2`` will cause the function to consider stream clone through
bundle2 and only through bundle2.

Returns a tuple of (supported, requirements). ``supported`` is True if
streaming clone is supported and False otherwise. ``requirements`` is
a set of repo requirements from the remote, or ``None`` if stream clone
isn't supported.
s   stream-preferred)FNFs   client)roles   streams
   streamreqss=   warning: stream clone requested but server has them disabled
   ,sG   warning: stream clone requested but client is missing requirements: %s
   , sQ   (see https://www.mercurial-scm.org/wiki/MissingRequirement for more information)
T)r(   remotestreamclonerequestedcapablelenheadscanusebundle2
bundle2modgetrepocapsr   getremotebundle2capsbooladdr   REVLOGV1_REQUIREMENTuiwarnr   split	supportedjoinsorted)pullopr   r(   r.   streamrequestedbundle2supported
local_capslocal_supportedremote_supportedr   
streamreqsmissingreqss               r$   canperformstreamclonerI   ^   s    ;;D]]F 11O  ..)<= 4yy ||++DyA
jnnY;<v77;;IrJK BC 	) 5L~~i  ==>B ? ^^M2
KKNN" ))$/0
 >>1KKNN* **VK01	2 KKNN/ !r&   c                ,   SSK Jn  [        U 5      u  p#U(       d  gU R                  nU R                  nSnUR                  S5      (       a9  UR                  5        nUR                  S0 5      R                  5       nSSS5        UR                  R                  [        S5      5        UR                  5        nUR                  S0 5      R                  5       nSSS5        WR                  5       n	 [        U	5      n
U
S:X  a  [        R"                  " [        S5      5      eU
S	:X  a  [        R"                  " [        S
5      5      eU
S:w  a  [        R"                  " [        S5      5      eUR                  5       n	 [%        [        U	R'                  SS5      5      u  pUR+                  5          [-        XHX5        [/        UR0                  U5      Ul        UR3                  UR                  UR0                  UR4                  5      UR6                  l        [:        R<                  " U5        [>        R@                  " U5        U(       a  URB                  RE                  XF5        URG                  5         SSS5        g! , (       d  f       GN	= f! , (       d  f       GN= f! [         a!    [        R                   " [        S5      U	5      ef = f! [        [(        4 a!    [        R                   " [        S5      U	5      ef = f! , (       d  f       g= f)zPossibly perform a legacy stream clone operation.

Legacy stream clones are performed as part of pull but before all other
operations.

A legacy stream clone will not be performed if a bundle2 stream clone is
supported.
r   	localrepoNs	   branchmaps   streaming all changes
s
   stream_out'   unexpected response from remote server:s   operation forbidden by server   s$   locking the remote repository failedr   s%   the server sent an unknown error code    )$ rL   rI   r(   r.   r0   commandexecutorcallcommandresultr;   statusr   readlineint
ValueErrorr   ResponseErrorAbortmapr=   	TypeErrorlock	consumev1r%   r   resolvestorevfsoptionsfeaturessvfsoptionsr   writereporequirementsr   post_stream_cleanup_branchcachesreplace
invalidate)rA   rL   r>   r   r(   r.   
rbranchmapefplresp	filecount	bytecounts                r$   maybeperformlegacystreamclonern      sk    3F;I;;D]]F J~~l####%|R8??AJ & 	GGNN1/01				!Q]]="-446 
" 	A
1v
 qykk!<=>>	kk!CDEE	kk!DEFF
A
"3a(89	 
$I19
 &<<GGT&&
		 	%%d+##D)&&t8 
E &%
 
"	!  
!!891
 	

 	" 
!!891
 	


 
s=   !I?9!J3J# >"K 0CL?
J
J #+K1L
Lc                    [         R                  U R                  ;  a  gU R                  R	                  SSSS9(       d  g[
        R                  " U 5      nU(       a  U R                  R	                  SS5      $ g)z5Whether streaming clones are allowed from the server.Fs   servers   uncompressedT)	untrusteds   uncompressedallowsecret)r   REPO_FEATURE_STREAM_CLONEr_   r;   
configboolr   	hassecret)r(   secrets     r$   allowservergenerationru     sc    ++4==@77iDI d#Fww!!)-GHHr&   c                6    U R                   R                  XUS9$ )Nphaseobsolescence)r   walk)r(   matcherrx   ry   s       r$   _walkstreamfilesr|     s     ::??7l?KKr&   c                    [         R                  " 5       U-
  nUS::  a  Sn[        S5      nUU[         R                  " U5      U[         R                  " X4-  5      4-  nU R                  R                  U5        g)z@common utility to report time it took to apply the stream bundler   gMbP?s5   stream-cloned %d files / %s in %.1f seconds (%s/sec)
N)r   timerr   rm   r;   rT   )r(   
start_time
file_count
byte_countelapsedms         r$   _report_transferredr     sm     jjlZ'G!|	
CDAz"z+,	
 A 	GGNN1r&   c                  ^ ^^^ / mSnT R                  5          T R                  R                  S5        [        T 5        [	        T 5       Hi  nUR                  5        HR  nUR                  T R                  R                  5      nU(       d  M1  TR                  UR                  U45        X-  nMT     Mk     [        T 5        SSS5        [        T 5        T R                  R                  S[        T5      U4-  5        T R                  mT R                  R                  mSUUU U4S jjn[        T5      X" 5       4$ ! , (       d  f       N= f)a  Emit content for version 1 of a streaming clone.

This returns a 3-tuple of (file count, byte size, data iterator).

The data iterator consists of N entries for each file being transferred.
Each file entry starts as a line with the file name and integer size
delimited by a null byte.

The raw file data follows. Following the raw file data is the next file
entry, or EOF.

When used on the wire protocol, an additional line indicating protocol
success will be prepended to the stream. This function is not responsible
for adding it.

This function will obtain a repository lock to ensure a consistent view of
the store is captured. It therefore may raise LockError.
r   	   scanning
Ns   %d files, %d bytes to transfer
c               3  `  >#    T H  u  pT(       a  TR                   R                  SX4-  5        S[        R                  " U 5      U4-  v   T" U SSS9 nUS::  a  UR	                  U5      v   O[
        R                  " X!S9 S h  vN   S S S 5        M     g  N! , (       d  f       M  = f7f)Ns   sending %s (%d bytes)
s   %s %d
s   rbF)	auditpathi   limit)r;   debugr   	encodedirreadr   filechunkiter)namesizeri   	debugflagentriesr(   r`   s      r$   emitrevlogdata"generatev1.<locals>.emitrevlogdataY  s     !JD8D<GH!6 === dEU3r5=''$-'#11"AAA	 43 " B	 43s0   AB.2BB	BB.B
B+	&B.returnzIterator[bytes])r\   r;   r   _test_sync_point_walk_1_2r|   files	file_sizer   vfsappendunencoded_path_test_sync_point_walk_3_test_sync_point_walk_4r1   r`   r   )	r(   total_bytesentryfr   r   r   r   r`   s	   `     @@@r$   
generatev1r   0  s   & GK	m$!$'%d+E[[]KK

7	9NNA$4$4i#@A,K	 # , 	 % 
 D!GGMM+s7|[.II 99D!!IB B w<n&666C 
s   A2D>4D>>
Ec              #     #    [        U 5      (       d  Sv   g [        U 5      u  pnSv   SX4-  v   U Sh  vN   g! [        R                   a    Sv    gf = f N#7f)a  Emit content for version 1 of streaming clone suitable for the wire.

This is the data output from ``generatev1()`` with 2 header lines. The
first line indicates overall success. The 2nd contains the file count and
byte size of payload.

The success line contains "0" for success, "1" for stream generation not
allowed, and "2" for error locking the repository (possibly indicating
a permissions error for the server process).
s   1
Ns   2
s   0
s   %d %d
)ru   r   r   	LockError)r(   rl   rm   its       r$   generatev1wireprotor   j  sl      !&&#-d#3 	b L
	-
--MM ??  s/   A> AAAAAAAc                   ^ ^^ TS:w  a  [        S5      e[        T 5      nSR                  [        U5      5      mSUU U4S jjnX#" 5       4$ )a  Emit content for version 1 of a stream clone bundle.

The first 4 bytes of the output ("HGS1") denote this as stream clone
bundle version 1.

The next 2 bytes indicate the compression type. Only "UN" is currently
supported.

The next 16 bytes are two 64-bit big endian unsigned integers indicating
file count and byte count, respectively.

The next 2 bytes is a 16-bit big endian unsigned short declaring the length
of the requirements string, including a trailing  . The following N bytes
are the requirements string, which is ASCII containing a comma-delimited
list of repo requirements that are needed to support the data.

The remaining content is the output of ``generatev1()`` (which may be
compressed in the future).

Returns a tuple of (requirements, data generator).
   UNz.we do not support the compression argument yetr,   c               3  
  >#    Sv   Tv   [        T5      u  pnTR                  R                  [        S5      X4-  5        [        R
                  " SX5      v   [        R
                  " S[        T5      S-   5      v   TS-   v   TS:X  d   eTR                  R                  [        S5      U[        S	5      S
9nUR                  S5        U H  nUR                  [        U5      S9  Uv   M!     UR                  5         g 7f)Ns   HGS1s   writing %d bytes for %d files
   >QQ   >Hr       r      bundle   bytestotalunitr   step)r   r;   rT   r   structpackr1   makeprogressr!   	incrementcomplete)rl   rm   r   progresschunkcompressionr(   requiress        r$   gengeneratebundlev1.<locals>.gen  s     #-d#3 	b01Y4JJ	
 kk&)77kk%X!233 e###77''iL	( ( 
 	ECJ/K  	s   D Dr   )rW   r#   r?   r@   )r(   r   r   r   r   s   ``  @r$   generatebundlev1r     sO    0 eIJJ(.Lyy-.H 6 r&   c                   U R                  5          U R                  R                  [        S5      U[        R
                  " U5      4-  5        U R                  R                  [        S5      U[        S5      S9nUR                  S5        [        R                  " 5       nSnU R                  S5         U R                  R                  U R                  US9   [        U5       GHe  n[        US5      (       a  UR                  5       nOW/ n	U	(       a	  U	S   S	:X  d4  U	R                  UR!                  S
5      5        U	(       d  M)  U	S   S	:X  d  M4  SR#                  U	5      n UR%                  SS
5      u  p['        U5      nU R                  R0                  (       a4  U R                  R3                  SU
[        R
                  " U5      4-  5        [4        R6                  " U
5      nU R                  USSS9 nUS
-  n[        R8                  " XS9 H,  nUR;                  [=        U5      S9  UR?                  U5        M.     SSS5        GMh     SSS5        U RA                  SS9  SSS5        URC                  5         [E        XXc5        SSS5        g! [(        [*        4 a!    [,        R.                  " [        S5      U5      ef = f! , (       d  f       GM  = f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)zApply the contents from version 1 of a streaming clone file handle.

This takes the output from "stream_out" and applies it to the specified
repository.

Like "stream_out," the status line added by the wire protocol is not
handled by this function.
!   %d files to transfer, %s of data
   cloner   r   r   )expectedcountrU      
r   r&   r   rM   s   adding %s (%s)
   wT)backgroundcloser   r   Nclearfilecache)#r\   r;   rT   r   r   rm   r   r!   r~   r   r`   backgroundclosingrangehasattrrU   r   r   r?   r=   rV   rW   r[   r   rX   r   r   r   	decodedirr   r   r1   writerf   r   r   )r(   ri   rl   rm   r   starttotal_file_countirj   l_bufr   r   pathofpr   s                  r$   r]   r]     s|    
34$..345	
 77''hKyq{ ( 
 	

  h',,TWWI,Ny)Ar:..KKM
 !##(U2Y%-?!LL4 $)5U2Y%-?HHUO%&WWUA%6
"4y
 ww((/49M2NN !??40D4tD(A-(%)%7%7%GE$..CJ.?IIe, &H ED3 * OD OO4O0G (J 	D)9EA 
V '	2 #11HI1  ED5 ON ('5 
s{   B$K=5%K,A+K	KK$JA6K9A
KKK,'$K=1KK
K	K
K)%K,,
K:	6K==
Lc                   U R                  S5      nUS:w  a"  [        R                  " [        S5      U-  5      e[        R
                  " SU R                  S5      5      u  p#[        R
                  " SU R                  S5      5      S   nU R                  U5      nUR                  S5      (       d  [        R                  " [        S	5      5      e[        UR                  S5      R                  S
5      5      nX#U4$ )NrN   r   s<   only uncompressed stream clone bundles are supported; got %sr      r   r   r   s@   malformed stream clone bundle: requirements not properly encodedr,   )
r   r   rY   r   r   unpackendswithr   rstripr=   )ri   r   rl   rm   requireslenr   r   s          r$   readbundle1headerr     s    ''!*Kekk% 	
 	
 "===I--rwwqz215Kww{#HU##kk5
 	
 xu-33D9:L--r&   c                `   [        U 5      (       a  [        R                  " [        S5      5      e[	        U5      u  p#nX@R
                  -
  nU(       a:  [        R                  " [        S5      SR                  [        U5      5      -  5      e[        XX#5        [        R                  " U 5        g)zApply the content from a stream clone bundle version 1.

We assume the 4 byte header has been read and validated and the file handle
is at the 2 byte compression identifier.
s2   cannot apply stream clone bundle on non-empty repo4   unable to apply stream clone: unsupported format: %sr-   N)r1   r   rY   r   r   r>   r?   r@   r]   r   rc   )r(   ri   rl   rm   r   rH   s         r$   applybundlev1r   )  s     4yykkCD
 	
 *;2)>&I,/KkkEFjj,-.
 	

 d	-%r&   c                  ,    \ rS rSrSrSS jrSS jrSrg)streamcloneapplieri@  zClass to manage applying streaming clone bundles.

We need to wrap ``applybundlev1()`` in a dedicated type to enable bundle
readers to perform bundle type-specific functionality.
c                    Xl         g N_fh)selffhs     r$   __init__streamcloneapplier.__init__G  s    r&   c                ,    [        XR                  5      $ r   )r   r   )r   r(   s     r$   applystreamcloneapplier.applyJ  s    T88,,r&   r   Nr   None)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r&   r$   r   r   @  s    -r&   r      s   cc                V    / nU R                  5       (       d  UR                  S5        U$ )z!list snapshot file from the stores
   phaseroots)
publishingr   )r(   fnamess     r$   _walkstreamfullstorefilesr   X  s%    F??m$Mr&   c                Z    U u  p4pVU[         :w  a  U $ X4XQ" X#   R                  U5      5      4$ )z actually copy the snapshot files)	_filefullr?   )r   copyvfsmapsrcr   ftypedatas          r$   _filterfullr  `  s8    "Cu	ud6;#3#3D#9:;;r&   c                      \ rS rSrSr\R                  (       a  SOSrSS jrS r	S r
SS jrSS	 jrSS
 jrSS jrSS jr\R"                  S 5       rSrg)VolatileManagerih  a  Manage temporary backups of volatile files during stream clone.

This class will keep open file handles for the volatile files, writing the
smaller ones on disk if the number of open file handles grow too much.

This should be used as a Python context, the file handles and copies will
be discarded when exiting the context.

The preservation can be done by calling the object on the real path
(encoded full path).

Valid filehandles for any file should be retrieved by calling `open(path)`.
rN   d   c                <    SU l         S U l        S U l        S U l        g Nr   )_counter_volatile_fps_copies_dst_dirr   s    r$   r   VolatileManager.__init__}  s    !r&   c                |    U R                   S:X  a  U R                  b   e0 U l        U =R                   S-  sl         U $ Nr   r   )r  r	  r  s    r$   	__enter__VolatileManager.__enter__  s;    ==A%%---!#Dr&   c                   U =R                   S-  sl         U R                   S:X  a  U R                  R                  5        H  u  p4UR                  5         M     SU l        U R                  bW  U R                  R                  5        H  n[
        R                  " U5        M     [
        R                  " U R                  5        SU l        SU l        U R                  b   eU R                  b   eU R                  b   egg)zdiscard all backupsr   r   N)	r  r	  valuescloser
  r   	tryunlinktryrmdirr  )r   argskwars_sizeri   tmps         r$   __exit__VolatileManager.__exit__  s    ==A!//668	
 9!%D||'<<..0CNN3' 1dmm,DL DM%%---<<'''==((( r&   c                    SU R                   :  d   eU R                  b   eU R                  b   e0 U l        [        R                  " SS9U l        g)zpprepare a temporary directory to save volatile files

This will be used as backup if we have too many files openr   Ns	   hg-clone-)prefix)r  r
  r  r   mkdtempr  s    r$   _init_tmp_copies VolatileManager._init_tmp_copies  sO     4==   ||###}}$$$ ((=r&   c                l   U R                   c  U R                  5         U R                  S-  n[        U R                  R                  5       5      SU  H  u  nu  p4[        R                  R                  U5      n[        R                  " XPR                  S9u  pgXpR                   U'   [        R                  " U5        [        US5       nUR                  S5        UR                  UR!                  5       5        SSS5        U R                  U	 UR                  5         M     g! , (       d  f       N0= f)z4move some of the open files to tempory files on diskNrN   )r  dirwbr   )r
  r   MAX_OPENr@   r	  itemsosr   basenamer   mkstempr  r  openseekr   r   )	r   flush_countr   r   ri   r  fddstbcks	            r$   _flush_some_on_disk#VolatileManager._flush_some_on_disk  s    <<!!#mmq(%d&8&8&>&>&@A,;OOC$WW%%c*F&&f--HGB #LLHHRL c4C
		"'')$ ! ""3'HHJ  P !s   
1D%%
D3	c                    S[        US5      4=u  p#U R                  U'   UR                  S[        R                  5        UR                  5       nXC4U R                  U'   U$ )z-preserve an open file handle for a given pathNrbr   )r*  r	  r+  r'  SEEK_ENDtell)r   r   r   ri   r   s        r$   	_keep_oneVolatileManager._keep_one  sZ     ,0c4*AA""3'
2;;wwy#'*3r&   c                    SU R                   :  d   e[        U R                  5      U R                  S-
  :  a  U R	                  5         U R                  U5        g)z!preserve the volatile file at srcr   r   N)r  r1   r	  r%  r0  r6  )r   r   s     r$   __call__VolatileManager.__call__  sH    4==   t!!"t}}q'89$$&sr&   c                B   SU R                   :  d   e[        U R                  5      U R                  S-
  :  a  U R	                  5          U R                  U5      $ ! [         a9  nUR                  [        R                  [        R                  4;  a  e  SnAgSnAff = f)zrecord a volatile file and returns it size

return None if the file does not exists.

Used for cache file that are not lock protected.
r   r   N)
r  r1   r	  r%  r0  r6  OSErrorerrnoENOENTEPERM)r   r   errs      r$   try_keepVolatileManager.try_keep  s     4==   t!!"t}}q'89$$&	>>#&& 	yyu{{ ;;	s   
A 
B%/BBc              #  J  #    SU R                   :  d   eU R                  R                  U5      nUb  Uu  p4UR                  S5        Uv   g U R                  c  UnOU R                  R                  X5      n[        US5       nUv   S S S 5        g ! , (       d  f       g = f7f)Nr   r3  )r  r	  r6   r+  r
  r*  )r   r   r   r  ri   actual_paths         r$   r*  VolatileManager.open  s     4==   ""&&s+IEGGAJH||#!"ll..s8k4(B )((s   BB#B		B#
B B#)r
  r  r  r	  Nr   )r   bytesr   rV   )r   rF  r   r   )r   rF  r   zOptional[int])r   r   r   r   r   r   	iswindowsr%  r   r  r  r   r0  r6  r9  rA  
contextlibcontextmanagerr*  r   r   r&   r$   r  r  h  sZ    $ &&qCH)">&"  r&   r  c                    [         U R                  [        U R                  0nU R                  UR                  5       ;  d   eU$ )z$make a (src -> vfs) map for the repo)	_srcstorer`   	_srccachecachevfsr   r  )r(   r   s     r$   _makemaprN    s<     	4994==F 886==?***Mr&   c              #    #    [        U 5      nU R                  UR                  5       ;   a  [        R                  " S5      eU VVs/ s H  u  p4X2U   U4PM     nnn[        U 5        [        U 5      nS=pg[        5        n[        R                  " 5          U HF  u  pnUR                  X5        UR                  5        H  nUS-  nX{R                  U
5      -  nM     MH     SSS5        U R                  R                  [        S5      U[        S5      S9nUR!                  S5        U   Xg4v   SnU H  u  pnUR#                  U U
UUSS	9nU H  u  nnnUv   [        R$                  " [        U5      5      v   [        R$                  " U5      v   Uv   SnU H4  nU[        U5      -  nU[        U5      -  nUR!                  U5        Uv   M6     UU:w  d  M  [        S
5      n[        R&                  " UUUU4-  5      e   M     SSS5        SSS5        gs  snnf ! , (       d  f       GND= f! , (       d  f       N/= f! , (       d  f       g= f7f)zactually emit the stream bundle9repo.vfs must not be added to vfsmap for security reasonsr   r   Nr   r   r   T)r(   r   	volatilesmax_changesetpreserve_file_counts=   clone could only read %d bytes from %s, but expected %d bytes)rN  r   r  r   ProgrammingErrorr   r1   r  r   nogcpreserve_volatilesr   r   r;   r   r   r!   get_streamsuvarintencoderY   )r(   r   r   vfs_keyrh   max_linkrevr   totalfilesizerQ  kr   r   r   totalbytecountr   entry_streamsr   streamr   rm   r   msgs                         r$   _emit2ra    s+    d^F xx6==?"$$G
 	

 BII'!,GId#d)K!""J		iYY[$	$$S4A!OJ![[%55M # %  77''iLAhK ( 
 	++N&! !'"-(, !. ! +8&D&$I,,SY77,,T22J !I!'!SZ/	&#e*4 7#	 "(
 !D(  1 $kk#D$0G*GHH% +8  '  
	 J [ X 
	sc   AIH&I IAH #AI+B-H2-H2	II 
H/	*I2
I 	<I
IIc           
   #    #    [        U 5      nU R                  UR                  5       ;   a  [        R                  " S5      e[        U5      n[        U 5        / n[        5        nU H  u  pVX%   nSnUR                  (       aN  SnUR                  Xt5        UR                  5        H'  n	U	R                  (       a  U	R                  U5        SnM)     U(       d  Ms  UR                  XRU   U45        M     [        U5      n
[        U 5      nU R                  R!                  [#        S5      U
[#        S5      S9nUR%                  S5        Sv   U   [&        R(                  " U
5      v   U H  u  pnUR+                  U UUUS	9n[&        R(                  " [        U5      5      v   U HR  u  nnnUv   [&        R(                  " [        U5      5      v   [&        R(                  " U5      v   Uv   U Sh  vN   MT     UR-                  5         M     SSS5        SSS5        g N-! , (       d  f       N= f! , (       d  f       g= f7f)
z$actually emit the stream bundle (v3)rP  TFr   s   entryr   r   N)r(   r   rQ  rR  )rN  r   r  r   rT  listr   r  maybe_volatilerV  r   is_volatiler   r   r1   r;   r   r   r!   r   rX  rW  r   )r(   r   r   base_entriesrQ  rY  rh   r   	any_filesr   total_entry_countrZ  r   r   r^  r   r_  r   s                     r$   _emit3ri  :  s    d^F xx6==?"$$G
 	
 =Ld#G		i&JG/CI!	$$S4A}}C( $I	 #
 y!<= '  L$i77''iL#8 ( 

 	
$$%677&! !'"-	 !. ! ((]);<<*7&D&$I,,SY77,,T22J%%% +8 ""$  ' 7 
	V &! X7 
	sQ   A"I$A2H2A4H2B#H!1H2H!H2	IH!!
H/	+H22
I <Ic                    g)za function for synchronisation during tests

Triggered after gather entry, but before starting to process/preserve them
under lock.

(on v1 is triggered before the actual walk start)
Nr   r(   s    r$   r   r   {      r&   c                    g)za function for synchronisation during tests

Triggered right before releasing the lock, but after computing what need
needed to compute under lock.
Nr   rk  s    r$   r   r     rl  r&   c                    g)zWa function for synchronisation during tests

Triggered right after releasing the lock.
Nr   rk  s    r$   r   r     rl  r&   c                  J   ^  \ rS rSrSrSU 4S jjrSS jrSU 4S jjrSrU =r	$ )	
CacheEntryi  zRepresent an entry for Cache files

It has special logic to preserve cache file early and accept optional
presence.


(Yes... this is not really a StoreEntry, but close enough. We could have a
BaseEntry base class, bbut the store one would be identical)
c                "   > [         TU ]  USS9  g )NT)re  )superr   )r   
entry_path	__class__s     r$   r   CacheEntry.__init__  s     	 	
r&   c                   UR                  UR                  U R                  5      5      U l        U R                  c  / U l        g U R
                  (       d   e[        U R                  U R                  U R
                  S9/U l        g )N)r   r   re  )rA  r?   _entry_path
_file_size_files_is_volatile	CacheFile)r   r   rQ  s      r$   rV  CacheEntry.preserve_volatiles  sm    #,,SXXd6F6F-GH??"DK$$$$#'#3#3"oo $ 1 1DKr&   c                   > U R                   c$  [        U R                  U R                  S9/U l         [        TU ]  5       $ )N)r   re  )ry  r{  rw  rz  rr  r   )r   rt  s    r$   r   CacheEntry.files  s>    ;;#'#3#3 $ 1 1DK w}r&   )rx  ry  r   )r   zlist[store.StoreFile])
r   r   r   r   r   r   rV  r   r   __classcell__rt  s   @r$   rp  rp    s    
 r&   rp  c                  $    \ rS rSr% SrS\S'   Srg)r{  i  Tr8   optionalr   N)r   r   r   r   r  __annotations__r   r   r&   r$   r{  r{    s     Hdr&   r{  c              #    #    U R                  U R                  5      c   eSnU(       d  U(       a!  [        R                  " U R                  X5      nU R                  5       (       + n[        R                  " 5          [        U UUUS9nU H  n[        U4v   M     [        R                  " U 5       H6  nU R                  R                  U5      (       d  M%  [        [        US94v   M8     SSS5        g! , (       d  f       g= f7f)zemit a seris of files information useful to clone a repo

return (vfs-key, entry) iterator

Where `entry` is StoreEntry. (used even for cache entries)
Nrw   )rs  )_currentlock_lockrefr   matchrootr   r   rU  r|   rK  r   cachetocopyrM  existsrL  rp  )	r(   includesexcludesincludeobsmarkersr{   rx   r   r   r   s	            r$   _entries_walkr    s      T]]+777G8""499hA!!E 
"*	
 Ee$$  ))$/D}}##D)) *"=>> 0 
s%   A:D<AC5C5,	D5
D?Dc                   U R                  5          U R                  R                  S5        [        U UUUS9n[	        X5      n[        U5      nUu  px[        U 5        SSS5        [        U 5        WWW4$ ! , (       d  f       N= f)a  Emit content for version 2 of a streaming clone.

the data stream consists the following entries:
1) A char representing the file destination (eg: store or cache)
2) A varint containing the length of the filename
3) A varint containing the length of file data
4) N bytes containing the filename (the internal, store-agnostic form)
5) N bytes containing the file data

Returns a 3-tuple of (file count, file size, data iterator).
r   r  r  r  N)r\   r;   r   r  ra  nextr   r   )	r(   r  r  r  r   chunksfirstr   total_file_sizes	            r$   
generatev2r    s|     
m$/	
 &V&+#
% 
 D!.. 
s   AA66
Bc           	     |   U R                  5          [        R                  " 5          U R                  R	                  S5        [        U UUUS9n[        U [        U5      5      n[        U5      nUb   e[        U 5        SSS5        SSS5        [        U 5        W$ ! , (       d  f       N#= f! , (       d  f       N,= f)a  Emit content for version 3 of a streaming clone.

the data stream consists the following:
1) A varint E containing the number of entries (can be 0), then E entries follow
2) For each entry:
2.1) The number of files in this entry (can be 0, but typically 1 or 2)
2.2) For each file:
2.2.1) A char representing the file destination (eg: store or cache)
2.2.2) A varint N containing the length of the filename
2.2.3) A varint M containing the length of file data
2.2.4) N bytes containing the filename (the internal, store-agnostic form)
2.2.5) M bytes containing the file data

Returns the data iterator.

XXX This format is experimental and subject to change. Here is a
XXX non-exhaustive list of things this format could do or change:

- making it easier to write files in parallel
- holding the lock for a shorter time
- improving progress information
- ways to adjust the number of expected entries/files ?
r   r  N)r\   r   rU  r;   r   r  ri  rc  r  r   r   )r(   r  r  r  r   r  r  s          r$   
generatev3r    s    < 
diikm$/	
 d7m,V}}% " D!M "ks#   B-AB?B-
B*	&B--
B;c               '     #    U S   nU SS  nU   U(       a  [        U6    S v   S S S 5        OS v   S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7fr  )nested)ctxsthisrests      r$   r  r  5  sI     7D8D	   
 
s/   AA:A	A
A	A
AAc                      \ rS rSrSrS rSrg)V2ReportiA  z8a small class to track the data we saw within the streamc                    SU l         g r  r   r  s    r$   r   V2Report.__init__D  s	    r&   r  N)r   r   r   r   r   r   r   r   r&   r$   r  r  A  s
    Br&   r  c                  ^  T R                  5          T R                  R                  [        S5      U[        R
                  " U5      4-  5        T R                  R                  [        S5      U[        S5      S9n[        R                  " 5       n[        5       n[        T 5      nT R                  UR                  5       ;   a  [        R                  " S5      e[        R                  " T R                  S5      n[        R                  " T R                  S5      n	T R                  R!                  SS	5      n
T R                  R#                  SS
5      nUS::  a	  [$        U   nT R                  R'                  SS5      nUS:  a  SnOUS:X  a	  [(        U	   nT R+                  S5         U 4S jUR                  5        5       n[-        U6    / nSnSnSn U
(       d	  [.        nUnOu[0        n[3        US9nUb  UR4                  n[        R6                  " U5      n[8        R:                  " UR<                  U4S9nUR?                  U5        URA                  5         [C        T UUUUUUUS9nU
(       d  [E        U5        Oi[G        U5      n[I        U5       H>  n[8        R:                  " [D        U4S9nUR?                  U5        URA                  5         M@     URK                  5          Ub  URO                  [Q        U5      5        U H  nURS                  5         M      SSS5        T RU                  SS9  SSS5        URW                  5         URY                  S5      nU(       a   e[[        T XRUR\                  5        SSS5        g!   Ub  URM                  5         e = f! Ub  URO                  [Q        U5      5        U H  nURS                  5         M     f = f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)zApply the contents from a version 2 streaming clone.

Data is read from an object that only needs to provide a ``read(size)``
method.
r   r   r   r   rP  s   cpus   memorys   workers!   parallel-stream-bundle-processings,   parallel-stream-bundle-processing.num-writerr   s/   parallel-stream-bundle-processing.memory-targetNc              3  X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r   r;   .0r   r(   s     r$   	<genexpr>consumev2.<locals>.<genexpr>z  !     Nos))$''22o   '*)memory_target)targetr  )file_chunker	mark_usedTr   r   )/r\   r;   rT   r   r   rm   r   r~   r  rN  r   r  r   rT  r   get_resource_profilerr   	configintDEFAULT_NUM_WRITERconfigbytesDEFAULT_MEMORY_TARGETr   r  _FileChunker_ThreadSafeFileChunker
_DataQueuer  chunkbuffer	threadingThread	fill_fromr   r   _v2_parse_files_write_files_FileInfoQueuer   fillabortr  r1   r?   rf   r   r   r   r   )r(   ri   rl   filesizer   r   reportr   cpu_profilemem_profilethreaded
num_writerr  r  workers
info_queue
data_queuer  fcraw_datawr   __remainss   `                       r$   	consumev2r  H  s    
34$..234	
 77''hK8 ( 

 

$ 88v}}&((K  22477FC22477IF77%%;
 WW&&;

 ?+K8J++>
 1 Ma1+>Mh'NfmmoND!
!
 	3!#)#%3%/m%L
(4(2(<(<I#'#3#3J#?%,,#-#7#7"$  q)	+ ! %'"+	E $$U+%3E%:
"'
"3B ) 0 0'3&0]!A $NN1-GGI #4 #) "- #((W6$ %o x OO4O0} (@ 	 ''!*{D%F4E4EFa 
t!-"((* "- #((W6$ %o  ('W 
su   FO=)#O,	OB'N=N >A(N&N '6OO,5A	O=N	N  8O	O
O)%O,,
O:	6O==
Pc                  *    \ rS rSrSrS rS rS rSrg)_Queuei  zDa reimplementation of queue.Queue which doesn't use thread.Conditionc                    [         R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       U l        g r   )collectionsdeque_queuer  Lock_lock_waitr  s    r$   r   _Queue.__init__  s0    !'') ^^%
^^%
r&   c                    U R                      U R                  R                  U5        U R                  R	                  5       (       a  U R                  R                  5         S S S 5        g ! , (       d  f       g = fr   )r  r  r   r  lockedrelease)r   items     r$   put
_Queue.put  sH    ZZKKt$zz  ""

""$	 ZZs   AA++
A9c                ^   U R                      [        U R                  5      S:X  a  U R                  R	                  SS9  U R                   R                  5         U R                  R	                  5         U R                   R	                  5         U R                  R                  5       (       a3  [        U R                  5      S:  a  U R                  R                  5         [        U R                  5      S:X  a  M  U R                  R                  5       sS S S 5        $ ! , (       d  f       g = f)Nr   Fblockingr   )r  r1   r  r  acquirer  r  popleftr  s    r$   r6   
_Queue.get  s    ZZdkk"a'

""E"2 

""$

""$

""$
 ::$$&&3t{{+;a+?JJ&&( dkk"a'  ;;&&(# ZZs   C,D;D
D,)r  r  r  N)	r   r   r   r   r   r   r  r6   r   r   r&   r$   r  r    s    N&%)r&   r  c                  @    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)r  i  zA queue passing data from the bundle stream to other thread

It has a "memory_target" optional parameter to avoid buffering too much
information. The implementation is not exact and the memory target might be
exceed for a time in some situation.
Nc                &   [        5       U l        SU l        Xl        U R                  b&  U R                  S::  a  [        R
                  " S5      e[        R                  " 5       U l        [        R                  " 5       U l	        SU l
        SU l        g )NFr   zmemory target should be > 0)r  _q_abort_memory_targetr   rT  r  r  r  r  _current_read_current_used)r   r  s     r$   r   _DataQueue.__init__   sq    (+*t/B/Ba/G(()FGG ^^%
^^%
r&   c                j    U R                   c  gU R                  U R                  -
  U R                   :  $ )zfTrue if more data can be read without further exceeding memory target

Must be called under the lock.
T)r  r  r  r  s    r$   _has_free_space_DataQueue._has_free_space  s7    
 & ""T%7%774;N;NNNr&   c                2   U R                   by  U R                     XR                  :  a  Xl        U R                  R	                  5       (       a/  U R                  5       (       a  U R                  R                  5         SSS5        gg! , (       d  f       g= f)z{Notify we have used the buffer up to "offset"

This is meant to be used from another thread than the one filler the queue.
N)r  r  r  r  r  r  r  )r   offsets     r$   r  _DataQueue.mark_used!  sl    
 *...)/&::$$&&4+?+?+A+AJJ&&(  +s   A$B
Bc                   U R                   n U GH6  nU =R                  [        U5      -  sl        UR                  U5        U R                  (       a    OU R
                  c  MU  U R                     U R                  5       (       d  U R                  R                  SS9  U R                  R                  5         U R                  R                  5         U R                  R                  5         U R                  R                  5       (       a  U R                  R                  5         U R                  5       (       d  M  SSS5        GM9     UR                  S5        g! , (       d  f       GM]  = f! UR                  S5        f = f)zffill the data queue from a bundle2 part object

This is meant to be called by the data reading thread
NFr  )r  r  r1   r  r  r  r  r  r  r  r  r  )r   r  qr  s       r$   r  _DataQueue.fill_from.  s   
 GG	""c$i/"d;;&&2"&"6"6"8"8 !JJ...> JJ..0 JJ..0 JJ..0  $zz0022 $

 2 2 4 #'"6"6"8"8 $ * EE$K $ EE$Ks+   AE0 %E0 1CE>E0 
E-	'	E0 0Fc              #     #    U R                   nUR                  5       =nb,  Uv   U R                  (       a  gUR                  5       =nb  M+  gg7f)zWIterate over the bundle chunkgs

This is meant to be called by the data parsing thread.N)r  r6   r  r   r  r   s      r$   __iter___DataQueue.__iter__L  sA      GGEEG|q(G{{ EEG|q(s   A	AAc                "   SU l         U R                  R                  S5        U R                  bO  U R                     U R
                  R                  5       (       a  U R
                  R                  5         SSS5        gg! , (       d  f       g= f)zjstop the data-reading thread and interrupt the comsuming iteration

This is meant to be called on errors.
TN)r  r  r  r  r  r  r  r  r  s    r$   r  _DataQueue.abortV  sc    
 D*::$$&&JJ&&(  +s   :B  
B)r  r  r  r  r  r  r  r   )r   r   r   r   r   r   r  r  r  r  r  r   r   r&   r$   r  r    s&    ,	O)<)r&   r  c                  4    \ rS rSrSrS	S jrS rS rS rSr	g)
r  id  zDA thread-safe queue to passer parsed file information to the writersc                .    Xl         [        5       U l        g r   )_infor  r  )r   infos     r$   r   _FileInfoQueue.__init__g  s    
(r&   c                d    U R                   nU R                   H  nUR                  U5        M     g)ziterate over the parsed information to file the queue

This is meant to be call from the thread parsing the stream information.
N)r  r  r  r  s      r$   r  _FileInfoQueue.fillk  s&    
 GGAEE!H r&   c                ^    [        U5       H  nU R                  R                  S5        M      g)zsignal all the workers that we no longer have any file info coming

Called from the thread parsing the stream information (and/or the main
thread if different).
N)r   r  r  )r   number_workerr  s      r$   r  _FileInfoQueue.closet  s#     &BGGKK 'r&   c              #  ~   #    U R                   nUR                  5       =nb  Uv   UR                  5       =nb  M  gg7f)zZiterate over the available file info

This is meant to be called from the writer threads.
N)r  r6   r  s      r$   r  _FileInfoQueue.__iter__}  s7     
 GGEEG|q(G EEG|q(s   7==)r  r  Nr  zIterable[FileInfoT])
r   r   r   r   r   r   r  r  r  r   r   r&   r$   r  r  d  s    Nr&   r  c                  N    \ rS rSrSr S         S	S jjrS
S jrSS jrSrg)r  i  zyield the chunk that constitute a file

This class exists as the counterpart of the threaded version and
would not be very useful on its own.
Nc                N    X@l         X0l        [        R                  " XS9U l        g )Nr   )r  r   r   r   _chunks)r   ri   data_lenr   r  r  s         r$   r   _FileChunker.__init__  s       ))"=r&   c                    g)z#Do nothing in non-threading contextNr   r  s    r$   r  _FileChunker.fill  rl  r&   c              #     #    U R                    HQ  nU R                  =R                  [        U5      -  sl        U R                  R                  [        U5      S9  Uv   MS     g 7f)Nr   )r  r  r   r1   r   r   )r   r   s     r$   r  _FileChunker.__iter__  sJ     \\EKK""c%j0"MM##U#4K "s   A#A%)r  r   r  r   
ri   bundle2mod.unbundlepartr  rV   r   scmutil.progressr  r  r  Optional[Callable[[int], None]]r   r   FileChunksT)	r   r   r   r   r   r   r  r  r   r   r&   r$   r  r    sK     6:
>#
> 
> #	
>
 
> 3
>2r&   r  c                  b   ^  \ rS rSrSr S         SU 4S jjjrS	U 4S jjrS
S jrSrU =r	$ )r  i  zyield the chunk that constitute a file

Make sure you  call the "fill" function in the main thread to read the
right data at the right time.
c                \   > [         TU ]  XX45        Xl        [        5       U l        XPl        g r   )rr  r   _fpr  r  
_mark_used)r   ri   r  r   r  r  rt  s         r$   r   _ThreadSafeFileChunker.__init__  s'     	x8h#r&   c                  >  [         TU ]  5        H9  nU R                  R                  5       nU R                  R                  X45        M;     U R                  R                  S5        g! U R                  R                  S5        f = f)zfill the file chunker queue with data read from the stream

This is meant to be called from the thread parsing information (and
consuming the stream data).
N)rr  r  r  r5  r  r  )r   r   r  rt  s      r$   r  _ThreadSafeFileChunker.fill  s^    	")+0 , KKOOD!DKKOOD!s   AA* *Bc              #     #    U R                   R                  5       =nbF  Uu  p#U R                  b  U R                  U5        Uv   U R                   R                  5       =nb  ME  gg7f)zUIterate over all the file chunk

This is meant to be called from the writer threads.
N)r  r6   r  )r   r  r   r  s       r$   r  _ThreadSafeFileChunker.__iter__  sW     
 {{((t5 ME*'K	 {{((t5s   A!A'%A')r  r  r  r   r  r   r  )
r   r   r   r   r   r   r  r  r   r  r  s   @r$   r  r    sV     6:$#$ $ #	$
 $ 3$ $"	 	r&   r  c              #  *   #    Ub  U" U5        U v   g7f)zused for single chunk file,Nr   )r   r  r  s      r$   _trivial_filer"    s      &
Ks   c           	   #  T  #    [        5       nUR                  S5        [        U5       GHy  n	[        R                  " US5      n
[        R
                  " U5      n[        R
                  " U5      n[        R                  " X5      nU R                  R                  (       a4  U R                  R                  SX[        R                  " U5      4-  5        X*   nUR                  X5      u  nnU[        R                  ::  aw  UR                  U5      nUR                  5       nU=R                  [        U5      -  sl        UR!                  [        U5      S9  [#        UUU5      nUU[%        U5      4v   GMO  U" UUUUUS9nUU[%        U5      4v   UR'                  5         GM|     g7f)zsdo the "stream-parsing" part of stream v2

The parsed information are yield result for consumption by the "writer"
r   r      adding [%s] %s (%s)
r   )r  N)r   r!   r   r   readexactlyuvarintdecodestreamr;   r   r   rm   prepare_streamed_fileDEFAULT_FILE_CHUNKr   r5  r   r1   r   r"  iterr  )r(   ri   vfs_mapr   r   r  r  r  
known_dirsr   r   namelendatalenr   r   r   modecr  r  s                       r$   r  r    s`     JOOA:r1%**2.**2.,77GGMM(Ct~~g7N+OO l..t@
dd--- AWWYFQ'CF+"1i8FtF|,,!#F tF|,,KKM= s   F&F(c                $   [         R                  [         R                  -  n[        R                  (       a  U[         R
                  -  nU  H  u  p#nUc  [         R                  " X!5      nO[         R                  " X!US9n U HT  n[         R                  " XV5      nU[        U5      :  d  M*  [         R                  " XVUS 5      nU[        U5      :  a  M*  MV     [         R                  " U5        M     g! [         R                  " U5        f = f)zwrite files from parsed dataN)r.  )
r'  O_WRONLYO_CREATr   rG  O_BINARYr*  r   r1   r  )r  io_flagsr   r.  r  r-  r   writtens           r$   r  r    s    {{RZZ'HBKK D<(Bd3B	((2-E
* hhr?;G E
*  HHRL ! HHRLs   (C7.(C7C77Dc                L  ^  T R                  5          [        R                  " 5       n[        R                  " U5      nT R                  R                  [        S5      U-  5        T R                  R                  [        S5      U[        S5      S9nUR                  S5        Sn[        T 5      nT R                  UR                  5       ;   a  [        R                  " S5      eSnT R                  S5         U 4S jUR                  5        5       n[        U6    [!        U5       GHp  n	[        R                  " U5      n
U
S:X  a9  T R                  R"                  (       a  T R                  R%                  SU	-  5        Xz-  n[!        U
5       H  n	[        R&                  " US	5      nXk   n[        R                  " U5      n[        R                  " U5      n[        R&                  " X5      nT R                  R"                  (       a8  S
nUX[        R(                  " U5      4-  nT R                  R%                  U5        X^-  nU" US5       n[        R*                  " XS9 H  nUR-                  U5        M     SSS5        M     UR/                  S	S9  GMs     SSS5        T R1                  SS9  SSS5        UR3                  5         [5        T X'U5        SSS5        g! , (       d  f       GMb  = f! , (       d  f       N^= f! , (       d  f       NX= f! , (       d  f       g= f)zApply the contents from a version 3 streaming clone.

Data is read from an object that only needs to provide a ``read(size)``
method.
s   %d entries to transfer
r   s   entriesr   r   rP  c              3  X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r  r  s     r$   r  consumev3.<locals>.<genexpr>A  r  r  s   entry with no files [%d]
r   r$  r   r   Nr   Tr   )r\   r   r~   r&  r;   rT   r   r   r!   rN  r   r  r   rT  r   r  r   r   r   r%  rm   r   r   r   rf   r   r   )r(   ri   r   
entrycountr   bytes_transferredr   r   r  r   rl   r   r   r,  r-  r   r`  r   r   s   `                  r$   	consumev3r;  !  sv    


--b1
q45DE77''hK: ( 

 	$ 88v}}&((K  h'NfmmoNDz*A $ 8 8 <I A~77,, GGMM*G1*MN$1$"9-"..r15$k"&":":2">"&":":2">#//<77,,":CCt~~g/F#GGC GGMM#.)4) t_)-););B)N #		% 0 *O -_ ." &&A&./ + 8 OO4O0= (@ 	D%;LMu 
` -_+  ('3 
sU   C%L7#LD4K3-K ; K3L2%L 
K0*	K33
L=L
L	L
L#c                f   SSK Jn  U Vs/ s H  ofU R                  ;  d  M  UPM     nnU(       a:  [        R                  " [        S5      SR                  [        U5      5      -  5      e[        R                  " 5          [        XX#5        S S S 5        [        U R                  U5      U l        UR                  U R                  U R                  U R                  5      U R                   l        [$        R&                  " U 5        [(        R*                  " U 5        g s  snf ! , (       d  f       N= fNr   rK   r   r-   )rP   rL   r>   r   rY   r   r?   r@   r   rU  r  r%   r   r^   r;   r_   r`   ra   r   rb   r   rc   )r(   ri   rl   r  r   rL   rrH   s           r$   applybundlev2r?  d  s     *Flt~~.E1lKFkkEFjj,-.
 	

 
$I0 
 6D "88""DMMDII !!$'%% G 
s   DD D""
D0c                   SSK Jn  U Vs/ s H  oDU R                  ;  d  M  UPM     nnU(       a>  [        S5      nUSR	                  [        U5      5      -  n[        R                  " U5      e[        X5        [        U R                  U5      U l
        UR                  U R                  U R                  U R                  5      U R                  l        [         R"                  " U 5        [$        R&                  " U 5        g s  snf r=  )rP   rL   r>   r   r?   r@   r   rY   r;  r%   r   r^   r;   r_   r`   ra   r   rb   r   rc   )r(   ri   r   rL   r>  rH   r`  s          r$   applybundlev3rA  ~  s    *Flt~~.E1lKFGHuzz&-..kk#d5D "88""DMMDII !!$'%! Gs
   DDc           	       ^^ S/mUU4S jnU H  u  pVnX   nX   n	UR                  U5      n
U	R                  U5      n[        R                  R                  U5      n[        R                  R	                  U5      (       d  [
        R                  " U5        U	R                  U5         [
        R                  " U
UTS   USS9  TR                  5         M     TS   $ ! [         a    U(       d  e  N-f = f)NTc                 0   > ST S'   [        S5      Tl        g )NFr   s   copying)r   topic)hardlinkr   s   r$   	copy_used_copy_files.<locals>.copy_used  s    :r&   r   F)rE  no_hardlink_cbcheck_fs_hardlink)r?   r'  r   dirnamer  r   makedirsregister_filecopyfileFileNotFoundErrorr   )src_vfs_mapdst_vfs_mapr   r   rF  r\  r   r  src_vfsdst_vfssrc_pathdst_pathrJ  rE  s      `         @r$   _copy_filesrU    s    vH' %..<<%<<% ''//(+ww~~g&&MM'"d#
	MM!!("' 	/ %0 A;	 ! 	 	s   *CC32C3c                   U R                    Vs1 s H  nU[        R                  ;  d  M  UiM     nnUR                    Vs1 s H  nU[        R                  ;  d  M  UiM     nnX4:X  d   eUR                  5          U R                  5          [        R
                  " U 5      nUR                  S5      nSn[        R                  R                  U5      (       a  Sn[        U SSSS9n[        U5      n[        U 5      n	[        U5      n
[        S U 5       5      U-   nU R                  R                  [!        S5      U[!        S	5      S
9nU VVVs/ s H5  u  pUR#                  5         H  nXR$                  UR&                  4PM     M7     nnnn[)        XUU5      nU(       a>  [        R
                  " U5      nUR                  S5      n[*        R,                  " UU5        SSS5        WR/                  5         W(       a  SnOSnU R                  R1                  UW-  5        UR3                  S5       nUR4                  R7                  U5        SSS5        [2        R8                  " UR                  R:                  UR<                  5        SSS5        gs  snf s  snf s  snnnf ! , (       d  f       N= f! , (       d  f       Nn= f! , (       d  f       g= f)zUcopy all content from one local repository to another

This is useful for local clones	   bookmarksr   r   NTr  c              3  Z   #    U  H!  n[        US    R                  5       5      v   M#     g7f)r   N)r1   r   )r  rh   s     r$   r  local_copy.<locals>.<genexpr>  s"     AAc!A$**,//s   )+s   linkings   files)rD  r   r   s   linked %d files
s   copied %d files
s
   localclone)r   r   WORKING_DIR_REQUIREMENTSr\   r   bookmarksvfsr?   r'  r   r  r  rc  rN  sumr;   r   r   r   r   r  rU  r   rM  r   r   r   r   r   cleanup_undo_filesr<   r*  )src_repo	dest_repor>  src_store_requirementsdest_store_requirementssrc_book_vfssrcbookmarksbm_countr   rO  dest_vfs_maptotal_filesr   rY  rh   r   r   rE  dst_book_vfsdstbookmarksr`  trs                         r$   
local_copyri    s    &&&AO<<< 	
&   '''AO<<< 	
'  
 "<<<		]]_ %11(;L',,\:LHww~~l++#"&	G 7mG"8,K#I.LAAAHLK{{//
m!x[ 0 H #*")JGA **AJJ7" 8")  
 #;eXNH (55i@+00>lL9W X 	&C&C#+,""=1ROO!!"% 2 	&&y||'8'8):K:KLq 
	
PA _f 21i 
	sg   JJJJ<KCJ*<J#AJ*$AK7J;=K#J**
J8	4K;
K		K
K)r"   Iterable[bytes]r#   rj  r   
Set[bytes])r   rk  )F)r   r8   r   )r   r8   )NFF)rx   r8   ry   r8   )r   floatr   rV   r   rV   )r   z tuple[int, int, Iterator[bytes]]r   )r   )r   rF  r   z"tuple[Set[bytes], Iterator[bytes]])rl   rV   rm   rV   r   r   )r   ztuple[int, int, Set[bytes]])r   zlist[bytes])r   Iterator[bytes | None])r  r8   )r  r8   r   rm  )rl   rV   r  rV   r   r   )r   rF  r  r  r  rV   r   r  )ri   r  r   rV   r   r  r  r  r  zType[_FileChunker]r  r  r   zIterator[FileInfoT]r  )rl   rV   r  rV   r   rj  r   r   )r   rj  r   r   )a
__future__r   r  rH  r=  r'  r   r  typingr   r   r   r   r   r	   r
   i18nr   
interfacesr   rP   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   revlogutilsr   RESOURCE_LOWRESOURCE_MEDIUMRESOURCE_HIGHr  r  r%   r#   rI   rn   ru   r|   r   r   r   r   r]   r   r   r   _fileappendr   rK  rL  r   r  r  rN  ra  ri  r   r   r   SimpleStoreEntryrp  	StoreFiler{  r  r  r  rI  r  r  r  rF  r  rV   	FileInfoTr  r  r  r  r  r"  r  r  r;  r?  rA  rU  ri  r   r&   r$   <module>rz     s8   #    	      "    !Q1  ,[9 )*  [|HV& CHL#L;?L),:="77t8  %99'9xIFX.8&.- - 	 		< D
@IF>%B('' (V ?@/>-15--`   vGt uo	SM	*) *)Zi) i)X   F :*\ *Z.  	$ (415.. 	.
 . . %. /. .b(@NF&&(+&;J&	&4&,DHMr&   