Ë
    ómxi<™  ã                   óˆ  — d Z ddlZddlmZmZmZmZ ddlmZm	Z	m
Z
mZ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 	 ddlmZ ddlmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z) dd	l*m+Z+ dd
l,m-Z- ddl.m/Z/ ddl0Z0ddl1Z1ddl2Z2ddl3Z3dZ4d„ Z5dd„Z6 G d„ d«      Z7 G d„ de	«      Z8 G d„ de	«      Z9 G d„ de	«      Z:y# e$ r Y Œ~w xY w)z3Contains PackIndexFile and PackFile implementationsé    N)Ú	BadObjectÚAmbiguousObjectNameÚUnsupportedOperationÚ
ParseError)ÚmmanÚ	LazyMixinÚunpack_fromÚ
bin_to_hexÚbyte_ord)Úcreate_pack_object_headerÚpack_object_header_infoÚis_equal_canonical_shaÚtype_id_to_type_mapÚwrite_objectÚstream_copyÚ
chunk_sizeÚdelta_typesÚ	OFS_DELTAÚ	REF_DELTAÚmsb_size©ÚPackIndexFile_sha_to_index)ÚOInfoÚOStreamÚ	OPackInfoÚOPackStreamÚODeltaStreamÚODeltaPackInfoÚODeltaPackStream)ÚDecompressMemMapReaderÚDeltaApplyReaderÚ
Sha1WriterÚ
NullStreamÚFlexibleSha1Writer)Úpack)Úcrc32)Ú	NULL_BYTE)ÚPackIndexFileÚPackFileÚ
PackEntityc                 óô  — | j                  |«      j                  «       }t        |«      \  }}}d}d}|t        k(  rM|}	t	        ||	   «      }
|	dz  }	|
dz  }|
dz  r)t	        ||	   «      }
|	dz  }	|dz  }|dz  |
dz  z   }|
dz  rŒ)|}|	}n|t
        k(  r|dz   }||| }n|}||z   }|r3t        ||d d|«      }|€|t        ||||«      fS |t        |||||«      fS |€|t        |||«      fS |t        ||||«      fS )a&  
    :return: Tuple(abs_data_offset, PackInfo|PackStream)
        an object of the correct type according to the type_id  of the object.
        If as_stream is True, the object will contain a stream, allowing  the
        data to be read decompressed.
    :param data: random accessible data containing all required information
    :parma offset: offset in to the data at which the object information is located
    :param as_stream: if True, a stream object will be returned that can read
        the data, otherwise you receive an info object onlyNé   é   é€   é   é   F)Ú
use_regionÚbufferr   r   r   r   r    r   r   r   r   )ÚcursorÚoffsetÚ	as_streamÚdataÚtype_idÚuncomp_sizeÚdata_rela_offsetÚtotal_rela_offsetÚ
delta_infoÚiÚcÚdelta_offsetÚabs_data_offsetÚstreams                 úA/home/htdocs/ttos/venv/lib/python3.12/site-packages/gitdb/pack.pyÚpack_object_atrB   L   sp  € ð ×Ñ˜VÓ$×+Ñ+Ó-€DÜ-DÀTÓ-JÑ*€Gˆ[Ð*ØÐØ€Jð ”)ÒØˆÜ�T˜!‘WÓˆØ	ˆQ‰ˆØ˜4‘xˆØ�$ŠhÜ˜˜a™Ó!ˆAØ�‰FˆAØ˜AÑˆLØ(¨AÑ-°!°d±(Ñ;ˆLð	 �$‹hð "ˆ
ØÑà	”IÒ	Ø,¨rÑ1ÐØÐ*Ð+<Ð=‰
ð -ÐàÐ0Ñ0€OÙÜ'¨Ð->Ð-?Ð(@À%ÈÓUˆØÐØ"¤K°¸ÀÈfÓ$UÐUÐUà"Ô$4°V¸WÀkÐS]Ð_eÓ$fÐfÐfàÐØ"¤I¨f°g¸{Ó$KÐKÐKà"¤N°6¸7ÀKÐQ[Ó$\Ð\Ð\ó    c                 óX  — d}d}|du}d}|r|}	  | t         «      }|t        |«      z  }|j                  |«      }	|t        |	«      z  } ||	«       |rt        |	|«      }t        |«      t         k7  rnŒc|j	                  «       }	|t        |	«      z  } ||	«       |rt        |	|«      }|||fS )a’  Copy a stream as read from read function, zip it, and write the result.
    Count the number of written bytes and return it
    :param base_crc: if not None, the crc will be the base for all compressed data
        we consecutively write and generate a crc32 from. If None, no crc will be generated
    :return: tuple(no bytes read, no bytes written, crc32) crc might be 0 if base_crc
        was falser   N)r   ÚlenÚcompressr&   Úflush)
ÚreadÚwriteÚzstreamÚbase_crcÚbrÚbwÚwant_crcÚcrcÚchunkÚ
compresseds
             rA   Úwrite_stream_to_packrR   ‚   sÍ   € ð 
€BØ	
€BØ˜tÐ#€HØ
€CÙØˆð Ù”ZÓ ˆØ
Œc�%‹jÑˆØ×%Ñ% eÓ,ˆ
Ø
Œc�*‹oÑˆÙˆjÔáÜ˜
 CÓ(ˆCô ˆu‹:œÒ#Øð ð —‘“€JØŒ#ˆj‹/Ñ€BÙ	ˆ*ÔÙÜ�J Ó$ˆð ��Cˆ=ÐrC   c                   ó&   — e Zd ZdZdZd„ Zd„ Zd„ Zy)ÚIndexWriterzœUtility to cache index information, allowing to write all information later
    in one go to the given stream
    **Note:** currently only writes v2 indicesÚ_objsc                 ó"   — t        «       | _        y ©N)ÚlistrU   ©Úselfs    rA   Ú__init__zIndexWriter.__init__´   s   € Ü“Vˆ�
rC   c                 ó@   — | j                   j                  |||f«       y)z&Append one piece of object informationN)rU   Úappend)rZ   ÚbinsharO   r4   s       rA   r]   zIndexWriter.append·   s   € à�
‰
×Ñ˜6 3¨Ð/Õ0rC   c                 óÒ  — | j                   j                  d„ ¬«       t        |«      }|j                  } |t        j
                  «        |t        dt        j                  «      «       t        d«      }| j                   D ]  }|t        |d   d   «      xx   dz  cc<   Œ  t        d«      D ])  }||   } |t        d|«      «       ||dz   xx   |z  cc<   Œ+  |t        d|d   «      «        |dj                  d	„ | j                   D «       «      «       | j                   D ]  } |t        d|d   d
