
    q&f                        d dl Z d dlZ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mZmZmZ ddlmZ d Zd Zd*d	Zd
 Zd Zd+dZd Zd Zd,dZ d Z!d Z"d Z# G d d      Z$d Z%dZ&dZ'dZ(d Z)d Z* G d d      Z+d Z,d Z-d Z.d Z/d Z0d  Z1d! Z2d" Z3e jh                  d#        Z5d$ Z6d% Z7d& Z8d' Z9d( Z:d) Z;y)-    N   )_)
repository)	bookmarksbundle2	cacheutilerror
narrowspecphasespycompatrequirementsscmutilstoretransactionutil)nodemapc                 d    t        |       }|t        j                  z  }|j                  |       |S )a	  determine 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_FIXED_REQUIREMENTSupdate)default_requirementsstreamed_requirementsr   s      7/usr/lib/python3/dist-packages/mercurial/streamclone.pynew_stream_clone_requirementsr   "   s4     +,LO===L-.    c                 @    | j                   t        j                  z  }|S )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%     	OEEE  r   c                    | j                   }| j                  }| j                  }||j                  d      }|syt	        |      ry| j
                  ryd}| j                  ret        j                  |d      }t        |j                  dg             }t        | j                  j                  dg             }t        ||z        }|r|sy|r|syt               }	|j                  d      r#|	j                  t        j                         d|	fS |j                  d      }
|
s/| j                   j                   j#                  t%        d             yt        |
j'                  d	            }
|
|j(                  z
  }|rx| j                   j                   j#                  t%        d
      dj+                  t-        |            z         | j                   j                   j#                  t%        d             y|
}	d|	fS )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   canperformstreamcloner?   :   s    ;;D]]F 11O  ..)<= 4y ||++DyA
jnnY;<v77;;IrJK2B BC 	) 5L~~i ==>B ? ^^M2
KKNN" ))$/0
 4>>1KKNN* **VK01	2 KKNN/ !r   c                    ddl m} t        |       \  }}|sy| j                  }| j                  }d}|j                  d      r9|j                         5 }|j                  di       j                         }ddd       |j                  j                  t        d             |j                         5 }|j                  di       j                         }ddd       j                         }		 t        |	      }
|
dk(  rt        j"                  t        d            |
d	k(  rt        j"                  t        d
            |
dk7  rt        j"                  t        d            |j                         }		 t%        t        |	j'                  dd            \  }}|j+                         5  t-        ||||       t/        |j0                  |      |_        |j3                  |j                  |j0                  |j4                        |j6                  _        t;        j<                  |       t?        j@                  |       |r|jB                  jE                  ||       |jG                          ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# t        $ r  t        j                   t        d      |	      w xY w# t        t(        f$ r  t        j                   t        d      |	      w xY w# 1 sw Y   yxY w)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    )$ rB   r?   r   r$   r&   commandexecutorcallcommandresultr1   statusr   readlineint
ValueErrorr	   ResponseErrorAbortmapr3   	TypeErrorlock	consumev1r   r   resolvestorevfsoptionsfeaturessvfsoptionsr   writereporequirementsr   post_stream_cleanup_branchcachesreplace
invalidate)r7   rB   r4   r   r   r$   
rbranchmapefplresp	filecount	bytecounts                r   maybeperformlegacystreamclonerd      s    3F;I|;;D]]F J~~l###% 	B|R8??AJ	B 	GGNN1/01				! 7Q]]="-4467 	A
1v
 qykk!<=>>	kk!CDEE	kk!DEFF
A
"3a(89	9 
 $Iy19
 &<<GGT&&
		 	%%d+##D)&&tZ8 E	B 	B
7 7  
!!891
 	

 	" 
!!891
 	


 s=   !I-0!I:*J /#J3 "CK%-I7:J)J03/K"%K.c                     t         j                  | j                  vry| j                  j	                  ddd      syt        j                  |       }|r| j                  j	                  dd      S y)z5Whether streaming clones are allowed from the server.Fs   servers   uncompressedT)	untrusteds   uncompressedallowsecret)r   REPO_FEATURE_STREAM_CLONErU   r1   
configboolr   	hassecret)r   secrets     r   allowservergenerationrk      sc    ++4==@77iDI d#Fww!!)-GHHr   c                 >    | j                   j                  |||      S )Nphaseobsolescence)r   walk)r   matcherrn   ro   s       r   _walkstreamfilesrr      s    ::??7%l?KKr   c                 h    g d} j                         5   j                  j                  d       t               D ]a  }|j	                         D ]L  }|j                   j                  j                        }|s+j                  |j                  |f       ||z  }N c t                ddd       t                 j                  j                  dt              |fz          j                   j                  j                   fd}t              | |       fS # 1 sw Y   zxY w)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   P  K   D ]  \  } }r j                   j                  d| |fz         dt        j                  |       |fz    | dd      5 }|dk  r|j	                  |       n t        j                  ||      D ]  }|  d d d         y # 1 sw Y   xY ww)Ns   sending %s (%d bytes)
s   %s %d
s   rbF)	auditpathi   limit)r1   debugr   	encodedirreadr   filechunkiter)namesizer_   chunk	debugflagentriesr   rV   s       r   emitrevlogdataz"generatev1.<locals>.emitrevlogdata!  s     ! 	$JD$8D$<GH!6 === dEU3 $r5=''$-'!%!3!3Bd!C $#$	$ $	$$ $s   AB&:BB&B#	B&)rR   r1   ry   rr   files	file_sizer   vfsappendunencoded_path_test_sync_point_walk_1_test_sync_point_walk_2r'   rV   r   )	r   total_bytesentryfr   r   r   r   rV   s	   `     @@@r   
generatev1r      s   & GK	 &m$%d+ 	-E[[] -KK

7	NNA$4$4i#@A9,K	-	- 	 %& D!GGMM+s7|[.II 99D!!I$ w<n&666C& &s   A$D(>1D((D1c              #      K   t        |       sd y	 t        |       \  }}}d d||fz   |D ]  }|  y# t        j                  $ r d Y yw xY ww)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
)rk   r   r	   	LockError)r   rb   rc   itr   s        r   generatev1wireprotor   3  su      !&#-d#3 	9b L
	9-
--  ?? s%   A< AAAAAc                      dk7  rt        d      t               }dj                  t        |             fd}| |       fS )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).
       UNs.   we do not support the compression argument yetr"   c               3     K   d  t              \  } }}j                  j                  t        d      || fz         t	        j
                  d| |       t	        j
                  dt              dz          dz    dk(  sJ j                  j                  t        d      |t        d	      
      }|j                  d       |D ]!  }|j                  t        |             | # |j                          y w)Ns   HGS1s   writing %d bytes for %d files
   >QQ   >Hr       r      bundle   bytestotalunitr   step)r   r1   rJ   r   structpackr'   makeprogressr   	incrementcomplete)rb   rc   r   progressr   compressionr   requiress        r   genzgeneratebundlev1.<locals>.genk  s     #-d#3 	9b01Y	4JJ	
 kk&)Y77kk%X!233 e###77''iL	( ( 
 	 	ECJ/K	 	s   DD)rM   r   r5   r6   )r   r   r   r   r   s   ``  @r   generatebundlev1r   O  sJ    , eJKK(.Lyy-.H6 r   c                    | j                         5  | j                  j                  t        d      |t	        j
                  |      fz         | j                  j                  t        d      |t        d            }|j                  d       t	        j                         }| j                  d      5  | j                  j                  | j                  |      5  t        |      D ]N  }t        |d      r|j                         }nIg }|r|d   d	k(  s,|j                  |j!                  d
             |s#|d   d	k(  s,dj#                  |      }	 |j%                  dd
      \  }	}
t'        |
      }
| j                  j0                  r3| j                  j3                  d|	t	        j
                  |
      fz         t5        j6                  |	      }| j                  |dd      5 }t	        j8                  ||
      D ].  }|j;                  t=        |             |j?                  |       0 	 ddd       Q 	 ddd       | jA                  d       ddd       t	        j                         |z
  }|dk  rd}|jC                          | j                  j                  t        d      t	        j
                  |      |t	        j
                  ||z        fz         ddd       y# t(        t*        f$ r  t-        j.                  t        d      |      w xY w# 1 sw Y   ;xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)a  Apply 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   )expectedcountrK      