z  «      «       Œ t        «       }| j                   D ]C  }|d   }	|	dkD  r"|j                  |	«       dt        |«      z   dz
  }	 |t        d|	d
z  «      «       ŒE |D ]  }	 |t        d|	«      «       Œ t        |«      dk(  sJ ‚ ||«       |j                  d¬«      }
 ||
«       |
S )zµWrite the index file using the given write method
        :param pack_sha: binary sha over the whole pack that we index
        :return: sha1 binary sha over all index file contentsc                 ó   — | d   S )Nr   © )Úos    rA   ú<lambda>z#IndexWriter.write.<locals>.<lambda>À   s
   €  a¨¡d€ rC   )Úkeyú>L(   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   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   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   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   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   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   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   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   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   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   r   r   r   r   r   r   r   r,   éÿ   rC   c              3   ó&   K  — | ]	  }|d    –— Œ y­w)r   Nra   )Ú.0Úts     rA   ú	<genexpr>z$IndexWriter.write.<locals>.<genexpr>Õ   s   è ø€ Ò4 A˜1˜Q�4Ñ4ùs   ‚ì   ÿÿ é   iÿÿÿì        ú>Qr0   F©Úas_hex)rU   Úsortr$   rI   r(   Úindex_v2_signaturer%   Úindex_version_defaultrX   r   ÚrangeÚjoinr]   rE   Úsha)rZ   Úpack_sharI   Ú
sha_writerÚ	sha_writeÚtmplistri   r<   ÚvÚofsrv   s              rA   rI   zIndexWriter.write»   sÞ  € ð
 	�
‰
�‰™NˆÔ+ä'¨Ó.ˆ
Ø×$Ñ$ˆ	Ù”-×2Ñ2Ô3Ù”$�tœ]×@Ñ@ÓAÔBô �zÓ"ˆØ—‘ò 	,ˆAØ”H˜Q˜q™T !™WÓ%Ó&¨!Ñ+Ô&ð	,ô �s“ò 	 ˆAØ˜‘
ˆAÙ”d˜4 “mÔ$Ø�A˜‘E‹N˜aÑŒNð	 ñ
 	”$�t˜W S™\Ó*Ô+ñ 	�#—(‘(Ñ4¨¯©Ô4Ó4Ô5ð —‘ò 	5ˆAÙ”d˜4  1¡¨
Ñ!2Ó3Õ4ð	5ô “&ˆà—‘ò 	4ˆAØ�A‘$ˆCØ�ZÒØ—‘˜sÔ#Ø ¤3 w£<Ñ/°!Ñ3�á”d˜4  zÑ!1Ó2Õ3ð	4ð ò 	'ˆCÙ”d˜4 “oÕ&ð	'ô
 �8‹} Ò"Ð#Ð"Ù�(ÔØ�n‰n EˆnÓ*ˆÙˆcŒ
Øˆ
rC   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r[   r]   rI   ra   rC   rA   rT   rT   ­   s   „ ñ2ð €Iòò1ó6rC   rT   c                   óÆ   ‡ — e Zd ZdZdZdZdZˆ fd„Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd e«       v rd„ Zˆ xZS ˆ xZS )r(   zmA pack index provides offsets into the corresponding pack, allowing to find
    locations for offsets faster.i  s   ÿtOcrl   c                 ó0   •— t         ‰| �  «        || _        y rW   )Úsuperr[   Ú
_indexpath)rZ   Ú	indexpathÚ	__class__s     €rA   r[   zPackIndexFile.__init__  s   ø€ Ü‰ÑÔØ#ˆ�rC   c                 óP   — t        j                  | j                  «       d | _        y rW   )r   Úforce_map_handle_removal_winr…   Ú_cursorrY   s    rA   ÚclosezPackIndexFile.close  s   € Ü×)Ñ)¨$¯/©/Ô:Øˆ�rC   c                 óˆ  — |dk(  r#| j                   j                  «       dd | _        y |dk(  r#| j                   j                  «       dd  | _        y |dk(  r¿t        j                  | j
                  «      j                  «       | _         t        j                  «       dkD  ru| j                   j                  «       t        j                  «       kD  rEt        d| j
                  | j                   j                  «       t        j                  «       fz  «      ‚y y | j                   j                  «       }|d d | j                  k(  xr dxs d	| _        | j                  dk(  r)t        d
|d«      d   }|| j                  k(  s
J d|z  «       ‚dD ](  }t        | |t        | d|| j                  fz  «      «       Œ* | j                  «        y )NÚ_packfile_checksuméØÿÿÿéìÿÿÿrŠ   r   zsThe index file at %s is too large to fit into a mapped window (%i > %i). This is a limitation of the implementationé   rl   r,   re   zUnsupported index version: %i)Úentryr4   rv   rO   z_%s_v%i)rŠ   Úmapr�   r   Úmake_cursorr…   r1   Úwindow_sizeÚ	file_sizeÚAssertionErrorrr   Ú_versionr	   ÚsetattrÚgetattrÚ_initialize)rZ   ÚattrÚmmapÚ
version_idÚfnames        rA   Ú_set_cache_zPackIndexFile._set_cache_  s¤  € ØÐ'Ò'Ø&*§l¡l×&6Ñ&6Ó&8¸¸SÐ&AˆDÕ#ØÐ)Ò)Ø&*§l¡l×&6Ñ&6Ó&8¸¸Ð&>ˆDÕ#Ø�YÒô  ×+Ñ+¨D¯O©OÓ<×GÑGÓIˆDŒLä×ÑÓ! AÒ%¨$¯,©,×*@Ñ*@Ó*BÄT×EUÑEUÓEWÒ*WÜ$ð  &[Ø—O‘O T§\¡\×%;Ñ%;Ó%=¼t×?OÑ?OÓ?Qð^Sñ &Só Tð Tð +XÐ%ð —<‘<×#Ñ#Ó%ˆDØ! " 1˜X¨×)@Ñ)@Ñ@ÒFÀQÒLÈ1ˆDŒMØ�}‰} Ò!Ü(¨¨t°QÓ7¸Ñ:�
Ø! T§]¡]Ò2Ð`Ð4SÐV`Ñ4`Ó`Ð2ð
 ;ò X�Ü˜˜e¤W¨T°9ÀÀtÇ}Á}Ð?UÑ3UÓ%VÕWðXð ×ÑÕrC   c                 ó^   — t        d| j                  j                  «       d|dz  z   «      dz   S )z!:return: tuple(offset, binsha, 0)z>L20sé   é   ©r   ©r	   rŠ   r’   ©rZ   r<   s     rA   Ú	_entry_v1zPackIndexFile._entry_v13  s+   € ä˜7 D§L¡L×$4Ñ$4Ó$6¸¸qÀ2¹v¹ÓFÈÑNÐNrC   c                 ó^   — t        d| j                  j                  «       d|dz  z   «      d   S )zsee ``_offset_v2``re   r¡   r¢   r   r¤   r¥   s     rA   Ú