r   r   r   rC   s   adding %s (%s)
   wT)backgroundcloserw   r   NclearfilecacheMbP?(   transferred %s in %.1f seconds (%s/sec)
)"rR   r1   rJ   r   r   rc   r   r   timerr   rV   backgroundclosingrangehasattrrK   r   r{   r5   r3   rL   rM   rQ   r	   rN   r   ry   r   	decodedirr|   r   r'   writer\   r   )r   r_   rb   rc   r   startir`   l_bufr}   r~   pathofpr   elapseds                  r   rS   rS     s    
 H
34$..345	
 77''hKyq{ ( 
 	

  h' "	1,,TWWI,N -y) -Ar:.KKM
 !##(U2Y%-?!LL4 $)U2Y%-?HHUO%&WWUA%6
d"4y
 ww((/49M2NN !??40D4tD -%)%7%7$%G -E$..CJ.?IIe,-- -3--B OO4O0E"	1H **,&a<G:;y)y723	
CH
 H
T '	2 #11HI1 - -5- -"	1 "	13H
 H
s|   B#L>4(L2AL&8L&L& K'3A2L&%A	L/L&;L2B	L>'/LL&L#L&&L/+L22L;	7L>>Mc                    | j                  d      }|dk7  r!t        j                  t        d      |z        t	        j
                  d| j                  d            \  }}t	        j
                  d| j                  d            d   }| j                  |      }|j                  d      st        j                  t        d	            t        |j                  d      j                  d
            }|||fS )NrD   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	   rO   r   r   unpackendswithr   rstripr3   )r_   r   rb   rc   requireslenr   r   s          r   readbundle1headerr     s    ''!*Kekk% 	
 	
 "===Iy--rwwqz215Kww{#HU#kk5
 	
 xu-33D9:Li--r   c                 N   t        |       rt        j                  t        d            t	        |      \  }}}|| j
                  z
  }|r9t        j                  t        d      dj                  t        |            z        t        | |||       t        j                  |        y)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)r'   r	   rO   r   r   r4   r5   r6   rS   r   rY   )r   r_   rb   rc   r   r>   s         r   applybundlev1r     s     4ykkCD
 	
 *;2)>&Iy,/KkkEFjj,-.
 	

 dB	9-%r   c                       e Zd ZdZd Zd Zy)streamcloneapplierzClass 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                     || _         y N)_fh)selffhs     r   __init__zstreamcloneapplier.__init__  s	    r   c                 .    t        || j                        S r   )r   r   )r   r   s     r   applyzstreamcloneapplier.apply  s    T488,,r   N)__name__
__module____qualname____doc__r   r    r   r   r   r     s    -r   r      s   cc                 L    g }| j                         s|j                  d       |S )z!list snapshot file from the stores
   phaseroots)
publishingr   )r   fnamess     r   _walkstreamfullstorefilesr   '  s"    F??m$Mr   c                 b    | \  }}}}|t         k7  r| S ||| |||   j                  |            fS )z actually copy the snapshot files)	_filefullr5   )r   copyvfsmapsrcr}   ftypedatas          r   _filterfullr   /  s@    "Cud	ud6#;#3#3D#9:;;r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TempCopyManagera  Manage temporary backup of volatile file during stream clone

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

    A copy can be done by calling the object on the real path (encoded full
    path)

    The backup path can be retrieved using the __getitem__ protocol, obj[path].
    On file without backup, it will return the unmodified path. (equivalent to
    `dict.get(x, x)`)
    c                      d | _         d | _        y r   )_copies_dst_dir)r   s    r   r   zTempCopyManager.__init__E  s    r   c                     | j                   d}t        j                  |      i | _         t        j                  d      | _        | S )NzCopies context already opens	   hg-clone-)prefix)r   r	   ProgrammingErrorr   mkdtempr   )r   msgs     r   	__enter__zTempCopyManager.__enter__I  s@    <<#/C((-- ((=r   c                    t         j                  j                  |      }t        j                  || j
                        \  }}t        j                  |       || j                  |<   t        j                  ||d       |S )z"create a backup of the file at src)r   dirT)hardlink)
osr   basenamer   mkstempr   closer   r   	copyfiles)r   r   r   fddsts        r   __call__zTempCopyManager.__call__Q  s^    !!#&""&dmmDC
SsC$/
r   c                 :    | j                   j                  ||      S )zreturn the path to a valid version of `src`

        If the file has no backup, the path of the file is returned
        unmodified.)r   r,   )r   r   s     r   __getitem__zTempCopyManager.__getitem__Z  s    
 ||S))r   c                     | j                   j                         D ]  }t        j                  |        t        j                  | j
                         d| _         d| _        y)zdiscard all backupsN)r   valuesr   	tryunlinktryrmdirr   )r   argskwarstmps       r   __exit__zTempCopyManager.__exit__a  sH    <<&&( 	 CNN3	 dmm$r   N)	r   r   r   r   r   r   r   r   r  r   r   r   r   r   7  s     *r   r   c                     t         | j                  t        | j                  i}| j                  |j                         vsJ |S )z$make a (src -> vfs) map for the repo)	_srcstorerV   	_srccachecachevfsr   r  )r   r   s     r   _makemapr  j  s<     	4994==F 886==?***Mr   c           
   #     K   t        |       }| j                  |j                         v rt        j                  d      |D cg c]  \  }}|||   |f }}}t        |       }dx}}|D ]4  \  }}	}|j                         D ]  }
|dz  }||
j                  |	      z  } 6 | j                  j                  t        d      |t        d            }|j                  d       t               5 }|5  |D ]I  \  }}	}|j                         D ]0  }
|
j                  s ||	j                  |
j                               2 K ||f d}|D ]  \  }}	}|j!                  | |	||d      }|D ]  \  }}}| t#        j$                  t        |             t#        j$                  |       | d}|D ]3  }|t        |      z  }|t        |      z  }|j                  |       | 5 ||k7  st        d	      }t        j&                  ||||fz          	 d
d
d
       d
d
d
       y
c c}}w # 1 sw Y   xY w# 1 sw Y   y
xY ww)zactually emit the stream bundle9   repo.vfs must not be added to vfsmap for security reasonsr   r   r   r   r   T)r   r   copiesmax_changesetpreserve_file_counts=   clone could only read %d bytes from %s, but expected %d bytesN)r  r   r  r	   r   r'   r   r   r1   r   r   r   r   is_volatiler5   r   get_streamsr   uvarintencoderO   )r   r   r   vfs_keyr^   max_linkrev
file_counttotalfilesizekr   r   r   r   totalbytecountr   entry_streamsr}   streamr~   rc   r   r   s                         r   _emit2r  w  s    d^F xx6==?"$$H
 	

 BII'1!,IGId)K!""J .	3 	.A!OJQ[[--M	..
 ww##	)M( $ H OOA		 $EdH $E  	5IAsAWWY 5==!"2"2345	5
 -''" 	EKCaMM)$( * M '4 E"fd	((T33((..
	#  EU+I"c%j0NOON3K	 
 $ -C  ++cYd,C&CDD%E	E$E $E $E J$E $E $E $EsP   AIH(BI,H:/)H.CH.-)H.H:I.H7	3H::I?Ic           	   #      K   t        |       }| j                  |j                         v rt        j                  d      |D cg c]  \  }}|||   |f }}}t        |      }t        |       }| j                  j                  t        d      |t        d            }|j                  d       t               5 }|5  |D ]Z  \  }	}
}|j                         D ]A  }|j                  |
       |j                  s! ||