_offset_v1zPackIndexFile._offset_v17  s+   € ä˜4 §¡×!1Ñ!1Ó!3°T¸AÀ¹F±]ÓCÀAÑFÐFrC   c                 óX   — d|dz  z   dz   }| j                   j                  «       ||dz    S )zsee ``_sha_v2``r¡   r¢   r�   r0   ©rŠ   r’   ©rZ   r<   Úbases      rA   Ú_sha_v1zPackIndexFile._sha_v1;  s2   € à�q˜2‘v‰ Ñ"ˆØ�|‰|×ÑÓ! $ t¨b¡yÐ1Ð1rC   c                  ó   — y)Úunsupportedr   ra   r¥   s     rA   Ú_crc_v1zPackIndexFile._crc_v1@  s   € àrC   c                 óf   — | j                  |«      | j                  |«      | j                  |«      fS )z#:return: tuple(offset, binsha, crc))Ú
_offset_v2Ú_sha_v2Ú_crc_v2r¥   s     rA   Ú	_entry_v2zPackIndexFile._entry_v2G  s(   € à—‘ Ó" D§L¡L°£O°T·\±\À!³_ÐEÐErC   c                 óö   — t        d| j                  j                  «       | j                  |dz  z   «      d   }|dz  r;t        d| j                  j                  «       | j                  |dz  dz  z   «      d   }|S )zŠ:return: 32 or 64 byte offset into pack files. 64 byte offsets will only
            be returned if the pack is larger than 4 GiB, or 2^32re   r�   r   rm   rn   lýÿÿÿ    é   )r	   rŠ   r’   Ú_pack_offsetÚ_pack_64_offset)rZ   r<   r4   s      rA   r²   zPackIndexFile._offset_v2K  s~   € ô ˜T 4§<¡<×#3Ñ#3Ó#5°t×7HÑ7HÈ1ÈqÉ5Ñ7PÓQÐRSÑTˆð
 �JÒÜ   t§|¡|×'7Ñ'7Ó'9¸4×;OÑ;OÐSYÐ\gÑSgÐklÑRlÑ;lÓmÐnoÑpˆFð ˆrC   c                 óf   — | j                   |dz  z   }| j                  j                  «       ||dz    S )z;:return: sha at the given index of this file index instancer0   )Ú_sha_list_offsetrŠ   r’   r«   s      rA   r³   zPackIndexFile._sha_v2Y  s4   € à×$Ñ$ q¨2¡vÑ-ˆØ�|‰|×ÑÓ! $ t¨b¡yÐ1Ð1rC   c                 ór   — t        d| j                  j                  «       | j                  |dz  z   «      d   S )z.:return: 4 bytes crc for the object at index ire   r�   r   )r	   rŠ   r’   Ú_crc_list_offsetr¥   s     rA   r´   zPackIndexFile._crc_v2^  s4   € ä˜4 §¡×!1Ñ!1Ó!3°T×5JÑ5JÈQÐQRÉUÑ5RÓSÐTUÑVÐVrC   c                 óN  — | j                  | j                  dk(  dz  «      | _        | j                  dk(  rp| j                  | j	                  «       dz  z   | _        | j
                  | j	                  «       dz  z   | _        | j                  | j	                  «       dz  z   | _        yy)zinitialize base datarl   r·   r0   r�   N)Ú_read_fanoutr—   Ú_fanout_tabler»   Úsizer½   r¸   r¹   rY   s    rA   rš   zPackIndexFile._initializef  sŒ   € à!×.Ñ.°·±ÀÑ0BÀaÑ/GÓHˆÔà�=‰=˜AÒØ$(×$9Ñ$9¸D¿I¹I»KÈ"Ñ<LÑ$LˆDÔ!Ø $× 5Ñ 5¸¿	¹	»Àa¹Ñ GˆDÔØ#'×#4Ñ#4°t·y±y³{ÀQ±Ñ#FˆDÕ ð rC   c           
      ó¾   — | j                   j                  «       }t        «       }|j                  }t	        d«      D ]  } |t        d|||dz  z   «      d   «       Œ  |S )z%Generate a fanout table from our dataé   re   r�   r   )rŠ   r’   rX   r]   rt   r	   )rZ   Úbyte_offsetÚdÚoutr]   r<   s         rA   r¿   zPackIndexFile._read_fanoutp  s_   € à�L‰L×ÑÓˆÜ‹fˆØ—‘ˆÜ�s“ò 	AˆAÙ”;˜t Q¨°a¸!±eÑ(;Ó<¸QÑ?Õ@ð	Að ˆ
rC   c                 ó   — | j                   S rW   ©r—   rY   s    rA   ÚversionzPackIndexFile.version}  s   € Ø�}‰}ÐrC   c                 ó    — | j                   d   S )z4:return: amount of objects referred to by this indexrf   )rÀ   rY   s    rA   rÁ   zPackIndexFile.size€  s   € à×!Ñ! #Ñ&Ð&rC   c                 ó   — | j                   S )z":return: path to the packindexfile)r…   rY   s    rA   ÚpathzPackIndexFile.path„  s   € à�‰ÐrC   c                 ó<   — | j                   j                  «       dd S )z@:return: 20 byte sha representing the sha1 hash of the pack filerŽ   r�   rª   rY   s    rA   Úpackfile_checksumzPackIndexFile.packfile_checksumˆ  s   € à�|‰|×ÑÓ! # cÐ*Ð*rC   c                 ó<   — | j                   j                  «       dd S )zB:return: 20 byte sha representing the sha1 hash of this index filer�   Nrª   rY   s    rA   Úindexfile_checksumz PackIndexFile.indexfile_checksumŒ  s   € à�|‰|×ÑÓ! # $Ð'Ð'rC   c                 ól  ‡ — ‰ j                   dk(  rzt        j                  d«      }|j                  ‰ j                  j	                  «       ‰ j
                  ‰ j                   «       t        j                  dk(  r|j                  «        |S t        ˆ fd„t        ‰ j                  «       «      D «       «      S )z–:return: sequence of all offsets in the order in which they were written

        **Note:** return value can be random accessed, but may be immmutablerl   ÚIÚlittlec              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wrW   )r4   )rh   ÚindexrZ   s     €rA   rj   z(PackIndexFile.offsets.<locals>.<genexpr>ž  s   øè ø€ ÒL°˜Ÿ™ U×+ÑLùs   ƒ)r—   ÚarrayÚ	frombytesrŠ   r’   r¸   r¹   ÚsysÚ	byteorderÚbyteswapÚtuplert   rÁ   )rZ   Úas   ` rA   ÚoffsetszPackIndexFile.offsets�  sƒ   ø€ ð �=‰=˜AÒä—‘˜CÓ ˆAØ�K‰K˜Ÿ™×(Ñ(Ó*¨4×+<Ñ+<¸T×=QÑ=QÐRÔSô �}‰} Ò(Ø—
‘
”ØˆHäÓL¼¸t¿y¹y»{Ó9KÔLÓLÐLrC   c                 óæ   — t        |d   «      }| j                  }d}|dk7  r| j                  |dz
     }| j                  |   }||k  r*||z   dz  } ||«      }||k  r|}n||k(  r|S |dz   }||k  rŒ*y)z±
        :return: index usable with the ``offset`` or ``entry`` method, or None
            if the sha was not found in this pack index
        :param sha: 20 byte sha to lookupr   r,   rl   N)r   rv   rÀ   )rZ   rv   Ú
first_byteÚget_shaÚloÚhiÚmidÚmid_shas           rA   Úsha_to_indexzPackIndexFile.sha_to_index¡  s™   € ô
 ˜c !™fÓ%ˆ
Ø—(‘(ˆØˆØ˜Š?Ø×#Ñ# J°¡NÑ3ˆBØ×Ñ 
Ñ+ˆð �2ŠgØ˜‘7˜q‘.ˆCÙ˜c“lˆGØ�WŠ}Ø‘Ø˜’Ø�
à˜1‘W�ð �2‹gð rC   c                 ó6  — t        |«      dk  rt        d«      ‚t        |t        «      sJ d«       ‚t	        |d   «      }| j
                  }d}|dk7  r| j                  |dz
     }| j                  |   }|t        dt        |«      z
  z  z   }||k  r+||z   dz  } ||«      }	||	k  r|}n||	k(  r|}n|dz   }||k  rŒ+|| j                  «       k  rL ||«      }
t        |||
«      r7d}|dz   | j                  «       k  r ||dz   «      }|r||
k(  rt        |«      ‚|S y)af  
        :return: index as in `sha_to_index` or None if the sha was not found in this
            index file
        :param partial_bin_sha: an at least two bytes of a partial binary sha as bytes
        :param canonical_length: length of the original hexadecimal representation of the
            given partial binary sha
        :raise AmbiguousObjectName:rl   z'Require at least 2 bytes of partial shazpartial_bin_sha must be bytesr   r,   r0   N)rE   Ú
ValueErrorÚ
isinstanceÚbytesr   rv   rÀ   r'   rÁ   r   r   )rZ   Úpartial_bin_shaÚcanonical_lengthrß   rà   rá   râ   Ú
filled_sharã   rä   Úcur_shaÚnext_shas               rA   Úpartial_sha_to_indexz"PackIndexFile.partial_sha_to_index»  sM  € ô ˆÓ !Ò#ÜÐFÓGÐGä˜/¬5Ô1ÐRÐ3RÓRÐ1Ü˜o¨aÑ0Ó1ˆ
à—(‘(ˆØˆØ˜Š?Ø×#Ñ# J°¡NÑ3ˆBØ×Ñ 
Ñ+ˆð %¤y°B¼¸_Ó9MÑ4MÑ'NÑNˆ
ð �2ŠgØ˜‘7˜q‘.ˆCÙ˜c“lˆGØ˜GÒ#Ø‘Ø˜wÒ&à�Øà˜1‘W�ð �2‹gð �—	‘	“ÒÙ˜b“kˆGÜ%Ð&6¸ÈÔQØ�Ø˜‘6˜DŸI™I›KÒ'Ù& r¨A¡v›�HÙ ¨GÒ 3Ü-¨oÓ>Ð>Ø�	ð rC   r   c                 ó   — t        | |«      S rW   r   ©rZ   rv   s     rA   rå   zPackIndexFile.sha_to_indexñ  s   € Ü-¨d°CÓ8Ð8rC   )r}   r~   r   r€   r»   rr   rs   r[   r‹   rŸ   r¦   r¨   r­   r°   rµ   r²   r³   r´   rš   r¿   rÉ   rÁ   rÌ   rÎ   rÐ   rÝ   rå   rï   ÚglobalsÚ__classcell__)r‡   s   @rA   r(   r(   ô   s£   ø„ ñ%ð  ÐØ#ÐØÐô$òò#òPOòGò2ò
òFòò2ò
WòGòòò'òò+ò(òMò"ò41ðf $¡w£yÑ0ö	9ó 1rC   r(   c                   óv   — e Zd ZdZdZdZdZdZdZd„ Z	d„ Z
d	„ Zdd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zy)r)   aë  A pack is a file written according to the Version 2 for git packs

    As we currently use memory maps, it could be assumed that the maximum size of
    packs therefore is 32 bit on 32 bit systems. On 64 bit systems, this should be
    fine though.

    **Note:** at some point, this might be implemented using streams as well, or
    streams are an alternate path in the case memory maps cannot be created
    for some reason - one clearly doesn't want to read 10GB at once in that
    case)Ú	_packpathrŠ   Ú_sizer—   iKCAPrl   é   r0   c                 ó   — || _         y rW   ©rõ   )rZ   Úpackpaths     rA   r[   zPackFile.__init__  s	   € Ø!ˆ�rC   c                 óP   — t        j                  | j                  «       d | _        y rW   )r   r‰   rõ   rŠ   rY   s    rA   r‹   zPackFile.close  s   € Ü×)Ñ)¨$¯.©.Ô9Øˆ�rC   c                 ó  — t        j                  | j                  «      j                  «       | _        t        d| j                  j                  «       d«      \  }| _        | _        || j                  k7  rt        d|z  «      ‚y )Nú>LLLr   zInvalid pack signature: %i)r   r“   rõ   r1   rŠ   r	   r’   r—   rö   Úpack_signaturer   )rZ   r›   r7   s      rA   rŸ   zPackFile._set_cache_  sp   € ä×'Ñ'¨¯©Ó7×BÑBÓDˆŒô .9¸ÀÇÁ×AQÑAQÓASÐUVÓ-WÑ*ˆ�” ¤
ð �d×)Ñ)Ò)ÜÐ9¸GÑCÓDÐDð *rC   c              #   ó  K  — | j                   }|j                  «       | j                  z
  }|xs | j                  }t	        «       }||k  rºt        ||d«      \  }}t        |j                  |j                  |j                  t        «       |j                  j                  |j                  k(  sJ ‚|||j                  z
  |j                  j                  «       z   z  }|r|j                  j                  d«       |–— ||k  rŒ¹yy­w)z7Handle the actual iteration of objects within this packTr   N)rŠ   r•   Úfooter_sizeÚfirst_object_offsetr#   rB   r   rH   rI   rÁ   r   r@   Ú_brÚpack_offsetÚcompressed_bytes_readÚseek)	rZ   Ústart_offsetr5   r=   Úcontent_sizeÚ
cur_offsetÚnullÚdata_offsetÚostreams	            rA   Ú_iter_objectszPackFile._iter_objects   sÜ   è ø€ à�L‰LˆØ—{‘{“} t×'7Ñ'7Ñ7ˆØ!Ò= T×%=Ñ%=ˆ
ä‹|ˆØ˜<Ò'Ü#1°!°ZÀÓ#FÑ ˆK˜ô ˜Ÿ™ d§j¡j°'·,±,Ä
ÔKØ—>‘>×%Ñ%¨¯©Ò5Ð5Ð5Ø˜;¨×)<Ñ)<Ñ<ÀÇÁ×@dÑ@dÓ@fÑfÑfˆJñ
 Ø—‘×#Ñ# AÔ&ØŠMð ˜<Õ'ùs   ‚DDÄDc                 ó   — | j                   S )z2:return: The amount of objects stored in this pack)rö   rY   s    rA   rÁ   zPackFile.size:  ó   € à�z‰zÐrC   c                 ó   — | j                   S )z!:return: the version of this packrÈ   rY   s    rA   rÉ   zPackFile.version>  s   € à�}‰}ÐrC   c                 óR   — | j                   j                  «       j                  «       S )zð
        :return: read-only data of this pack. It provides random access and usually
            is a memory map.
        :note: This method is unsafe as it returns a window into a file which might be larger than than the actual window size)rŠ   r1   r’   rY   s    rA   r6   zPackFile.dataB  s    € ð �|‰|×&Ñ&Ó(×,Ñ,Ó.Ð.rC   c                 ó�   — | j                   j                  | j                   j                  «       dz
  «      j                  «       dd S )zE:return: 20 byte sha1 hash on all object sha's contained in this filer0   N)rŠ   r1   r•   r2   rY   s    rA   ÚchecksumzPackFile.checksumJ  s7   € à�|‰|×&Ñ& t§|¡|×'=Ñ'=Ó'?À"Ñ'DÓE×LÑLÓNÉqÐQÐQrC   c                 ó   — | j                   S )z:return: path to the packfilerù   rY   s    rA   rÌ   zPackFile.pathN  s   € à�~‰~ÐrC   c                 óÔ   — t        «       }| j                  }	 t        ||d«      d   }|j                  |«       |j                  t
        k(  r|j                  |j                  z
  }n	 |S ŒR)a  
        :return: list of pack streams which are required to build the object
            at the given offset. The first entry of the list is the object at offset,
            the last one is either a full object, or a REF_Delta stream. The latter
            type needs its reference object to be locked up in an ODB to form a valid
            delta chain.
            If the object at offset is no delta, the size of the list is 1.
        :param offset: specifies the first byte of the object within this packTr,   )rX   rŠ   rB   r]   r7   r   r  r;   )rZ   r4   rÆ   r=   r  s        rA   Úcollect_streamszPackFile.collect_streamsU  si   € ô ‹fˆØ�L‰LˆØÜ$ Q¨°Ó5°aÑ8ˆGØ�J‰J�wÔØ�‰¤)Ò+Ø ×,Ñ,¨w×/AÑ/AÑA‘ð
 ð ˆ
ð rC   c                 óR   — t        | j                  |xs | j                  d«      d   S )zËRetrieve information about the object at the given file-absolute offset

        :param offset: byte offset
        :return: OPackInfo instance, the actual type differs depending on the type_id attributeFr,   ©rB   rŠ   r  ©rZ   r4   s     rA   ÚinfozPackFile.infor  s)   € ô
 ˜dŸl™l¨FÒ,N°d×6NÑ6NÐPUÓVÐWXÑYÐYrC   c                 óR   — t        | j                  |xs | j                  d«      d   S )zßRetrieve an object at the given file-relative offset as stream along with its information

        :param offset: byte offset
        :return: OPackStream instance, the actual type differs depending on the type_id attributeTr,   r  r  s     rA   r@   zPackFile.streamy  s)   € ô
 ˜dŸl™l¨FÒ,N°d×6NÑ6NÐPTÓUÐVWÑXÐXrC   c                 ó(   — | j                  |d¬«      S )a¤  
        :return: iterator yielding OPackStream compatible instances, allowing
            to access the data in the pack directly.
        :param start_offset: offset to the first object to iterate. If 0, iteration
            starts at the very first object in the pack.

        **Note:** Iterating a pack directly is costly as the datastream has to be decompressed
        to determine the bounds between the objectsT©r5   ©r  )rZ   r  s     rA   Ústream_iterzPackFile.stream_iter€  s   € ð ×!Ñ! ,¸$Ð!Ó?Ð?rC   N)Tr£   )r}   r~   r   r€   r�   rþ   Úpack_version_defaultr  r   r[   r‹   rŸ   r  rÁ   rÉ   r6   r  rÌ   r  r  r@   r  ra   rC   rA   r)   r)   ø  sl   „ ñ	ð >€IØ€NØÐð  ÐØ€Kò"òò
Eóò4òò/òRòòò:ZòYô	@rC   r)   c                   óÜ   — e Zd ZdZdZeZeZd„ Z	d„ Z
d„ Zd„ Zd„ Zdd„Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zeddej8                  fd„«       Zedej8                  fd„«       Zy)r*   zqCombines the PackIndexFile and the PackFile into one, allowing the
    actual objects to be resolved and iterated)Ú_indexÚ_packÚ_offset_mapc                 ó¬   — t         j                  j                  |«      \  }}| j                  d|z  «      | _        | j                  d|z  «      | _        y)zGInitialize ourselves with the path to the respective pack or index filez%s.idxz%s.packN)ÚosrÌ   ÚsplitextÚIndexFileClsr!  ÚPackFileClsr"  )rZ   Úpack_or_index_pathÚbasenameÚexts       rA   r[   zPackEntity.__init__›  sI   € äŸ™×(Ñ(Ð);Ó<‰ˆ�#Ø×'Ñ'¨°8Ñ(;Ó<ˆŒØ×%Ñ% i°(Ñ&:Ó;ˆ�
rC   c                 ól   — | j                   j                  «        | j                  j                  «        y rW   )r!  r‹   r"  rY   s    rA   r‹   zPackEntity.close¡  s"   € Ø�‰×ÑÔØ�
‰
×ÑÕrC   c                 óœ  — t        | j                  j                  «       «      }t        | j                  j                  «       «      | j                  j                  z
  }|sJ d«       ‚d }t        |«      dk(  r|d   |i}|| _        y t        |«      }t        |«      }t        |«       t        ||«      }t        |«      }|||d   <   || _        y )NzCannot handle empty indicesr,   r   éÿÿÿÿ)Úsortedr!  rÝ   rE   r"  r6   r   ÚiterÚnextÚzipÚdictr#  )rZ   r›   Úoffsets_sortedÚlast_offsetÚ
offset_mapÚiter_offsetsÚiter_offsets_plus_oneÚconsecutives           rA   rŸ   zPackEntity._set_cache_¥  sÈ   € ô
   §¡× 3Ñ 3Ó 5Ó6ˆÜ˜$Ÿ*™*Ÿ/™/Ó+Ó,¨t¯z©z×/EÑ/EÑEˆÙÐ<Ð<Ó<ˆ~àˆ
Üˆ~Ó !Ò#Ø(¨Ñ+¨[Ð9ˆJð &ˆÕô   Ó/ˆLÜ$(¨Ó$8Ð!ÜÐ&Ô'Ü˜lÐ,AÓBˆKä˜kÓ*ˆJð .9ˆJ�~ bÑ)Ñ*à%ˆÕrC   c                 óV   — | j                   j                  |«      }|€t        |«      ‚|S )z*:return: index for the given sha, or raise)r!  rå   r   )rZ   rv   rÕ   s      rA   Ú_sha_to_indexzPackEntity._sha_to_index¾  s*   € à—‘×(Ñ(¨Ó-ˆØˆ=Ü˜C“.Ð ØˆrC   c              #   óÄ   K  — | j                   j                  }| j                  }t        | j                   j	                  «       «      D ]  } | ||«      ||«      –— Œ y­w)zPIterate over all objects in our index and yield their OInfo or OStream instencesN)r!  rv   Ú_objectrt   rÁ   )rZ   r5   Ú_shar=  rÕ   s        rA   r  zPackEntity._iter_objectsÅ  sP   è ø€ à�{‰{�‰ˆØ—,‘,ˆÜ˜4Ÿ;™;×+Ñ+Ó-Ó.ò 	9ˆEÙ™$˜u›+ y°%Ó8Ó8ñ	9ùs   ‚AA c                 ón  — |dk  r| j                  |«      }|€| j                  j                  |«      }| j                  j                  |«      }t	        | j
                  j                  j                  |«      j                  «       «      \  }}}|r�|t        vrG| j
                  j                  |«      }t        ||j                  |j                  |j                  «      S | j                  |«      }	t        j                   |	«      }
t#        ||
j                  d|
«      S |t        vrt%        |t&        |   |«      S | j                  |«      }	|	d   j)                  d«      }t+        |«      \  }}t+        ||«      \  }}|	d   j,                  t        v rt/        |d«      ‚t%        ||	d   j                  |«      S )zž:return: OInfo or OStream object providing information about the given sha
        :param index: if not -1, its assumed to be the sha's index in the IndexFiler   Ni   r.  zCould not resolve delta object)r;  r!  rv   r4   r   r"  rŠ   r1   r2   r   r@   r   ÚtyperÁ   Úcollect_streams_at_offsetr!   Únewr   r   r   rH   r   r7   r   )rZ   rv   r5   rÕ   r4   r7   r8   r9   Ú
packstreamÚstreamsÚdstreamÚbufÚsrc_sizeÚtarget_sizes                 rA   r=  zPackEntity._objectÍ  s‡  € ð �1Š9Ø×&Ñ& sÓ+ˆEØˆ;Ø—+‘+—/‘/ %Ó(ˆCà—‘×#Ñ# EÓ*ˆÜ1HÈÏÉ×I[ÑI[×IfÑIfÐgmÓIn×IuÑIuÓIwÓ1xÑ.ˆ�Ð.ÙØœkÑ)Ø!ŸZ™Z×.Ñ.¨vÓ6�
Ü˜s J§O¡O°Z·_±_Àj×FWÑFWÓXÐXð ×4Ñ4°VÓ<ˆGÜ&×*Ñ*¨7Ó3ˆGä  W§\¡\°4¸ÓAÐAàœkÑ)Ü˜SÔ"5°gÑ">ÀÓLÐLð
 ×4Ñ4°VÓ<ˆGØ˜!‘*—/‘/ #Ó&ˆCÜ'¨›}ÑˆF�HÜ"*¨3°Ó"7ÑˆF�Kð �r‰{×"Ñ"¤kÑ1Ü Ð%EÓFÐFÜ˜˜g b™k×.Ñ.°Ó<Ð<rC   c                 ó&   — | j                  |d«      S )z¯Retrieve information about the object identified by the given sha

        :param sha: 20 byte sha1
        :raise BadObject:
        :return: OInfo instance, with 20 byte shaF©r=  rñ   s     rA   r  zPackEntity.infoù  s   € ð �|‰|˜C Ó'Ð'rC   c                 ó&   — | j                  |d«      S )zÃRetrieve an object stream along with its information as identified by the given sha

        :param sha: 20 byte sha1
        :raise BadObject:
        :return: OStream instance, with 20 byte shaTrJ  rñ   s     rA   r@   zPackEntity.stream  s   € ð �|‰|˜C Ó&Ð&rC   c                 ó(   — | j                  dd|«      S )zMAs ``info``, but uses a PackIndexFile compatible index to refer to the objectNFrJ  ©rZ   rÕ   s     rA   Úinfo_at_indexzPackEntity.info_at_index	  s   € à�|‰|˜D %¨Ó/Ð/rC   c                 ó(   — | j                  dd|«      S )zWAs ``stream``, but uses a PackIndexFile compatible index to refer to the
        objectNTrJ  rM  s     rA   Ústream_at_indexzPackEntity.stream_at_index  s   € ð �|‰|˜D $¨Ó.Ð.rC   c                 ó   — | j                   S )z*:return: the underlying pack file instance)r"  rY   s    rA   r%   zPackEntity.pack  r  rC   c                 ó   — | j                   S )z0:return: the underlying pack index file instance)r!  rY   s    rA   rÕ   zPackEntity.index  s   € à�{‰{ÐrC   c                 óÚ  — |rë| j                   j                  «       dk  rt        d«      ‚| j                  |«      }| j                   j	                  |«      }| j
                  |   }| j                   j                  |«      }t        j                  }| j                  j                  «       }|}	d}
|	|k  r2t        |	t        z   |«      }||	z
  } |||	|	|z    |
«      }
|	|z  }	|	|k  rŒ2|
dz  |k(  S t        «       }| j                  |d¬«      }t        |j                   |j"                  |j$                  |j&                  «       |j)                  d¬«      |k(  sJ ‚|j)                  d¬«      |k(  S )	a€  
        Verify that the stream at the given sha is valid.

        :param use_crc: if True, the index' crc is run over the compressed stream of
            the object, which is much faster than checking the sha1. It is also
            more prone to unnoticed corruption or manipulation.
        :param sha: 20 byte sha1 of the object whose stream to verify
            whether the compressed stream of the object is valid. If it is
            a delta, this only verifies that the delta's data is valid, not the
            data of the actual undeltified object, as it depends on more than
            just this stream.
            If False, the object will be decompressed and the sha generated. It must
            match the given sha

        :return: True if the stream is valid
        :raise UnsupportedOperation: If the index is version 1 only
        :raise BadObject: sha was not foundrl   z=Version 1 indices do not contain crc's, verify by sha insteadr   rk   Tr  Fro   )r!  rÉ   r   r;  r4   r#  rO   Úzlibr&   r"  r6   Úminr   r"   r=  r   r@  rÁ   rH   rI   rv   )rZ   rv   Úuse_crcrÕ   r4   Únext_offsetÚ	crc_valueÚ
crc_updateÚ	pack_dataÚcur_posÚthis_crc_valueÚrboundrÁ   Ú	shawriterr@   s                  rA   Úis_valid_streamzPackEntity.is_valid_stream  sZ  € ñ$ Ø�{‰{×"Ñ"Ó$ qÒ(Ü*Ð+jÓkÐkð ×&Ñ& sÓ+ˆEØ—[‘[×'Ñ'¨Ó.ˆFØ×*Ñ*¨6Ñ2ˆKØŸ™Ÿ™¨Ó.ˆIô Ÿ™ˆJØŸ
™
Ÿ™Ó)ˆIØˆGØˆNØ˜KÒ'Ü˜W¤zÑ1°;Ó?�Ø Ñ'�Ù!+¨I°g¸gÈ¹nÐ,MÈ~Ó!^�Ø˜4‘�ð	 ˜KÓ'ð # ZÑ/°IÑ=Ð=ä"›ˆIØ—\‘\ #°�\Ó6ˆFä˜Ÿ™ f§k¡k°6·;±;À	ÇÁÔPà—=‘=¨�=Ó.°#Ò5Ð5Ð5Ø—=‘=¨�=Ó.°#Ñ5Ð5rC   c                 ó&   — | j                  d¬«      S )zi
        :return: Iterator over all objects in this pack. The iterator yields
            OInfo instancesFr  r  rY   s    rA   Ú	info_iterzPackEntity.info_iterU  s   € ð ×!Ñ!¨EÐ!Ó2Ð2rC   c                 ó&   — | j                  d¬«      S )zk
        :return: iterator over all objects in this pack. The iterator yields
            OStream instancesTr  r  rY   s    rA   r  zPackEntity.stream_iter[  s   € ð ×!Ñ!¨DÐ!Ó1Ð1rC   c                 óÐ  — | j                   j                  |«      }|d   j                  t        k(  �r3|d   }|j                  t        v �r|j                  t        k(  r¾t        |j                  t        «      r4| j                  j                  |j                  j                  «       «      }n%| j                  j                  |j                  «      }|€	 |S | j                   j                  | j                  j                  |«      «      }|j                  |«       n6| j                   j                  |j                  «      }|j                  |«       |j                  t        v r�Œ|S )zÖ
        As the version in the PackFile, but can resolve REF deltas within this pack
        For more info, see ``collect_streams``

        :param offset: offset into the pack file at which the object can be foundr.  )r"  r  r7   r   r   rè   r;   Ú
memoryviewr!  rå   Útobytesr@   r4   r]   )rZ   r4   rD  r@   Úsindexs        rA   rA  z$PackEntity.collect_streams_at_offseta  s  € ð —*‘*×,Ñ,¨VÓ4ˆð �2‰;×Ñ¤)Ó+Ø˜R‘[ˆFØ—.‘.¤KÒ/Ø—>‘>¤YÒ.ä! &×"3Ñ"3´ZÔ@Ø!%§¡×!9Ñ!9¸&×:KÑ:K×:SÑ:SÓ:UÓ!V™à!%§¡×!9Ñ!9¸&×:KÑ:KÓ!L˜Ø�~Øð ˆð "ŸZ™Z×.Ñ.¨t¯{©{×/AÑ/AÀ&Ó/IÓJ�FØ—N‘N 6Õ*ð
 "ŸZ™Z×.Ñ.¨v×/@Ñ/@ÓA�FØ—N‘N 6Ô*ð! —.‘.¤KÓ/ð* ˆrC   c                 ót   — | j                  | j                  j                  | j                  |«      «      «      S )ab  
        As ``PackFile.collect_streams``, but takes a sha instead of an offset.
        Additionally, ref_delta streams will be resolved within this pack.
        If this is not possible, the stream will be left alone, hence it is adivsed
        to check for unresolved ref-deltas and resolve them before attempting to
        construct a delta stream.

        :param sha: 20 byte sha1 specifying the object whose related streams you want to collect
        :return: list of streams, first being the actual object delta, the last being
            a possibly unresolved base object.
        :raise BadObject:)rA  r!  r4   r;  rñ   s     rA   r  zPackEntity.collect_streams„  s0   € ð ×-Ñ-¨d¯k©k×.@Ñ.@À×ASÑASÐTWÓAXÓ.YÓZÐZrC   Nc                 óŒ  — |}|s,t        |t        t        f«      st        |«      }t        |«      }t	        |«      }|j
                  }d}	d}
|du} |t        dt        j                  t        j                  |«      «       |	dz  }	|r
t        «       }
d}|D ]Ç  }|dz  }d}t        |j                  |j                  «      }|rt        |«      }nd} ||«       t        j                   |«      }|j"                  }t%        |j&                  |||¬«      \  }}}||j                  k(  sJ ‚|r|
j)                  |j*                  ||	«       |	t        |«      |z   z  }	||k(  sŒÇ n ||k7  rt-        d||fz  «      ‚|j/                  d¬	«      }t        |«      d
k(  sJ ‚ ||«       |	t        |«      z  }	d}|r|
j                  ||«      }||fS )a®  
        Create a new pack by putting all objects obtained by the object_iterator
        into a pack which is written using the pack_write method.
        The respective index is produced as well if index_write is not Non.

        :param object_iter: iterator yielding odb output objects
        :param pack_write: function to receive strings to write into the pack stream
        :param indx_write: if not None, the function writes the index file corresponding
            to the pack.
        :param object_count: if you can provide the amount of objects in your iteration,
            this would be the place to put it. Otherwise we have to pre-iterate and store
            all items into a list to get the number, which uses more memory than necessary.
        :param zlib_compression: the zlib compression level to use
        :return: tuple(pack_sha, index_binsha) binary sha over all the contents of the pack
            and over all contents of the index. If index_write was None, index_binsha will be None

        **Note:** The destination of the write functions is up to the user. It could
        be a socket, or a file for instance

        **Note:** writes only undeltified objectsr   Nrý   r÷   r,   )rK   zKExpected to write %i objects into pack, but received only %i from iteratorsFro   r0   )rè   rÛ   rX   rE   r$   rI   r%   r)   rþ   r  rT   r   r7   rÁ   r&   rT  Úcompressobjr@   rR   rH   r]   r^   rç   rv   )ÚclsÚobject_iterÚ
pack_writeÚindex_writeÚobject_countÚzlib_compressionÚobjsÚpack_writerÚpwriter|   rÕ   Úwants_indexÚactual_countÚobjrO   ÚhdrrJ   r  rL   rM   rw   Ú	index_shas                         rA   Ú
write_packzPackEntity.write_pack’  sä  € ð. ˆÙÜ˜k¬E´4¨=Ô9Ü˜KÓ(�ä˜t›9ˆLô )¨Ó4ˆØ×"Ñ"ˆØˆØˆØ!¨Ð-ˆñ 	Œt�FœH×3Ñ3´X×5RÑ5RÐT`ÓaÔbØˆr‰	ˆáÜ“MˆEð ˆØò 	ˆCØ˜AÑˆLØˆCô ,¨C¯K©K¸¿¹ÓBˆCÙÜ˜C“j‘à�á�3ŒKô ×&Ñ&Ð'7Ó8ˆGØ—j‘jˆGÜ.¨w¯|©|¸VÀWÐWZÔ[‰KˆB��CØ˜Ÿ™’>Ð"�>ÙØ—‘˜SŸZ™Z¨¨cÔ2ð ”3�s“8˜b‘=Ñ ˆCØ˜|Ó+Ùð1	ð8 ˜<Ò'ÜØ]ÐamÐo{Ð`|Ñ|ó~ð ~ð
 —?‘?¨%�?Ó0ˆÜ�8‹} Ò"Ð"Ð"Ù�8ÔØŒs�8‹}Ñˆàˆ	ÙØŸ™ H¨kÓ:ˆIð ˜Ð"Ð"rC   c                 ó*  ‡‡— t        j                  dd|«      \  Š}t        j                  dd|«      \  Š}ˆfd„}ˆfd„}| j                  |||||«      \  }	}
t        j                  ‰«       t        j                  ‰«       d}t        j
                  j                  ||t        |	«      dfz  «      }t        j
                  j                  ||t        |	«      dfz  «      }t        j                  ||«       t        j                  ||«        | |«      S )aœ  Create a new on-disk entity comprised of a properly named pack file and a properly named
        and corresponding index file. The pack contains all OStream objects contained in object iter.
        :param base_dir: directory which is to contain the files
        :return: PackEntity instance initialized with the new pack

        **Note:** for more information on the other parameters see the write_pack methodÚ r%   rÕ   c                 ó0   •— t        j                  ‰| «      S rW   ©r%  rI   )rÅ   Úpack_fds    €rA   rc   z#PackEntity.create.<locals>.<lambda>ø  s   ø€ œrŸx™x¨°Ó3€ rC   c                 ó0   •— t        j                  ‰| «      S rW   r|  )rÅ   Úindex_fds    €rA   rc   z#PackEntity.create.<locals>.<lambda>ù  s   ø€ ¤§¡¨°1Ó 5€ rC   z
pack-%s.%sÚidx)	ÚtempfileÚmkstemprx  r%  r‹   rÌ   ru   r
   Úrename)rj  rk  Úbase_dirrn  ro  Ú	pack_pathÚ
index_pathrl  rm  Úpack_binshaÚindex_binshaÚfmtÚnew_pack_pathÚnew_index_pathr  r}  s                 @@rA   ÚcreatezPackEntity.createî  sé   ù€ ô &×-Ñ-¨b°&¸(ÓCÑˆ�Ü'×/Ñ/°°G¸XÓFÑˆ�*Û3ˆ
Û5ˆà$'§N¡N°;À
ÈKÐYeÐgwÓ$xÑ!ˆ�\Ü
�‰�ÔÜ
�‰�ÔàˆÜŸ™Ÿ™ X¨s´jÀÓ6MÈvÐ5VÑ/VÓWˆÜŸ™Ÿ™ h°´zÀ+Ó7NÐPUÐ6VÑ0VÓWˆÜ
�	‰	�)˜]Ô+Ü
�	‰	�*˜nÔ-á�=Ó!Ð!rC   )r.  )F)r}   r~   r   r€   r�   r(   r'  r)   r(  r[   r‹   rŸ   r;  r  r=  r  r@   rN  rP  r%   rÕ   r_  ra  r  rA  r  ÚclassmethodrT  ÚZ_BEST_SPEEDrx  rŒ  ra   rC   rA   r*   r*   Ž  s·   „ ñ2ð€Ið
 !€LØ€Kò<òò&ò2ò9ó'=òX(ò'ò0ò/òòó5òn3ò2ò!òF[ð Ø=AØ $°t×7HÑ7HòY#ó ðY#ðv Ø8<Èt×O`ÑO`ò "ó ñ"rC   r*   rW   );r€   rT  Ú	gitdb.excr   r   r   r   Ú
gitdb.utilr   r   r	   r
   r   Ú	gitdb.funr   r   r   r   r   r   r   r   r   r   r   Úgitdb_speedups._perfr   ÚImportErrorÚ
gitdb.baser   r   r   r   r   r   r   Úgitdb.streamr    r!   r"   r#   r$   Ústructr%   Úbinasciir&   Úgitdb.constr'   r�  rÖ   r%  rØ   Ú__all__rB   rR   rT   r(   r)   r*   ra   rC   rA   ú<module>rš     sÏ   ðñ
 :Û ÷ó ÷õ ÷÷ ÷ ñ ð	Ý?÷
÷ ñ ÷õ õ Ý å !ã Û Û 	Û 
à
5€ò
1]ól%÷VDñ DôN~9�Iô ~9ôHQ@ˆyô Q@ôlw"�õ w"øðO ò 	Ùð	ús   ¼B9 Â9CÃ C