j                  |j                               C \ d t!        j"                  |       |D ]  \  }}
}|j%                  | |
||      }t!        j"                  t        |             |D ]O  \  }}}| t!        j"                  t        |             t!        j"                  |       | |E d{    Q |j'                           	 ddd       ddd       yc c}}w 7 0# 1 sw Y   xY w# 1 sw Y   yxY ww)z$actually emit the stream bundle (v3)r  r   s   entryr   r   N)r   r   r  r  )r  r   r  r	   r   r'   r1   r   r   r   r   r   r   r  r5   r   r   r  r  r   )r   r   r   r  r^   total_entry_countr  r   r   r  r   r   r   r  r}   r  r~   s                    r   _emit3r     s    d^F xx6==?"$$H
 	

 BII'1!,IGIGd)Kww##	)x[ $ H
 OOA		 !dH !  	5IAsAWWY 5C ==!"2"2345	5 
  !233" 	!KCaMM)	 * M $$S%788&3 ""fd	((T33((..
!!!"  	!! ! ! JF "3! ! ! !s\   AHG.A$H:H=:G68CG6G4G6H%H4G66G?	;HHHc                      yz+a function for synchronisation during testsNr   r   s    r   r   r         r   c                      yr"  r   r#  s    r   r   r     r$  r   c              #     K   | j                  | j                        J d}|s|r!t        j                  | j                  ||      }| j                          }t        | |||      }|D ]  }t        |f  t        j                  |       D ]?  }| j                  j                  |      st        j                  |d      }t        |f A yw)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)
    Nrm   T)
entry_pathr  )_currentlock_lockrefr
   matchrootr   rr   r	  r   cachetocopyr  existsr   SimpleStoreEntryr
  )	r   includesexcludesincludeobsmarkersrq   rn   r   r   r}   s	            r   _entries_walkr2    s      T]]+777G8""499hA!!E&	G  !%  ! %%d+ %==%** E e$$%s   B)C,$Cc                    | j                         5  | j                  j                  d       t        | |||      }t	        | |      }t        |      }|\  }}t        |        ddd       t        |        fS # 1 sw Y   xY w)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).
    rt   r/  r0  r1  N)rR   r1   ry   r2  r  nextr   r   )	r   r/  r0  r1  r   chunksfirstr  total_file_sizes	            r   
generatev2r9    s     
 &m$/	
 g&V&+#
O%& D!..#& &s   AA;;Bc                    | j                         5  | j                  j                  d       t        | |||      }t	        | t        |            }t        |      }|J t        |        ddd       t        |        S # 1 sw Y   xY w)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 ?
    rt   r4  N)	rR   r1   ry   r2  r   listr5  r   r   )r   r/  r0  r1  r   r6  r7  s          r   
generatev3r<  9  s    2 
 &m$/	
 d7m,V}}%& D!M!& &s   AB  B	c               '      K   | d   }| dd  }|5  |rt        | 5  d  d d d        nd  d d d        y # 1 sw Y   xY w# 1 sw Y   y xY ww)Nr   r   )nested)ctxsthisrests      r   r>  r>  e  sb     7D8D	       s-   AA5A	A>	AA
Ac                 0     j                         5   j                  j                  t        d      |t	        j
                  |      fz         t	        j                         } j                  j                  t        d      |t        d            }|j                  d       t               } j                  |j                         v rt        j                  d       j                  d      5   fd|j                         D        }t        | 5  t!        |      D ]  }t	        j"                  |d      }	||	   }
t	        j$                  |      }t	        j$                  |      }t	        j"                  ||      } j                  j&                  r4 j                  j)                  d	|	|t	        j
                  |      fz          |
|d
      5 }t	        j*                  ||      D ].  }|j-                  t/        |             |j1                  |       0 	 ddd        	 ddd        j3                  d       ddd       t	        j                         |z
  }|dk  rd} j                  j                  t        d      t	        j
                  |j4                        |t	        j
                  |j4                  |z        fz         |j7                          ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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   r   r  c              3   T   K   | ]  }|j                  j                         ! y wr   r   r1   .0r   r   s     r   	<genexpr>zconsumev2.<locals>.<genexpr>        NsC))$''2N   %(r      adding [%s] %s (%s)
r   rw   r   NTr   r   r   )rR   r1   rJ   r   r   rc   r   r   r   r  r   r  r	   r   r   r>  r   readexactlyuvarintdecodestreamr   ry   r|   r   r'   r   r\   posr   )r   r_   rb   filesizer   r   r   r?  r   r   r   namelendatalenr}   r   r   r   s   `                r   	consumev2rQ  q  s    
 <34$..234	

 

77''hKxak ( 
 	$ 88v}}&((L  h' 	1NfmmoND -y) -A**2q1C +C"66r:G"66r:G++B8Dww((4"D$..*ABC
 T4 -C%)%7%7'%J -E$..CJ.?IIe,-- ---, OO4O01	14 **,&a<G:;x||,x||g56	
 	y< <P- -- -	1 	1/< <sW   CL1"L B>K4A	K'K4'L BL'K1,K44K=9L  L		LLc                      j                         5  t        j                         }t        j                  |      } j                  j                  t        d      |z          j                  j                  t        d      |t        d            }|j                  d       d}t               } j                  |j                         v rt        j                  d       j                  d      5   fd|j                         D        }t        | 5  t!        |      D ]a  }t        j                  |      }	|	dk(  r4 j                  j"                  r j                  j%                  d|z         t!        |	      D ]  }t        j&                  |d	      }
||
   }t        j                  |      }t        j                  |      }t        j&                  ||      } j                  j"                  r8d
}||
|t        j(                  |      fz  } j                  j%                  |       ||z  } ||d      5 }t        j*                  ||      D ]  }|j-                  |        	 ddd        |j/                  d	       d 	 ddd        j1                  d       ddd       t        j                         |z
  }|dk  rd}t        d      }t        j(                  |      }t        j(                  ||z        }||||fz  } j                  j                  |       |j3                          ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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   r  c              3   T   K   | ]  }|j                  j                         ! y wr   rD  rE  s     r   rG  zconsumev3.<locals>.<genexpr>  rH  rI  s   entry with no files [%d]
r   rJ  r   rw   Nr   Tr   r   r   )rR   r   r   rL  r1   rJ   r   r   r   r  r   r  r	   r   r   r>  r   r   ry   rK  rc   r|   r   r   r\   r   )r   r_   r   
entrycountr   bytes_transferredr   r?  r   rb   r   r   rO  rP  r}   r   r   r   r   
byte_count	bytes_secs   `                    r   	consumev3rX    s    
 A

--b1
q45DE77''hK: ( 

 	$ 88v}}&((L  h' 	1NfmmoND /z* /A $ 8 8 <I A~77,, GGMM*G1*MN"9- 1"..r15$Sk"&":":2">"&":":2">#//G<77,,":CCt~~g/F#GGC GGMM#.)W4) t_ 1)-););Bg)N 1 #		% 011 11" &&A&.-//8 OO4O0=	1@ **,&a<G<=^^$56
NN#4w#>?	
GY//sCA A`1 1+/ /	1 	13A AsV   C!M 3"MD#M8.L;'MM!BM ;M MMMM	M  M)c                    ddl m} |D cg c]  }|| j                  vs| }}|r9t        j                  t        d      dj                  t        |            z        t        | |||       t        | j                  |      | _
        |j                  | j                  | j                  | j                        | j                  _        t!        j"                  |        t%        j&                  |        y c c}w Nr   rA   r   r#   )rF   rB   r4   r	   rO   r   r5   r6   rQ  r   r   rT   r1   rU   rV   rW   r   rX   r   rY   )r   r_   rb   rN  r   rB   rr>   s           r   applybundlev2r\     s    *Fat~~.E1FKFkkEFjj,-.
 	

 dB	8,5D "88""DMMDII !!$'%# Gs
   C4C4c                    ddl m} |D cg c]  }|| j                  vs| }}|r=t        d      }|dj	                  t        |            z  }t        j                  |      t        | |       t        | j                  |      | _
        |j                  | j                  | j                  | j                        | j                  _        t!        j"                  |        t%        j&                  |        y c c}w rZ  )rF   rB   r4   r   r5   r6   r	   rO   rX  r   r   rT   r1   rU   rV   rW   r   rX   r   rY   )r   r_   r   rB   r[  r>   r   s          r   applybundlev3r^    s    *Fat~~.E1FKFGHuzz&-..kk#dB5D "88""DMMDII !!$'%! Gs
   C6C6c                    dgfd}|D ]  \  }}| |   }||   }|j                  |      }	|j                  |      }
t        j                  j                  |
      }t        j                  j	                  |      st        j                  |       |j                  |       t        j                  |	|
d   |d       j                           d   S )NTc                  0    d d<   t        d      _        y )NFr   s   copying)r   topic)r   r   s   r   	copy_usedz_copy_files.<locals>.copy_used0  s    :r   r   F)r   no_hardlink_cbcheck_fs_hardlink)
r5   r   r   dirnamer-  r   makedirsregister_filecopyfiler   )src_vfs_mapdst_vfs_mapr   r   rb  r  r   src_vfsdst_vfssrc_pathdst_pathre  r   s      `        @r   _copy_filesro  -  s    vH'  4a.a.<<%<<% ''//(+ww~~g&MM'"d#a[$#	
 	'( A;r   c           
      J   | j                   D ch c]  }|t        j                  vr| }}|j                   D ch c]  }|t        j                  vr| }}||k(  sJ |j                         5  | j                         5  t	        j
                  |       }|j                  d      }d}t        j                  j                  |      rd}t        | ddd      }t        |      }t        |       }	t        |      }
t        d |D              |z   }| j                  j                  t!        d      |t!        d	      
      }|D cg c](  \  }}|j#                         D ]  }||j$                  f * }}}}t'        |	|
||      }|r<t	        j
                  |      }|j                  d      }t)        j*                  ||       ddd       j-                          rd}nd}| j                  j/                  |z         |j1                  d      5 }|j2                  j5                  |       ddd       t1        j6                  |j                  j8                  |j:                         ddd       yc c}w c c}w c c}}}w # 1 sw Y   xY w# 1 sw Y   cxY w# 1 sw Y   yxY w)zYcopy all content from one local repository to another

    This is useful for local clones	   bookmarksr   r   NTr4  c              3   T   K   | ]   }t        |d    j                                " yw)r   N)r'   r   )rF  r^   s     r   rG  zlocal_copy.<locals>.<genexpr>p  s     AAc!A$**,/As   &(s   linkings   files)ra  r   r   s   linked %d files
s   copied %d files
s
   localclone)r   r   WORKING_DIR_REQUIREMENTSrR   r   bookmarksvfsr5   r   r   r-  r2  r;  r  sumr1   r   r   r   r   ro  r   rh  r   ry   r   r   r   cleanup_undo_filesr2   vfs_map)src_repo	dest_repor[  src_store_requirementsdest_store_requirementssrc_book_vfssrcbookmarksbm_countr   ri  dest_vfs_maptotal_filesr   r  r^   r   r   r   dst_book_vfsdstbookmarksr   trs                         r   
local_copyr  K  s    &&O<<< 	
  ''O<<< 	
 
 "%<<<<		 9M]]_ ,	:
 %11(;L',,\:LHww~~l+#"&	G 7mG"8,K#I.LAAAHLK{{//
m!x[ 0 H #* GQ  !**++E 
 #;eXNH (55i@+00>lL9Y,	:Z 	&C&C#+,""=1 	&ROO!!"%	& 	&&y||'8'8):K:KLs9M 9M
RC,	: ,	:h	& 	&k9M 9Ms[   I0I5.J?CJ-I:1AJAJJ+<J:JJ
	JJ	JJ")F)NFF)r   )<
contextlibr   r   i18nr   
interfacesr   rF   r   r   r*   r   r	   r
   r   r   r   r   r   r   r   r   revlogutilsr   r   r   r?   rd   rk   rr   r   r   r   rS   r   r   r   _fileappendr   r	  r
  r   r   r   r  r  r   r   r   r2  r9  r<  contextmanagerr>  rQ  rX  r\  r^  ro  r  r   r   r   <module>r     s    	   "   

[|HV$L77t87tQ
h.8&.- - 	 		<0 0f
@EF2!j66%B/B)X  BJGT&.&,<IMr   