403Webshell
Server IP : 217.160.0.244  /  Your IP : 216.73.217.138
Web Server : Apache
System : Linux infong-eu155 4.4.400-icpu-108 #2 SMP Wed Feb 11 11:51:01 UTC 2026 x86_64
User : u100174116 ( 6746176)
PHP Version : 8.5.10
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/dulwich/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/dulwich/__pycache__/pack.cpython-313.pyc
�

mEdg�g��8	�SrSSKrSSKJrJr SSKJr SSKJrJ	r	 SSK
Jr SSKrSSKrSSKrSSKrSSKrSSKJrJrJr SS	KJr SS
KJr SSKJrJr SSKJr SS
KJ r J!r!J"r"J#r#J$r$J%r%J&r& SSK'r'Sr(\RTS:XaSr(SSK+J,r,J-r- SSK.J/r/ SSK0J1r1 SSK2J3r3J4r4J5r5J6r6J7r7 Sr8Sr9\8\94r:Sr;Sr<\&\=\&\>\?4\@\>4\@\>4rA\!\>/\=\?\A44rB\!\?\C/S4rD\=\?\#\>4rE"SS\F5rG"SS\$5rH"SS\H5rI"S S!5rJS�S"\!\?/\>4S#\#\?S$\=\@\?\#\?44S%jjrK"S&S'\F5rL"S(S)5rMS*rNS\N4S+\!\?/\>4S,\MS-\OS.\?S$\>4
S/jjrPS0rQS1rRS�S2jrSS3rTS4rU\=\>\?\#\?4rV"S5S65rW"S7S8\W5rX"S9S:\W5rY"S;S<\Y5rZ"S=S>\Y5r[S$\=\?\?44S?jr\S@\&\>\\>4S$\?4SAjr]SSS\N4SB\!\?/\>4S+\#\!\?/\>4S$\=\M\>44SCjjr^SDr_"SESF5r`"SGSH\`5raSIrbS�SJjrc"SKSL5rd\%"SM5re"SNSO\"\e5rf"SPSQ\f\M5rg"SRSS\f\V5rh"STSU\f\45ri"SVSW5rj"SXSY5rkSZrlS�S\jrmS�S]jrnSSS[S^.S_\&\\4\\=\4\#\>44S`\#\OSa\#\?Sb\?4ScjjroSdrpS�SejrqSSSf.Sg\ISh\r\>Si\#\r\>S$\\M4SjjjrsSSSk.S_\&\\>\\=\4\#\>44Sl\#\?S$\\M4SmjjrtS_\&\\4\\=\4\#\E44S$\\44SnjruS�Sl\#\?4SojjrvSSSSSp.S_\&\\4\\=\4\#\>44S`\#\OSa\#\?Sq\OS$\=\?\\M44
SrjjrwS�Sg\ISh\\=\3\#\E4Sa\#\?S`\#\OSs\OSq\OSi\#\r\>S$\\M4StjjrxSu\4S$\M4SvjryS�Sg\ISh\\=\3\#\E4Sa\#\?S`\#\OSs\OSb\?Si\#\r\>4SwjjrzSSS[Sx.S_\&\\4\\=\4\#\>44Sa\#\?S`\#\OSb\?4Syjjr{"SzS{5r|SSS[S|.S}\\M4S~jjr}Sr~S$\>4S�jrS�r�S�r�S�r�S�r�S�\\VS�\>S$\>4S�jr�\�r�"S�S�5r�S[SS�.S�\ Sh\r\3S$\=\>\@44S�jjr�SS�K�J�r�JUrU g!\
a
 SSKJr GNYf=f!\)a Sr(GNf=f!\)a gf=f)�a�Classes for dealing with packed git objects.

A pack is a compact representation of a bunch of objects, stored
using deltas where possible.

They have two parts, the pack file, which stores the data, and an index
that tells you where the data is.

To find an object you look in all of the index files 'til you find a
match for the object name. You then use the pointer got from this as
a pointer in to the corresponding packfile.
�N)�defaultdict�deque)�suppress)�BytesIO�UnsupportedOperation)�CSequenceMatcher)�SequenceMatcher)�Iterable�Iterator�Sequence)�sha1)�chain)�SEEK_CUR�SEEK_END)�unpack_from)�BinaryIO�Callable�Generic�Optional�Protocol�TypeVar�UnionTF�Plan9�)�ApplyDeltaError�ChecksumMismatch)�GitFile)�LRUSizeCache)�ObjectID�ShaFile�
hex_to_sha�
object_header�
sha_to_hex���
ic�"�\rSrSrSrSSjrSrg)�UnresolvedDeltas�dz$Delta objects could not be resolved.Nc��Xlg�N��shas)�selfr-s  �./usr/lib/python3/dist-packages/dulwich/pack.py�__init__�UnresolvedDeltas.__init__gs���	�r,��returnN)�__name__�
__module__�__qualname__�__firstlineno__�__doc__r0�__static_attributes__�r2r/r(r(ds
��.�r2r(c��\rSrSrS\SS4SjrS
S\\\\\	4S\\
\	/S4SS4SjjrS	\S\
4S
jrS	\S\4SjrSrg)�ObjectContainer�k�objr4Nc��g)z)Add a single object to this object store.Nr;�r.r?s  r/�
add_object�ObjectContainer.add_objectl��r2�objects�progressc��g)zkAdd a set of objects to this object store.

Args:
  objects: Iterable over a list of (object, path) tuples
Nr;)r.rErFs   r/�add_objects�ObjectContainer.add_objectsorDr2r
c��g)zCheck if a hex sha is present.Nr;�r.r
s  r/�__contains__�ObjectContainer.__contains__zrDr2c��g)zRetrieve an object.Nr;rKs  r/�__getitem__�ObjectContainer.__getitem__}rDr2r;r+)r5r6r7r8r rBr�tupler�strrrH�bytes�boolrLrOr:r;r2r/r=r=ks���8�g�8�$�8�59�	��%���#�� 6�7�8�	��8�S�E�4�K�0�1�	�
�		�-��-�4�-�"��"�'�"r2r=c��\rSrSrSS.S\S\SS4SjjrSS	.S
\\S\S\\	4Sjjr
SS
\\S\S\S
\S\S4
SjjrSr
g)�PackedObjectContainer�F��include_compr
rYr4�UnpackedObjectc�,�[UR5e)zGet a raw unresolved object.)�NotImplementedError�get_unpacked_object)r.r
rYs   r/r]�)PackedObjectContainer.get_unpacked_object�s��"�$�":�":�;�;r2��
allow_missingr-r`c�,�[UR5er+)r\�iterobjects_subset�r.r-r`s   r/rb�(PackedObjectContainer.iterobjects_subset�s��"�$�"9�"9�:�:r2�convert_ofs_deltac�,�[UR5er+)r\�iter_unpacked_subset)r.r-rYr`res     r/rg�*PackedObjectContainer.iter_unpacked_subset�s��"�$�";�";�<�<r2r;N)FFT)r5r6r7r8rSrTr]r
rr rb�setrgr:r;r2r/rVrV�s���38�<��<�,0�<�	�<�?D�;��U�O�;�7;�;�	�'�	�;�#�#�"&�=��%�j�=��=��	=�
 �=�
�"�	#�
=�=r2rVc�6�\rSrSrS\S4SjrS\4SjrSrg)�UnpackedObjectStream�r4rZc�,�[UR5er+)r\�__iter__�r.s r/rn�UnpackedObjectStream.__iter__�s��!�$�-�-�0�0r2c�,�[UR5er+�r\�__len__ros r/rs�UnpackedObjectStream.__len__�s��!�$�,�,�/�/r2r;N)	r5r6r7r8rrn�intrsr:r;r2r/rkrk�s ��1�(�#3�4�1�0��0r2rk�read�crc32r4c��/n[U5S:Xd
USS-(a^U"S5nUb[R"X15nUR[	USS55 [U5S:XaMOUSS-(aM^X!4$)zJRead bytes marked with most significant bit.

Args:
  read: Read function
r����rN)�len�binasciirw�append�ord)rvrw�ret�bs    r/�take_msb_bytesr��st���C�

�c�(�a�-�3�r�7�T�>���G�����N�N�1�,�E��
�
�3�q��!�u�:��	�c�(�a�-�3�r�7�T�>�>�
�:�r2c��\rSrSrSSjrSrg)�PackFileDisappeared�Nc��Xlgr+�r?rAs  r/r0�PackFileDisappeared.__init__�s���r2r�r3)r5r6r7r8r0r:r;r2r/r�r��s��r2r�c���\rSrSr%Sr/SQr\\\S'\\	\
\S'\S\
\4\S'\	\
\S'\\	\
\S	'SSSSSSS
.SSjjrS
r
SrS\4SjrSrSrS\4SjrSrg)rZ�a�Class encapsulating an object unpacked from a pack file.

These objects should only be created from within unpack_object. Most
members start out as empty and are filled in at various points by
read_zlib_chunks, unpack_object, DeltaChainIterator, etc.

End users of this object should take care that the function they're getting
this object from is guaranteed to set the members they need.
)
�_sha�comp_chunksrw�
decomp_chunks�
decomp_len�
delta_base�
obj_chunks�obj_type_num�offset�
pack_type_numr�r�Nr�r�r�)r�r�rw�shar�r�r4c�0�XplXPlXlX lSUlU=(d /UlUb"Uc[
[[U55Ul	OX0l	X@l
U[;aSUlSUl
gXlUR
Ul
X lgr+)r�r�r�r�r�r��sum�mapr{r�rw�DELTA_TYPESr�r�)r.r�r�r�rwr�r�r�s        r/r0�UnpackedObject.__init__�s������	�*��$�����*7�*=�2����$��);�!�#�c�=�"9�:�D�O�(�O��
��K�'� $�D��"�D�O� -��"�0�0�D�O�(�Or2c�~�URc%[URUR5UlUR$)z%Return the binary SHA of this object.)r��obj_shar�r�ros r/r��UnpackedObject.sha�s.���9�9���� 1� 1�4�?�?�C�D�I��y�y�r2c��URb
URce[R"URUR5$)z"Return a ShaFile from this object.)r�r�r �from_raw_chunksros r/�sha_file�UnpackedObject.sha_file�s:��� � �,����1L�L�L��&�&�t�'8�'8�$�/�/�J�Jr2c��UR[;a?[UR[[
45(deURUR4$UR$)z>Return the decompressed chunks, or (delta base, delta chunks).)r�r��
isinstancer�rSrur�ros r/�_obj�UnpackedObject._objsL������,��d�o�o��s�|�<�<�<�<��O�O�T�%7�%7�8�8��%�%�%r2c��[U[5(dgURHn[X5[X5:wdM g g�NFT)r�rZ�	__slots__�getattr)r.�other�slots   r/�__eq__�UnpackedObject.__eq__	s:���%��0�0���N�N�D��t�"�g�e�&:�:��#�r2c��X:X+$r+r;�r.r�s  r/�__ne__�UnpackedObject.__ne__s���"�"r2c	���URVs/sHoS[X5<3PM nnSRURRSRU55$s snf)N�=z{}({})z, )r�r��format�	__class__r5�join)r.�s�datas   r/�__repr__�UnpackedObject.__repr__sR��59�^�^�D�^��#�Q�w�t�'�*�+�^��D����t�~�~�6�6��	�	�$��H�H��Es�A r3)r5r6r7r8r9r�rru�__annotations__�listrSrr0r�r��OldUnpackedObjectr�r�r�rRr�r:r;r2r/rZrZ�s�����I��3�-����e��%�%��d�E�3�&�'�'���;���$�u�+�&�&�������)�
�)�>�K�&�'�&��#�I�#�Ir2rZi�	read_some�unpackedrY�buffer_sizec��URS::a[S5e[R"5n/nURnSnUR
nU"U5n	U	(d[R"S5eURU	5 URU	5n
U[U
5-
nURU
5 URnU(a:[U5nUb[R
"U	SU*U5nU(a	U	SU*US'OUb[R
"X�5nM�UbUS-nXqR:wa[R"S5eX�lU(aXQlU$)aDRead zlib data from a buffer.

This function requires that the buffer have additional data following the
compressed data, which is guaranteed to be the case for git pack files.

Args:
  read_some: Read function that returns at least one byte, but may
    return less than the requested size.
  unpacked: An UnpackedObject to write result data to. If its crc32
    attr is not None, the CRC32 of the compressed bytes will be computed
    using this starting CRC32.
    After this function, will have the following attrs set:
    * comp_chunks    (if include_comp is True)
    * decomp_chunks
    * decomp_len
    * crc32
  include_comp: If True, include compressed data in the result.
  buffer_size: Size of the read buffer.
Returns: Leftover unused data from the decompression.

Raises:
  zlib.error: if a decompression error occurred.
ryz+non-negative zlib data stream size expectedrzEOF before end of zlib streamN���z.decompressed data does not match expected size)
r��
ValueError�zlib�
decompressobjr�rw�errorr}�
decompressr{�unused_datar|r�)
r�r�rYr��
decomp_objr�r�r�rw�add�decomp�unused�lefts
             r/�read_zlib_chunksr�sJ��:���b� ��F�G�G��#�#�%�J��K��*�*�M��J��N�N�E�
���$����*�*�<�=�=����3���&�&�s�+���c�&�k�!�
����V�$��'�'����v�;�D�� � ���s�6�T�E�{�E�:���"%�f��u�+��B���
�
��N�N�3�.�E�#�$
��
�����(�(�(��j�j�I�J�J��N��*���Mr2c��[5nUHnURU5 M UR5RS5$)z�Return the hexdigest of the SHA1 over a set of names.

Args:
  iter: Iterator over string objects
Returns: 40-byte hex sha1 digest
�ascii)r
�update�	hexdigest�encode)�iterr��names   r/�	iter_sha1r�`s8���&�C����
�
�4����=�=�?�!�!�'�*�*r2c�f�[US5n[X5sSSS5 $!,(df   g=f)zrLoad an index file by path.

Args:
  path: Path to the index file
Returns: A PackIndex loaded from the given path
�rbN)r�load_pack_index_file)�path�fs  r/�load_pack_indexr�ms$��
��t�	��#�D�,�
�	�	�s�"�
0c�`�UR5nUbUUc [R"U5R
n[(a'[R"X![RS9nX14$UR5n[U5nX14$![[4a SnN�f=f![a NBf=f)N)�access)�filenor�AttributeError�os�fstat�st_size�has_mmap�mmap�ACCESS_READ�OSErrorrvr{)r��size�fd�contentss    r/�_load_file_contentsr�xs����
�X�X�Z��
�~��<��8�8�B�<�'�'�D��8�
&��9�9�R�d�6F�6F�G��
 �~�%��v�v�x�H��x�=�D��>���!
!�.�1��
�����
��
�s#�B�#B �B�B� 
B-�,B-c��[U5up#USSS:Xa;[R"SUSS5SnUS:Xa
[XX#S9$[	S	U35e[XX#S9$)
z�Load an index file from a file-like object.

Args:
  path: Path for the index file
  f: File-like object
Returns: A PackIndex loaded from the given file
N���tOc�>L�r�)�filer�r�zUnknown pack index format )r��struct�unpack�
PackIndex2�KeyError�
PackIndex1)r�r�r�r��versions     r/r�r��sm��)��+�N�H����|�z�!��-�-��x��!�}�5�a�8���a�<��d�X�I�I��7��y�A�B�B��$��E�Er2c�x�X::deX::a.X-S-nU"U5nXR:aUS-nO
XR:�aUS-
nOU$X::aM.g)z�Find a SHA in a data blob with sorted SHAs.

Args:
  start: Start index of range to search
  end: End index of range to search
  sha: Sha to find
  unpack_name: Callback to retrieve SHA by index
Returns: Index of the SHA, or None if it wasn't found
r�rNr;)�start�endr��unpack_name�i�file_shas      r/�bisect_find_shar��sU���<��<�
�,�
�[�Q����q�>���>���E�E�
�^��a�%�C��H��,�r2c���\rSrSrSrSrSrS\4SjrS\	\
4SjrS\	\4Sjr
S\
4S	jrS
\
S\4SjrS
\
S\4SjrS
\S\
4SjrS
\
S\4SjrS\
4SjrS\	\
4SjrSSjrSSjrSrg)�	PackIndexi�z�An index in to a packfile.

Given a sha id of an object a pack index can tell you the location in the
packfile of that object if it has it.
c��[U[5(dg[UR5UR55Huun nun nX$:wdM g gr�)r�r��zip�iterentries)r.r��name1�_�name2s     r/r��PackIndex.__eq__�sX���%��+�+��,/������ 1� 1� 3�-
�(�M�U�A�q�=�E�1�a��~��	-
�
r2c�.�URU5(+$r+)r�r�s  r/r��PackIndex.__ne__�s���;�;�u�%�%�%r2r4c�,�[UR5e)�0Return the number of entries in this pack index.rrros r/rs�PackIndex.__len__�s��!�$�,�,�/�/r2c�>�[[UR55$)z#Iterate over the SHAs in this pack.)r�r#�_itersharos r/rn�PackIndex.__iter__�s���:�t�}�}��/�/r2c�,�[UR5e)��Iterate over the entries in this pack index.

Returns: iterator over tuples with object name, offset in packfile and
    crc32 checksum.
)r\rros r/r�PackIndex.iterentries�s��"�$�"2�"2�3�3r2c�,�[UR5e)�`Return the SHA1 checksum stored for the corresponding packfile.

Returns: 20-byte binary digest
)r\�get_pack_checksumros r/r�PackIndex.get_pack_checksum�s��
"�$�"8�"8�9�9r2r�c�X�[R"S[SS9 URU5$)Nz Please use object_offset insteadr���
stacklevel)�warnings�warn�DeprecationWarning�
object_offset�r.r�s  r/�object_index�PackIndex.object_index�s)���
�
�.�0B�q�	
��!�!�#�&�&r2c�,�[UR5e)��Return the offset in to the corresponding packfile for the object.

Given the name of an object it will return the offset that object
lives at within the corresponding pack file. If the pack file doesn't
have the object then None will be returned.
)r\rrs  r/r�PackIndex.object_offset�s��"�$�"4�"4�5�5r2�indexc�^�UR5Hup#nX1:XdM
Us $ [U5e)z<Return the SHA1 corresponding to the index in the pack file.)rr�)r.r#r�r�rws     r/�object_sha1�PackIndex.object_sha1�s0��#'�#3�#3�#5��D�%�����$6��5�/�!r2c�,�[UR5e)�NSee object_offset.

Args:
  sha: A *binary* SHA string. (20 characters long)_
)r\�_object_offsetrs  r/r)�PackIndex._object_offset�s��"�$�"5�"5�6�6r2c�4�[UR55$)zuReturn the hex SHA1 over all the shas of all objects in this pack.

Note: This is used for the filename of the pack.
)r�r
ros r/�objects_sha1�PackIndex.objects_sha1s��
�����)�)r2c�,�[UR5e)z9Yield all the SHA1's of the objects in the index, sorted.)r\r
ros r/r
�PackIndex._itersha
s��!�$�-�-�0�0r2Nc��gr+r;ros r/�close�PackIndex.close���r2c��gr+r;ros r/�check�PackIndex.checkr3r2r;r3)r5r6r7r8r9r�r�rursrrSrn�PackIndexEntryrrrrr%r)r,r
r1r5r:r;r2r/r�r��s����	�&�0��0�0�(�5�/�0�4�X�n�5�4�:�5�:�'��'�#�'�6��6�3�6�"��"��"�7�%�7�C�7�*�e�*�1�(�5�/�1�
�
r2r�c�r�\rSrSrSrSSSjjrSrS\4SjrSr	S	r
S
rSr\
S5r\
S
5rSrg)�MemoryPackIndexiz-Pack index that is stored entirely in memory.Nr4c��0Ul0UlUH"up4nX@RU'X0RU'M$ XlX lg)z~Create a new MemoryPackIndex.

Args:
  entries: Sequence of name, idx, crc32 (sorted)
  pack_checksum: Optional pack checksum
N)�_by_sha�
_by_offset�_entries�_pack_checksum)r.�entries�
pack_checksumr�r�rws      r/r0�MemoryPackIndex.__init__sF��������#*��D�%�!'�L�L���&*�O�O�F�#�$+� �
�+�r2c��UR$r+)r>ros r/r�!MemoryPackIndex.get_pack_checksum*s���"�"�"r2c�,�[UR5$r+)r{r=ros r/rs�MemoryPackIndex.__len__-s���4�=�=�!�!r2c�T�[U5S:Xa[U5nURU$)N�()r{r!r;rs  r/r�MemoryPackIndex.object_offset0s%���s�8�r�>��S�/�C��|�|�C� � r2c� �URU$r+)r<)r.r�s  r/r%�MemoryPackIndex.object_sha15s�����v�&�&r2c�,�[UR5$r+)r�r;ros r/r
�MemoryPackIndex._itersha8s���D�L�L�!�!r2c�,�[UR5$r+)r�r=ros r/r�MemoryPackIndex.iterentries;s���D�M�M�"�"r2c�R�[UR5UR55$r+)r9�sorted_entries�calculate_checksum)�cls�packs  r/�for_pack�MemoryPackIndex.for_pack>s!���t�2�2�4�d�6M�6M�6O�P�Pr2c�L�U"UR5UR55$r+)rr)rR�other_indexs  r/�clone�MemoryPackIndex.cloneBs!���;�*�*�,�k�.K�.K�.M�N�Nr2)r<r;r=r>r+r3)r5r6r7r8r9r0rrursrr%r
r�classmethodrTrXr:r;r2r/r9r9s[��7�
,�#�"��"�!�
'�"�#��Q��Q��O��Or2r9c�d^�\rSrSr%Sr\\\S'SSSjjr\	S\
4Sj5rU4SjrSSjr
S\4S	jrS
\S\4SjrS\4SjrS\4S
jrS\\4SjrS\\4SjrS\\4SjrS\4SjrSSjrS\4SjrS\4SjrS\4SjrS\S\4SjrS\S\4SjrS\S\\4Sjr Sr!U=r"$)�
FilePackIndexiGa�Pack index that is based on a file.

To do the loop it opens the file, and indexes first 256 4 byte groups
with the first byte of the sha id. The value in the four byte group indexed
is the end of the group that shares the same starting byte. Subtract one
from the starting byte and index again to find the start of the group.
The values are sorted by sha id within the group, so do the math to find
the start and end offset and then bisect in to find if the value is
present.
�_fan_out_tabler4c��XlUc[US5UlOX lUc$[URU5uUlUlgX4sUlUlg)z{Create a pack index object.

Provide it with the name of the index file to consider, and it will map
it whenever required.
Nr�)�	_filenamer�_filer��	_contents�_size)r.�filenamer�r�r�s     r/r0�FilePackIndex.__init__UsP��"���<� ��4�0�D�J��J���)<�T�Z�Z��)N�&�D�N�D�J�*2�&�D�N�D�Jr2c��UR$r+�r_ros r/r��FilePackIndex.pathg����~�~�r2c�>�[U[5(aURUR:wag[TU]U5$�NF)r�r\r]�superr�)r.r�r�s  �r/r��FilePackIndex.__eq__ks8���
�u�m�,�,��#�#�u�';�';�;���w�~�e�$�$r2c��URR5 [URSS5bURR5 gg)Nr1)r`r1r�raros r/r1�FilePackIndex.closeus:���
�
�����4�>�>�7�D�1�=��N�N� � �"�>r2c� �URS$)r
ry)r]ros r/rs�FilePackIndex.__len__zs���"�"�2�&�&r2r�c�,�[UR5e)z�Unpack the i-th entry in the index file.

Returns: Tuple with object name (SHA), offset in pack file and CRC32
    checksum (if known).
)r\�
_unpack_entry�r.r�s  r/rr�FilePackIndex._unpack_entry~s��"�$�"4�"4�5�5r2c�,�[UR5e)z)Unpack the i-th name from the index file.)r\�_unpack_namerss  r/rv�FilePackIndex._unpack_name�s��!�$�"3�"3�4�4r2c�,�[UR5e)z2Unpack the i-th object offset from the index file.)r\�_unpack_offsetrss  r/ry�FilePackIndex._unpack_offset�s��!�$�"5�"5�6�6r2c�,�[UR5e)zAUnpack the crc32 checksum for the ith object from the index file.)r\�_unpack_crc32_checksumrss  r/r|�$FilePackIndex._unpack_crc32_checksum�s��!�$�"=�"=�>�>r2c#�h# �[[U55HnURU5v� M g7fr+)�ranger{rvrss  r/r
�FilePackIndex._itersha�s)����s�4�y�!�A��#�#�A�&�&�"���02c#�h# �[[U55HnURU5v� M g7f)rN)rr{rrrss  r/r�FilePackIndex.iterentries�s+����s�4�y�!�A��$�$�Q�'�'�"�r��start_offsetc��/n[S5HHnURXS--XS-S--nUR[R"SU5S5 MJ U$)N�r�r�>Lr)rrar}r�r�)r.r�rr��fanout_entrys     r/�_read_fan_out_table�!FilePackIndex._read_fan_out_table�s_�����u��A��>�>��1�u�$�|�1�u��k�'A��L�
�J�J�v�}�}�T�<�8��;�<�	�
�
r2c�d�UR5nUR5nX:wa[X!5eg)z;Check that the stored checksum matches the actual checksum.N�rQ�get_stored_checksumr�r.�actual�storeds   r/r5�FilePackIndex.check��4���(�(�*���)�)�+����"�6�2�2�r2c�N�[URSS5R5$)z\Calculate the SHA1 checksum over this pack index.

Returns: This is a 20-byte binary digest
N���)r
ra�digestros r/rQ� FilePackIndex.calculate_checksum�s#��
�D�N�N�4�C�(�)�0�0�2�2r2c�2�[URSS5$)ri���r��rSraros r/r�FilePackIndex.get_pack_checksum�s��
�T�^�^�C��,�-�-r2c�2�[URSS5$)zPReturn the SHA1 checksum stored for this index.

Returns: 20-byte binary digest
r�Nr�ros r/r��!FilePackIndex.get_stored_checksum�s��
�T�^�^�C�D�)�*�*r2r�c���[U5S:Xa[U5nURU5$![a/n[	UR
SS5nUS;a[
U5UeeSnAff=f)r!rG�closedN)NT)r{r!r)r�r�rar�)r.r��excr�s    r/r�FilePackIndex.object_offset�sh���s�8�r�>��S�/�C�	��&�&�s�+�+���	��T�^�^�X�t�<�F���%�)�$�/�S�8���		�s�-�
A&�*A!�!A&c��[U5S:Xde[USS5nUS:XaSnOURUS-
nURUn[X4XR5nUc[U5eUR
U5$)r(�Nrr)r{r~r]r�rvr�ry)r.r��idxr�r�r�s      r/r)�FilePackIndex._object_offset�s����3�x�2�~��~��#�b�q�'�l���!�8��E��'�'��a��0�E��!�!�#�&���E��->�->�?���9��3�-���"�"�1�%�%r2�prefixc#�h# �[USS5nUS:XaSnOURUS-
n[USS5S-nUS:Xa[U5nOURUnX#::deSn[X#5H;nUR	U5nURU5(aUv� SnM2U(dM; g g7f)z-Iterate over all SHA1s with the given prefix.Nrrr�FT)r~r]r{rrv�
startswith)r.r�r�r��startedr�r�s       r/�iter_prefix�FilePackIndex.iter_prefix�s�����F�2�A�J����A�:��E��'�'���	�2�E��&��!�*�o��!���%�<��d�)�C��%�%�c�*�C��|��|����u�"�A��+�+�A�.�D����v�&�&��
������
#�s�B'B2�-B2)rar`r_rb�NNNr3)#r5r6r7r8r9r�rur�r0�propertyrRr�r�r1rsr7rrrSrvryrr|rr
rr�r5rQrr�rr)r�r:�
__classcell__�r�s@r/r\r\Gs���	���I��:�$��c����%�#�
'��'�6�s�6�~�6�5��5�7�3�7�?�8�C�=�?�'�(�5�/�'�(�X�n�5�(����3�3�E�3�.�5�.�+�U�+����3��"&�%�&�C�&�$�%��H�U�O��r2r\c�X^�\rSrSrSrSS\SS4U4SjjjrSrSrS	r	S
S
jr
SrU=r$)r�i�zVersion 1 Pack Index file.Nrcr4c�`>�[TU]XX45 SUlURS5Ulg)Nrr)rkr0r�r�r]�r.rcr�r�r�r�s     �r/r0�PackIndex1.__init__s,���
�����8����"�6�6�q�9��r2c�H�[SURSUS--5up#X2S4$)N�>L20s���rra)r.r�r�r�s    r/rr�PackIndex1._unpack_entrys+��$�W�d�n�n�y�Q�QS�V�>T�U����d�#�#r2c�:�SUS--S-nURX"S-$)Nr�r�r�r�)ra�r.r�r�s   r/rv�PackIndex1._unpack_name
s(����B��'�!�+���~�~�f��{�3�3r2c�F�SUS--n[SURU5S$)Nr�r�r�rr�r�s   r/ry�PackIndex1._unpack_offsets(����B��'���4�����8��;�;r2c��gr+r;rss  r/r|�!PackIndex1._unpack_crc32_checksums��r2)r]r�r�r3�
r5r6r7r8r9rRr0rrrvryr|r:r�r�s@r/r�r��s7���$�:��:�d�:�:�
$�4�<��r2r�c�T^�\rSrSrSrSS\SS4U4SjjjrSrSrS	r	S
r
SrU=r$)
r�izVersion 2 Pack Index file.Nrcr4c��>�[TU]XX45 URSSS:wa[S5e[	SURS5uUlUR
S:wa[SUR
35eUR
S5UlSUlURS	[U5--Ul
URS[U5--UlURS[U5--Ulg)
Nr�r�zNot a v2 pack index filer�r��Version was r�ir�)
rkr0ra�AssertionErrorrr�r�r]�_name_table_offsetr{�_crc32_table_offset�_pack_offset_table_offset�_pack_offset_largetable_offsetr�s     �r/r0�PackIndex2.__init__s����
�����8��>�>�"�1���+� �!;�<�<�%�e�T�^�^�Q�?�����<�<�1�� �<����~�!>�?�?�"�6�6�q�9���"/���#'�#:�#:�R�#�d�)�^�#K�� �)-�)A�)A�A��D�	�M�)Q��&�.2�.L�.L�q�SV��T
�P
�/
��+r2c�f�URU5URU5URU54$r+)rvryr|rss  r/rr�PackIndex2._unpack_entry)s6�����a� �����"��'�'��*�
�	
r2c�H�URUS--nURX"S-$�Nr�)r�rar�s   r/rv�PackIndex2._unpack_name0s)���(�(�1�r�6�1���~�~�f��{�3�3r2c���URUS--n[SURU5SnUS-(a/URUS-S--n[SURU5SnU$)Nr�r�r�i���r�z>Q)r�rrar�r�s   r/ry�PackIndex2._unpack_offset4sl���/�/�!�a�%�7���T�4�>�>�6�:�1�=���U���8�8�F�i�<P�TU�;U�U�F� ��t�~�~�v�>�q�A�F��
r2c�V�[SURURUS--5S$)Nr�r�r)rrar�rss  r/r|�!PackIndex2._unpack_crc32_checksum<s+���4�����1I�1I�A�PQ�E�1Q�R�ST�U�Ur2)r�r]r�r�r�r�r�r�r�s@r/r�r�s9���$�

��

�d�

�

�
�4��V�Vr2r�c���U"S5nU(d[S5eUSSS:wa[SU<35e[SUS5unUS;a[S	U35e[SUS
5unX#4$)z�Read the header of a pack file.

Args:
  read: Read function
Returns: Tuple of (pack version, number of objects). If no data is
    available to read, returns (None, None).
�zfile too short to contain packNr��PACKzInvalid pack header r�)r��r�r�)r�r)rv�headerr��num_objectss    r/�read_pack_headerr�@s����"�X�F���=�>�>�
�b�q�z�W���3�F�:�>�?�?��U�F�A�.�J�W��f���|�G�9�5�6�6� ����2�N�[��!�!r2�chunksc�t�[U[5(a[U5$[[	[U55$r+)r�rSr{r�r�)r�s r/�
chunks_lengthr�Ts+���&�%� � ��6�{���3�s�F�#�$�$r2�read_allc��UcUnU(aSnOSn[XS9upeUSS-	S-nUSS-n[USS5Hup�X�S-U	S-S---
nM [U5nU[:XaT[XS9upeU[U5-
nUS	S
-(a[eUSS-nUSSHn
US-
nUS-nX�S--
nM Un
O5U[
:Xa)U"S5nUb[R"X�5nUn
US-
nOSn
[X}X�S9n[UUUUS
9nUU4$)amUnpack a Git object.

Args:
  read_all: Read function that blocks until the number of requested
    bytes are read.
  read_some: Read function that returns at least one byte, but may not
    return the number of bytes requested.
  compute_crc32: If True, compute the CRC32 of the compressed data. If
    False, the returned CRC32 will be None.
  include_comp: If True, include compressed data in the result.
  zlib_bufsize: An optional buffer size for zlib operations.
Returns: A tuple of (unpacked, unused), where unused is the unused data
    leftover from decompression, and unpacked in an UnpackedObject with
    the following attrs set:

    * obj_chunks     (for non-delta types)
    * pack_type_num
    * delta_base     (for delta types)
    * comp_chunks    (if include_comp is True)
    * decomp_chunks
    * decomp_len
    * crc32          (if compute_crc32 is True)
Nr)rwr�r%�r�ryrzr�)r�r�rw)r�rY)
r��	enumerater{�	OFS_DELTAr��	REF_DELTAr|rwrZr�)r�r��
compute_crc32rY�zlib_bufsizerw�raw�type_numr�r��byte�raw_base�delta_base_offsetr��delta_base_objr�r�s                 r/�
unpack_objectr�[si��<���	��������6�J�C��A��!��t�#�H��q�6�D�=�D��S���W�%������1�q�5�A�+�.�.��&��3�x�H��9��#�H�:�
���C��H����r�7�T�>� � ���F�T�M�����G�D���"���!�#�����,���'�
�	�Y�	�!�"������N�N�>�9�E�#�
��B����
���D��H���� �!�	�F��V��r2c�P�UupU[;a[US5$[U5$)zBCompute the size of a unresolved object for use with LRUSizeCache.r)r�r�)�value�numr?s   r/�_compute_object_sizer��s+���J�S�
�k���S��V�$�$����r2c�x�\rSrSrSrS\4SSjjrSrSr\	S5r
S	rS
rS\
4SjrSS\\4SjjrS
rg)�PackStreamReaderi�zpClass to read a pack stream.

The pack is read from a ReceivableProtocol using read() or recv() as
appropriate.
Nr4c��XlUcXlOX l[5UlSUl[5Ul[5UlX0l	g�Nr)
r�r�r
r��_offsetr�_rbufr�_trailer�
_zlib_bufsize)r.r�r�r�s    r/r0�PackStreamReader.__init__�s?�� �
���%�N�&�N��6�������Y��
�&+�g��
�)�r2c��U"U5n[U5nU=RU-
sl[UR5nUS:�aUnSnO[XE-S-
S5nUnURR[
[[U5Vs/sHo�RR5PM sn555 URRX7*S5 URRUSU*5 U$s snf)aRead up to size bytes using the given callback.

As a side effect, update the verifier's hash (excluding the last 20
bytes read).

Args:
  read: The read callback to read from.
  size: The maximum number of bytes to read; the particular
    behavior is callback-specific.
r�rN)r{r�r��maxr�r�rS�	bytearrayr�popleft�extend)	r.rvr�r��n�tn�to_pop�to_addrs	         r/�_read�PackStreamReader._read�s����D�z��
��I��������
����
����7��F��F����"��a�(�F��F�������)�e�F�m�L�m��]�]�2�2�4�m�L�M�N�	
�	
�
�
���T�'�(�^�,�	
������X�v�g��'����
Ms�#C9c��URnUR5nURS[5 UR5nURU5 X2-
$r�)r��tell�seekr)r.�bufr�r�s    r/�_buf_len�PackStreamReader._buf_len�sB���j�j�����
������H���h�h�j��������{�r2c�<�URUR5-
$r+)r�r	ros r/r��PackStreamReader.offset�s���|�|�d�m�m�o�-�-r2c���UR5nX!:�aURRU5$URR5n[5UlX0R	UR
X-
5-$)z)Read, blocking until size bytes are read.)r	r�rvrrr�)r.r��buf_len�buf_datas    r/rv�PackStreamReader.read�sX���-�-�/���?��:�:�?�?�4�(�(��:�:�?�?�$���Y��
��*�*�T�]�]�D�N�C�C�Cr2c���UR5nU(a1URRU5nX:�a[5UlU$UR	UR
U5$)z7Read up to size bytes, blocking until one byte is read.)r	r�rvrrr�)r.r�rr�s    r/�recv�PackStreamReader.recv�sJ���-�-�/����:�:�?�?�4�(�D���$�Y��
��K��z�z�$�.�.�$�/�/r2c��UR$r+��_num_objectsros r/rs�PackStreamReader.__len__s��� � � r2c#�# �[UR5uo l[UR5H�nURn[URURUURS9upVXEl[5nURU5 URURR55 URS5 Xpl
Uv� M� UR5S:aURS5 [UR5nX�RR!5:wa-[#[%U5URR'55eg7f)a~Read the objects in this pack file.

Args:
  compute_crc32: If True, compute the CRC32 of the compressed
    data. If False, the returned CRC32 will be None.
Returns: Iterator over UnpackedObjects with the following members set:
    offset
    obj_type_num
    obj_chunks (for non-delta types)
    delta_base (for delta types)
    decomp_chunks
    decomp_len
    crc32 (if compute_crc32 is True)

Raises:
  ChecksumMismatch: if the checksum of the pack contents does not
    match the checksum in the pack trailer.
  zlib.error: if an error occurred during zlib decompression.
  IOError: if an error occurred writing to the output file.
)r�r�r�rr�N)r�rvrrr�r�rr�r�writer�rr	r�r�r�r�rr#r�)	r.r��pack_versionr�r�r�r�r�pack_shas	         r/�read_objects�PackStreamReader.read_objectss���*+;�4�9�9�*E�'��'��t�(�(�)�A��[�[�F�,��	�	��)�)�+�!�/�/�	 ��H�%�O��)�C��I�I�f���I�I�d�j�j�o�o�'�(��H�H�Q�K��J��N�#*�&�=�=�?�R��

�I�I�b�M��T�]�]�+���x�x���(�(�"�:�h�#7����9K�9K�9M�N�N�)�s�EE)rr�r�r�r�r�r�r�r3�F)r5r6r7r8r9�
_ZLIB_BUFSIZEr0rr	r�r�rvrrursrrZrr:r;r2r/r�r��sb���,0�m�*��@��.��.�D�0�!��!�3O�8�N�3K�3O�3Or2r�c�N^�\rSrSrSrSSU4SjjjrU4SjrSSSjjrSrU=r	$)	�PackStreamCopieri<z�Class to verify a pack stream as it is being read.

The pack is read from a ReceivableProtocol using read() or recv() as
appropriate and written out to the given file-like object.
c�8>�[TU]XS9 X0lX@lg)alInitialize the copier.

Args:
  read_all: Read function that blocks until the number of
    requested bytes are read.
  read_some: Read function that returns at least one byte, but may
    not return the number of bytes requested.
  outfile: File-like object to write output through.
  delta_iter: Optional DeltaChainIterator to record deltas as we
    read them.
)r�N)rkr0�outfile�_delta_iter)r.r�r�r#�
delta_iterr�s     �r/r0�PackStreamCopier.__init__Cs ���	�����7���%�r2c�\>�[TU]X5nURRU5 U$)z:Read data from the read callback and write it to the file.)rkrr#r)r.rvr�r�r�s    �r/r�PackStreamCopier._readSs(����w�}�T�(�������4� ��r2c	�:�Sn[UR55H]up#UR(aURRU5 UcM6U"SUS[	U5S3RS55 M_ UbU"SUS3RS55 gg)	z�Verify a pack stream and write it to the output file.

See PackStreamReader.iterobjects for a list of exceptions this may
throw.
rNzcopying pack entries: �/�
r�zcopied z pack entries
)r�rr$�recordr{r�)r.rFr�r�s    r/�verify�PackStreamCopier.verifyYs���
��$�T�%6�%6�%8�9�K�A����� � �'�'��1��#��1�!��A�c�$�i�[��C�J�J�7�S�T�	:�
���w�q�c��1�8�8��A�B� r2)r$r#r+r3)
r5r6r7r8r9r0rr-r:r�r�s@r/r!r!<s#����&�&� �
C�
Cr2r!c��[5nUR[U[U555 [	U[
5(a!URU5 UR
5$UHnURU5 M UR
5$)z5Compute the SHA for a numeric type and object chunks.)r
r�r"r�r�rSr�)�typer�r��chunks    r/r�r�isl��
�&�C��J�J�}�T�=��#8�9�:��&�%� � ��
�
�6���:�:�<���E��J�J�u����:�:�<�r2c�v�[5nURS[5 UR5nUS:aXR-U:dX%:�a[	SUSUSU35eXR-U-
nURU5 U(aBUR[
Xc55nURU5 U[U5-nU(aMBU$)ahHash a portion of a file into a new SHA.

Args:
  f: A file-like object to read from that supports seek().
  start_ofs: The offset in the file to start reading at.
  end_ofs: The offset in the file to end reading at, relative to the
    end of the file.
  buffer_size: A buffer size for reading.
Returns: A new SHA object updated with data read from the file.
rz/Attempt to read beyond file length. start_ofs: z, end_ofs: z, file length: )	r
rrrr�rv�minr�r{)r��	start_ofs�end_ofsr�r��length�todor�s        r/�compute_file_shar8us����&�C��F�F�1�h��
�V�V�X�F��!���(�9�4��9I��=�i�[��T[�S\�\k�lr�ks�t�
�	
���i�'�D��F�F�9��
��v�v�c�$�,�-���
�
�4����D�	����$��Jr2c�^�\rSrSrSrS"S#Sjjr\S5r\S5r\	S$Sj5r
\	S	5rS#S
jrSr
SrS
rSrS\4SjrSrSS.S\4SjjrS"S\\4SjjrS"S\\S\\4SjjrS"SjrS"SjrS%SjrSrS#SjrSS.S\S\S\ 4Sjjr!S\S\"\\#44S jr$S!r%g)&�PackDatai�a�The data contained in a packfile.

Pack files can be accessed both sequentially for exploding a pack, and
directly with the help of an index to retrieve a specific object.

The objects within are either complete or a delta against another.

The header is variable length. If the MSB of each byte is set then it
indicates that the subsequent byte is still part of the header.
For the first byte the next MS bits are the type, which tells you the type
of object, and whether it is a delta. The LS byte is the lowest bits of the
size. For each subsequent byte the LS 7 bits are the next MS bits of the
size, i.e. the last byte of the header contains the MS bits of the size.

For the complete objects the data is stored as zlib deflated data.
The size in the header is the uncompressed object size, so to uncompress
you need to just keep feeding data to zlib until you get an object back,
or it errors on bad data. This is done here by just giving the complete
buffer from the start of the deflated object on. This is bad, but until I
get mmap sorted out it will have to do.

Currently there are no integrity checks done. Also no attempt is made to
try and detect the delta case, or a request for an object at the wrong
position.  It will all just throw a zlib or KeyError.
Nr4c��XlX0lSUlUc[URS5UlOX l[URR5uo@l[[[[[44"S[S9Ul
g)a9Create a PackData object representing the pack in the given filename.

The file must exist and stay readable until the object is disposed of.
It must also stay the same size. It will be mapped whenever needed.

Currently there is a restriction on the size of the pack as the python
mmap implementation is flawed.
r�Nr�i@)�compute_size)r_rb�_header_sizerr`r�rvrrrurQr�r��
_offset_cache)r.rcr�r�r�s     r/r0�PackData.__init__�sr��"���
�����<� �����6�D�J��J�'7��
�
���'H�$��#�)�#�u�S�:K�5K�/L�*L�M��+?�
��r2c�T�[RRUR5$r+)r�r��basenamer_ros r/rc�PackData.filename�s���w�w������/�/r2c��UR$r+rfros r/r��
PackData.path�rhr2c�"�U"[U5XS9$)N)r�r�)rR)rRr�r�s   r/�	from_file�PackData.from_file�s���3�t�9�4�3�3r2c��U"US9$)N)rcr;)rRr�s  r/�	from_path�PackData.from_path�s
���D�!�!r2c�8�URR5 gr+)r`r1ros r/r1�PackData.close�s���
�
���r2c��U$r+r;ros r/�	__enter__�PackData.__enter__�����r2c�$�UR5 gr+�r1�r.�exc_type�exc_val�exc_tbs    r/�__exit__�PackData.__exit__�����
�
�r2c�p�[U[5(a!UR5UR5:H$grj)r�r:r�r�s  r/r��PackData.__eq__�s/���e�X�&�&��+�+�-��1J�1J�1L�L�L�r2c�D�URbUR$[RRUR5UlURUR
:a4URSURSUR
S3n[
U5eUR$)Nz is too small for a packfile (z < �))rbr�r��getsizer_r=r�)r.�errmsgs  r/�	_get_size�PackData._get_size�s����:�:�!��:�:���W�W�_�_�T�^�^�4��
��:�:��)�)�)����'�'E�d�j�j�\�QT�UY�Uf�Uf�Tg�gh�i�F� ��(�(��z�z�r2c��UR$)z+Returns the number of objects in this pack.rros r/rs�PackData.__len__�s��� � � r2c�F�[URSS9R5$)zKCalculate the checksum for this pack.

Returns: 20-byte binary SHA1 digest
r��r5)r8r`r�ros r/rQ�PackData.calculate_checksum�s��
 ��
�
�C�8�?�?�A�Ar2FrXrYc#�# �URRUR5 URcg[	UR5HrnURR5n[
URRSUS9upEX4lUv� URR[U5*[5 Mt g7f)NF)r�rY)r`rr=rrrr�rvr�r{r)r.rYrr�r�r�s      r/�
iter_unpacked�PackData.iter_unpacked�s�����
�
����)�)�*����$���t�(�(�)�A��Z�Z�_�_�&�F�,��
�
���u�<� ��H�%�O��N��J�J�O�O�S��[�L�(�3�*�s�CC�resolve_ext_refc#�# �URn[RXS9n[U5HupVUbU"XS5 Uv� M g7f)��Yield entries summarizing the contents of this pack.

Args:
  progress: Progress function, called with current and total
    object count.
Returns: iterator of tuples with (sha, offset, crc32)
�rjN)r�PackIndexer�
for_pack_datar�)r.rFrjr��indexerr��results       r/r�PackData.iterentriessI����'�'���+�+�D�+�R��"�7�+�I�A��#���(��L�,�s�AArFc�2�[URXS95$�z�Return entries in this pack, sorted by SHA.

Args:
  progress: Progress function, called with current and total
    object count
Returns: Iterator of tuples with (sha, offset, crc32)
�rFrj)�sortedr)r.rFrjs   r/rP�PackData.sorted_entriess"������h��P�
�	
r2c��URX#S9n[US5n[XTUR55sSSS5 $!,(df   g=f)z�Create a version 1 file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
ru�wbN)rPr�write_pack_index_v1rQ�r.rcrFrjr?r�s      r/�create_index_v1�PackData.create_index_v1#�I���%�%��&�
���X�t�
$��&�q�4�3J�3J�3L�M�%�
$�
$���A�
Ac��URX#S9n[US5n[XTUR55sSSS5 $!,(df   g=f)z�Create a version 2 index file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
ruryN)rPr�write_pack_index_v2rQr{s      r/�create_index_v2�PackData.create_index_v21r~rc�v�US:XaURXUS9$US:XaURXUS9$[SU35e)z�Create an  index file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
rrmr�zunknown index format )r|r�r�)r.rcrFr�rjs     r/�create_index�PackData.create_index?sc���a�<��'�'��O�(��
���\��'�'��O�(��
��4�W�I�>�?�?r2c�x�URRS[5 URRS5$)z1Return the expected checksum stored in this pack.r�r�)r`rrrvros r/r��PackData.get_stored_checksumRs'���
�
����X�&��z�z���r�"�"r2c�d�UR5nUR5nX:wa[X!5eg)z#Check the consistency of this pack.Nr�r�s   r/r5�PackData.checkWr�r2r�c��XR:�deURRU5 [URRUS9up4XlU$)z5Given offset in the packfile return a UnpackedObject.rX)r=r`rr�rvr�)r.r�rYr�rs     r/�get_unpacked_object_at�PackData.get_unpacked_object_at^sF���*�*�*�*�*��
�
�����#�D�J�J�O�O�,�O��� ���r2c��URU$![a Of=fURUSS9nURUR	54$)z�Given an offset in to the packfile return the object that is there.

Using the associated index the location of an object can be looked up,
and then the packfile can be asked directly for that object using this
function.
FrX)r>r�r�r�r�)r.r�r�s   r/�
get_object_at�PackData.get_object_athsV��	��%�%�f�-�-���	��	���.�.�v�E�.�J���&�&��
�
��8�8s��
�)r`r_r=rr>rb�NNr3r+)Nr�N)&r5r6r7r8r9r0r�rcr�rZrFrIr1rNrWr�r`rursrQrTrhr�ResolveExtRefFnr�
ProgressFnrPr|r�r�r�r5rZr�rQr�r�r:r;r2r/r:r:�s6���4
�*�0��0������4��4��"��"�����
�!��!�B�5:�4�T�4�"KO��.6��.G��&*.�59�
��:�&�
�"�/�2�
� N�N�@�&#�
3�49����,0��	��9�C�9�E�#�7H�2H�,I�9r2r:�Tc� �\rSrSrSrSrSrSS.SSjjr\S S\	4S	jj5r
\SSS
.SSS
\\S\
4Sjj5rS\SS4SjrS\	SS4SjrSrSSjrSrS\S\4SjrS\S\S\\S\4SjrS\S\S\\4SjrS\\4SjrSrSrg)!�DeltaChainIteratorizapAbstract iterator over pack data based on delta chains.

Each object in the pack is guaranteed to be inflated exactly once,
regardless of how many objects reference it as a delta base. As a result,
memory usage is proportional to the length of the longest delta chain.

Subclasses can override _result to define the result type of the iterator.
By default, results are UnpackedObjects with the following members set:

* offset
* obj_type_num
* obj_chunks
* pack_type_num
* delta_base     (for delta types)
* comp_chunks    (if _include_comp is True)
* decomp_chunks
* decomp_len
* crc32          (if _compute_crc32 is True)
FNrmr4c��XlX l[[5Ul[[5Ul/Ul/Ulgr+)r`�_resolve_ext_refrr��_pending_ofs�_pending_ref�	_full_ofs�	_ext_refs)r.�file_objrjs   r/r0�DeltaChainIterator.__init__�s5���
� /��2=�d�2C���4?��4E���02���&(��r2�	pack_datac��U"SUS9nURU5 URSS9HnURU5 M U$)NrmFrX)�
set_pack_datarhr,)rRr�rj�walkerr�s     r/ro� DeltaChainIterator.for_pack_data�sF���T�?�;�����Y�'�!�/�/�U�/�C�H��M�M�(�#�D��
r2�r`rjrS�Packr-r`c��U"SUS9nURUR5 [5nUHGn[U[5(deUR
R
U5nURU5 MI [5n	U(GaUR5nURRU5n
URU
5 U	RU5 SnU
R[:XaU
RU
R-
nOrU
R[ :Xa^[#[5 [U
R[5(deUR
R%U
R5nSSS5 UbX�;aURU5 U(aGMU$![a
 U(deGM�f=f!,(df   NM=f)Nrm)r�r�rir�rSr#rr�r��popr�r,r�r�r�r�r�rr)rRrSr-r`rjr�r7r��off�doner��base_ofss            r/�for_pack_subset�"DeltaChainIterator.for_pack_subset�so���T�?�;�����T�Y�Y�'��u���C��c�5�)�)�)�)�
��j�j�.�.�s�3��
����
���u����(�(�*�C��y�y�7�7��<�H��M�M�(�#��H�H�S�M��H��%�%��2�#�?�?�X�-@�-@�@���'�'�9�4��h�'�%�h�&9�&9�5�A�A�A�A�#�z�z�6�6�x�7J�7J�K�H�(��#��(<�����"��d��
��)�
�$��%�
��(�'�s�
F �,AF:� F7�6F7�:
Gr�c��URnURnU[:Xa-X1R-
nURURU5 gU[:XaJ[UR[5(deURURRU5 gURRX245 gr+)r�r�r�r�r�r}r�r�rSr�r�)r.r�r�r��base_offsets     r/r,�DeltaChainIterator.record�s����)�)�������y� � �#6�#6�6�K����k�*�1�1�&�9�
��
"��h�1�1�5�9�9�9�9����h�1�1�2�9�9�&�A��N�N�!�!�6�"4�5r2c�&�URUlgr+)r`)r.r�s  r/r�� DeltaChainIterator.set_pack_data�s
���_�_��
r2c#�# �URHupURXS5Shv�N M! UR5Shv�N UR(a[	UR55egNLN27fr+)r��
_follow_chain�_walk_ref_chainsr��repr)r.r�r�s   r/�_walk_all_chains�#DeltaChainIterator._walk_all_chains�si��� $����F��)�)�&�D�A�A�A�!/��(�(�*�*�*��$�$�=�d�4�+<�+<�&=�=�$�$�
B�*�s!�'A:�A6�A:�A8�1A:�8A:c��UR(a/[URVs/sHn[U5PM sn5egs snfr+)r�r(r#)r.r�s  r/�_ensure_no_pending�%DeltaChainIterator._ensure_no_pending�s9�����"�4�;L�;L�#M�;L�a�J�q�M�;L�#M�N�N���#Ms�Ac#��# �UR(dUR5 g[URR	55H�upXR;aMURU5up4URRU5 URRU5 UHnURXSU5Shv�N M M� UR5 g![
a M�f=fN.7fr+)
r�r�rvr��itemsr�r�r}r�r�)r.�base_sha�pendingr�r��
new_offsets      r/r��#DeltaChainIterator._walk_ref_chains�s�����$�$��#�#�%��!'��(9�(9�(?�(?�(A�!B��H��0�0�0��
�#'�#8�#8��#B� ��
�N�N�!�!�(�+����!�!�(�+�%�
��-�-�j�F�K�K�K�&�"C�	
���!���
��	
��L�s7�AC3�C �2AC3�C1�C3� 
C.�*C3�-C.�.C3c��[er+)r\�r.r�s  r/�_result�DeltaChainIterator._result�s��!�!r2r�r��base_chunksc�N�URRU5 [URRURUR
S9upEXlUcURU:XdeU$UR[;deX$l	[X4R5UlU$)N)rYr�)
r`rr�rv�
_include_comp�_compute_crc32r�r�r�r��apply_deltar�r�)r.r�r�r�r�rs      r/�_resolve_object�"DeltaChainIterator._resolve_object�s���	
�
�
�����#��J�J�O�O��+�+��-�-�
���
!�����)�)�\�9�9�9�
���)�)�[�8�8�8�$0�!�"-�k�;Q�;Q�"R�H���r2c#�^# �XU4/nU(a�UR5upnURXU5mURT5v� [URRTR
/5URRTR5/55nURU4SjU55 U(aM�gg7f)Nc3�V># �UHnUTRTR4v� M  g7fr+)r�r�)�.0r�r�s  �r/�	<genexpr>�3DeltaChainIterator._follow_chain.<locals>.<genexpr>s+�����"+�J��X�2�2�H�4G�4G�H�"+�s�&))	r�r�r�rr�r�r�r�r�)r.r�r�r�r7�	unblockedr�s      @r/r�� DeltaChainIterator._follow_chains������{�3�4���26�(�(�*�/�V�;��+�+�F�+�N�H��,�,�x�(�(���!�!�%�%�h�o�o�r�:��!�!�%�%�h�l�l�n�b�9��I�
�K�K��"+��
��d�s�B?C�Cc�"�UR5$r+)r�ros r/rn�DeltaChainIterator.__iter__s���$�$�&�&r2c��UR$r+)r�ros r/�ext_refs�DeltaChainIterator.ext_refs!s���~�~�r2)r�r`r�r�r�r�r3r+)r5r6r7r8r9r�r�r0rZr:ror
rSrTr�rZr,r�r�r�r�r�r�rur�r�r�rrnr�r:r;r2r/r�r�zs���(�N��M�48�)���h�����$��
#��#��u�o�#�
�#��#�J
6�~�
6�$�
6�%�x�%�D�%�>�O�"�,"��"�1�"����),��;?��;��	��$�C��s���e���$'�(�1�+�'�r2r�c��\rSrSrSrSrSrg)�UnpackedObjectIteratori%z1Delta chain iterator that yield unpacked objects.c��U$r+r;r�s  r/r��UnpackedObjectIterator._result(s���r2r;N�r5r6r7r8r9r�r:r;r2r/r�r�%s
��;�r2r�c�"�\rSrSrSrSrSrSrg)rni,z/Delta chain iterator that yields index entries.Tc�P�UR5URUR4$r+)r�r�rwr�s  r/r��PackIndexer._result1s���|�|�~�x������>�>r2r;N)r5r6r7r8r9r�r�r:r;r2r/rnrn,s��9��N�?r2rnc��\rSrSrSrSrSrg)�PackInflateri5z1Delta chain iterator that yields ShaFile objects.c�"�UR5$r+)r�r�s  r/r��PackInflater._result8s��� � �"�"r2r;Nr�r;r2r/r�r�5s
��;�#r2r�c�B�\rSrSrSrS
SjrSSjrS
SjrSrSr	S	r
g)�
SHA1Readeri<�AWrapper for file-like object that remembers the SHA1 of its data.Nc�0�Xl[S5Ulg�Nr2�r�r
�r.r�s  r/r0�SHA1Reader.__init__?s������I��	r2c�r�URRU5nURRU5 U$r+)r�rvr
r�)r.r�r�s   r/rv�SHA1Reader.readCs+���v�v�{�{�3����	�	������r2c���URRS5nXRR5:wa-[	URR5[
U55egr�)r�rvr
r�rr�r#)r.r�s  r/�	check_sha�SHA1Reader.check_shaHsJ�������R����Y�Y�%�%�'�'�"�4�9�9�#6�#6�#8�*�V�:L�M�M�(r2c�6�URR5$r+)r�r1ros r/r1�SHA1Reader.closeMs���v�v�|�|�~�r2c�6�URR5$r+�r�rros r/r�SHA1Reader.tellP����v�v�{�{�}�r2r�r3r+)r5r6r7r8r9r0rvr�r1rr:r;r2r/r�r�<s��K���
N�
�r2r�c�D�\rSrSrSrSSjrSSjrSrSrSr	S	r
S
rg)�
SHA1WriteriTr�Nc�>�XlSUl[S5Ulg)Nrr2�r�r6r
r�s  r/r0�SHA1Writer.__init__Ws���������I��	r2c��URRU5 URRU5 U=R[U5-
slgr+)r
r�r�rr6r{)r.r�s  r/r�SHA1Writer.write\s6���	�	����������T�����s�4�y� �r2c���URR5n[U5S:XdeURR	U5 U=R
[U5-
slU$r�)r
r�r{r�rr6rs  r/�	write_sha�SHA1Writer.write_shaasK���i�i��� ���3�x�2�~��~������S�����s�3�x����
r2c�Z�UR5nURR5 U$r+)r�r�r1rs  r/r1�SHA1Writer.closehs ���n�n����������
r2c��UR$r+)r6ros r/r��SHA1Writer.offsetms���{�{�r2c�6�URR5$r+r�ros r/r�SHA1Writer.tellpr�r2r�r3)r5r6r7r8r9r0rr�r1r�rr:r;r2r/r�r�Ts#��K��
!�
��
�r2r�c��/nUS-US--nUS-nU(a'URUS-5 US-nUS-nU(aM'URU5 U[:XaOUS-/nUS-nU(a+US-nURSSUS--5 US-nU(aM+URU5 OU[:Xa[U5S:XdeX1-
n[
U5$)	z�Create a pack object header for the given object info.

Args:
  type_num: Numeric type of the object.
  delta_base: Delta base offset or ref, or None for whole objects.
  size: Uncompressed object size.
Returns: A header for a packed object.
r�r�rzr�r%rrr�)r}r��insertr�r�r{r�)r�r�r�r��crs      r/�pack_object_headerr
ts����F�	�Q��4�"�9�%�A��Q�J�D�
��
�
�a�$�h���4�K����
���$��M�M�!���9���D� �!���q��
���!�O�J��J�J�q�$�*�t�"3�4�5��1��J��j�	�
�
�c��	�Y�	��:��"�$�$�$�����V��r2ryc#�># �U[;aUup1OSn[U[5(aU/n[[X[	[[U5555v� [R"US9nUHnURU5v� M UR5v� g7f)z�Generate chunks for a pack object.

Args:
  type: Numeric type of the object
  object: Object to write
  compression_level: the zlib compression level
Returns: Chunks
N)�level)r�r�rSr
r�r�r{r��compressobj�compress�flush)r0�object�compression_levelr��
compressorr�s      r/�pack_object_chunksr�s�����{��#��
�F��
��&�%� � ����
�"�4�S��S�&�9I�5J�K�
L�L��!�!�(9�:�J����!�!�$�'�'��
�
�
�
��s�BBc��Sn[XUS9H5nU"U5 UbURU5 [R"Xe5nM7 US-$)z�Write pack object to a file.

Args:
  write: Write function to use
  type: Numeric type of the object
  object: Object to write
  compression_level: the zlib compression level
Returns: Tuple with offset at which the object was written, and crc32
r�rr�)rr�r|rw)rr0rr�rrwr1s       r/�write_pack_objectr�sO��
�E�#�D�DU�V��
�e���?��J�J�u�����u�,��	W�
�:��r2)�deltify�delta_window_sizerrErrrc
�n�[US-S5n[URUUUUS9upgSSS5 [WR	5VV	s/sHup�X�SU	S4PM sn	n5n[US-S5nW[XVU54sSSS5 $!,(df   Nk=fs sn	nf!,(df   g=f)azWrite a new pack data file.

Args:
  filename: Path to the new pack file (without .pack extension)
  container: PackedObjectContainer
  entries: Sequence of (object_id, path) tuples to write
  delta_window_size: Delta window size
  deltify: Whether to deltify pack objects
  compression_level: the zlib compression level
Returns: Tuple with checksum of pack file and index file
�.packry�rrrNrr�.idx)r�write_pack_objectsrrvr�r�)
rcrErrrr�r?�data_sum�k�vs
          r/�
write_packr!�s���&
��G�#�T�	*�a�.�
�G�G��/��/�
���
+��G�M�M�O�D�O�&�1�q�A�$��!��o�O�D�E�G�	��F�"�D�	)�Q��,�Q��B�B�
*�	)�
+�	*��E�	)�	)�s�B�
B 
�7B&�
B�&
B4c#�x# �Sv� [R"SS5v� [R"SU5v� g7f)zYield chunks for a pack header.r�r�r�N)r�rS)r�s r/�pack_header_chunksr#�s,���
�M�
�+�+�e�Q�
��
�+�+�e�[�
)�)�s�8:c��[US5(a&URn[R"S[SS9 [U5HnU"U5 M
 g)z4Write a pack header for the given number of objects.rz?write_pack_header() now takes a write rather than file argumentr�rN)�hasattrrrrrr#)rr�r1s   r/�write_pack_headerr&�sE���u�g��������
�
�M���	
�
$�K�0��
�e��1r2��other_havesrF�	container�
object_idsr(c	#�# �Uc
[5nSn[URUSSS95HwupVUb/US-S:Xa&U"SUS[U5S3R	55 UR
[:XdMM[UR5nXq;dXr;dMnUv� US-
nMy UbU"S	US
3R	55 gg7f)NrT)r`re��zchecking for reusable deltas: r*r+rzfound z deltas to reuse
)	rir�rgr{r�r�r�r#r�)r)r*r(rF�reusedr�r��hexshas        r/�find_reusable_deltasr/�s�������e��
�F� ��&�&��d�d�	'�	
����
��A��H��M��5�a�S��#�j�/�9J�"�M�T�T�V�W��!�!�Y�.��� 3� 3�4�F��#�v�'<����!�������F�6�(�"4�5�=�=�?�@��s�A3C�9C�,C��window_sizerFr1c#�`^# �U4Sjn[[U"55UUS9Shv�N gN7f)z�Generate deltas for pack objects.

Args:
  objects: An iterable of (object, path) tuples to deltify.
  window_size: Window size; None for default
Returns: Iterator over type_num, object id, delta_base, content
    delta_base is None for full text entries
c3�># �THFn[U[5(aXRS44v� M+USUSRUS44v� MH g7f)Nrr)r�r r�)�erEs �r/�objects_with_hints�0deltify_pack_objects.<locals>.objects_with_hintssO�����A��!�W�%�%��:�:�t�,�-�-���t�a��d�m�m�Q�q�T�2�3�3�	�s�AAr0N)�deltas_from_sorted_objects�sort_objects_for_delta)rEr1rFr5s`   r/�deltify_pack_objectsr9
s1����4�*��1�3�4������s�#.�,�.c���/nUHOn[U[5(aUup4UcSnSnOUupVOUnURWWUR5*U45 MQ UR	5 SU5$)Nc3�*# �UH	oSv� M g7f)r�Nr;)r��xs  r/r��)sort_objects_for_delta.<locals>.<genexpr>9s��� �%�Q�a�D�%�s�)r�rQr}�
raw_length�sort)rE�magic�entryr?�hintr�r�s       r/r8r8'sz��
�E����e�U�#�#��I�C��|�����#'� ��4��C�
���h��s�~�~�'7�&7��=�>��
�J�J�L� �%� � r2c	#�6# �Uc[n[5n[U5GHrupEUb#US-S:XaU"SUS3R55 UR	5nUn[[
[U55nSn	UHqup�nX�R:waMSn
/n[X�5H*nU
[U5-
n
X�:�a M?URU5 M, U
n	Un[[
[U55nMs [URUR5R5U	UUS9v� URUR5R5URU45 [U5U:�dGMQUR5 [U5U:�aM!GMu g7f)Nr,rzgenerating deltas: r+)r�r�r�r�)�DEFAULT_PACK_DELTA_WINDOW_SIZErr�r��
as_raw_chunksr�r�r{r��create_deltar}rZr�r��
appendleftr�)rEr1rF�possible_basesr��or��winner�
winner_len�winner_base�base_id�
base_type_num�base�	delta_len�deltar1s                r/r7r7<ss�����4��<A�G�N��'�"�����A��H��M��+�A�3�b�1�9�9�;�<��o�o�������S�&�)�*�
���,:�(�G�D��
�
�*���I��E�%�d�0���S��Z�'�	��*�����U�#�	1�&���� ��S�&�!1�2�
�-;��
�J�J������� �"�!� �
�	
�	�!�!�1�5�5�7�>�>�#3�Q�Z�Z��"E�F��.�!�K�/���� ��.�!�K�/�/�;#�s�E+F�2F�F)rr�	ofs_deltarFrRc�z^�[T5nUcSnU(aU[[T5UUS94$U4SjnXV"54$)��Create pack data from objects.

Args:
  objects: Pack objects
Returns: Tuples with (type_num, hexdigest, delta base, object chunks)
Fr0c3�># �TH7n[U[5(a[US5v� M*[U5v� M9 g7fr�)r�rQ�full_unpacked_object)rIrEs �r/�iter_without_path�/pack_objects_to_data.<locals>.iter_without_path�s7�������a��'�'�.�q��t�4�4�.�q�1�1�	�s�?A)r{r9r�)rErrrRrF�countrWs`      r/�pack_objects_to_datarZesU���
��L�E������� ��W�
�-�!�
�
�	
�	2��(�*�+�+r2�reuse_deltasc#�z^# �[U5mU(a9[U[T5XgS9H!nT[UR	55	Uv� M# UcSnU(aEURTR
5SS9n	[[U4SjU	55UUS9Shv�N gTHn
[X
5v� M gN7f)rTr'NFr_c3�D># �UHoTUR4v� M g7fr+��id)r�rIr7s  �r/r��,generate_unpacked_objects.<locals>.<genexpr>�s����"M�<L�q�t�A�D�D�z�?�<L�s� r0)
�dictr/rir#r�rb�keysr7r8rV)r)r*rrr[rRr(rFr��objects_to_delta�oidr7s           @r/�generate_unpacked_objectsre�s����� �
��D��*��s�4�y�k�
�F��Z��
�
��-�.��L�	
�
�����$�7�7��I�I�K�u�8�
��.�"�"M�<L�"M�M�)��
�	
�	
��C�&�y�~�6�6��
	
�s�BB;�B9�B;rIc��[URSSUR5UR5R	5S9$)N)r�rwr�r�)rZr�rEr�r�)rIs r/rVrV�s6���	�
�
����o�o�'�
�E�E�G�N�N���r2c	�L�[U5n[UUUUUUS9n	[UU	UUS9$)a�Write a new pack data file.

Args:
  write: write function to use
  container: PackedObjectContainer
  entries: Sequence of (object_id, path) tuples to write
  delta_window_size: Sliding window size for searching for deltas;
                     Set to None for default window size.
  deltify: Whether to deltify objects
  compression_level: the zlib compression level to use
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
)rrr[r(��num_recordsr)r{re�write_pack_data)
rr)r*rrr[rr(�pack_contents_count�
pack_contentss
          r/�write_pack_from_containerrm�sE��,�j�/��-���+��!��
�M��
��'�+�	�r2rc�0�[XS9upV[UUUUS9$)a�Write a new pack data file.

Args:
  write: write function to use
  objects: Sequence of (object, path) tuples to write
  delta_window_size: Sliding window size for searching for deltas;
                     Set to None for default window size.
  deltify: Whether to deltify objects
  compression_level: the zlib compression level to use
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
)rrh)rZrj)rrErrrrkrls       r/rr�s+��&*>�g�)W�&���
��'�+�	�r2c
�n�\rSrSrSSSjjrSrSrSSSSS	.S
\\S\	S\
S\\4S
jjrSr
g)�PackChunkGeneratoriNryTr4c�b�[S5Ul0UlURUUUUUS9Ulg)Nr2)ri�recordsrFr�reuse_compressed)r
�csr?�_pack_data_chunks�_it)r.rirrrFrrss      r/r0�PackChunkGenerator.__init__s<���s�)���AC����)�)�#���/�-�*�
��r2c�6�URR5$r+)rtr�ros r/�
sha1digest�PackChunkGenerator.sha1digests���w�w�~�~��r2c��UR$r+)rvros r/rn�PackChunkGenerator.__iter__s���x�x�r2)rirFrrsrrrrsc#�,# �Uc[U5nSn[U5H0nUv� URRU5 U[U5-
nM2 Sn[	U5GH-up�U
R
nUb'U	S-S:XaU"SU	SUS3R
S55 U
Rb3URU
Rup�[nXl-
U
R4nOU
RnU
RbU(a
U
RnO
[!X�US9nSnSnUHGnUv� ["R$"UU5nURRU5 U[U5-
nMI US	-
nUU4URU
R'5'UU-
nGM0 X�:wa[)S
USU35eURR+5v� g![aC [n[U
R[5(deU
RU
R4nGN)f=f7f)a:Iterate pack data file chunks.

Args:
  records: Iterator over UnpackedObject
  num_records: Number of records (defaults to len(records) if not specified)
  progress: Function to report progress to
  compression_level: the zlib compression level
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
Nrr,zwriting pack data: r*r+r�rrz actual records written differs: z != )r{r#rtr�r�r�r�r�r?r�r�r�r�r�rSr�rr|rwr�r�r�)r.rrrirFrrsr�r1�actual_num_recordsr�r�r�r��
base_crc32r�r�rw�object_sizes                  r/ru�$PackChunkGenerator._pack_data_chunkss���&���g�,�K���'��4�E��K��G�G�N�N�5�!��c�%�j� �F�5���$�W�-�K�A��-�-�H��#��D��A�
��/��s�!�K�=��C�K�K�G�T�U��"�"�.�I�.2�l�l�8�;N�;N�.O�+�K� )�H�!�/��1G�1G�H�C��,�,���#�#�/�4D�!�-�-��+��5F����E��K����� ���u�e�4�������u�%��s�5�z�)��	 �

�!�#��,2�E�?�D�L�L�����(��k�!�F�A.�B�,� �2�3E�2F�d�;�-�X��
��g�g�n�n����= �H�(�H�%�h�&9�&9�5�A�A�A�A�#�.�.��0F�0F�G�C�H�s,�B&H�)G�DH�A	H�
H�H�H)rvrtr?)NNNryTr3)r5r6r7r8r0ryrnrrZrurTrSrur:r;r2r/rprpsy�������

�
�
�$ ����!#�!%�A��.�)�A��
A��A�
�%��A�Ar2rp)rirFrrrc�t�[UUUUS9nUHnU"U5 M
 URUR54$)acWrite a new pack data file.

Args:
  write: Write function to use
  num_records: Number of records (defaults to len(records) if None)
  records: Iterator over type_num, object_id, delta_base, raw
  progress: Function to report progress to
  compression_level: the zlib compression level
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
)rirrrFr)rpr?ry)rrrrirFr�chunk_generatorr1s       r/rjrjcsG��$)����+�	�O�!��
�e��!��"�"�O�$>�$>�$@�@�@r2c��[U5n[S5nUHupEnU[USS5==S-
ss'M! [S5H<nUR	[
R"SX755 X7S-==X7-
ss'M> UH=upEnUS::d[S5eUR	[
R"SXT55 M? [U5S	:XdeUR	U5 UR5$)
z�Write a new pack index file.

Args:
  f: A file-like object to write to
  entries: List of tuples with object name (sha), offset_in_pack,
    and crc32_checksum.
  pack_checksum: Checksum of the pack file.
Returns: The SHA of the written index file
c��gr�r;r;r2r/�<lambda>�%write_pack_index_v1.<locals>.<lambda>�s��r2Nrr�r�r�z)pack format 1 only supports offsets < 2Gbr�r�)
r�rr~rrr�rS�	TypeErrorr{r�)r�r?r@�
fan_out_tabler�r��entry_checksumr�s        r/rzrz�s���	�1�
�A��	�*�M�(/�$��n��c�$�r��(�m�$��)�$�)0��5�\��	������D�-�"2�3�4��!�e��
� 0�0���)0�$��n��*�$��G�H�H�	������G�V�2�3�)0��}���#�#�#��G�G�M���;�;�=�r2c��[5nUS-nUS-nU(a'URUS-5 US-nUS-nU(aM'URU5 [U5$)Nr�r%rz)r�r}rS)r�rr	s   r/�_delta_encode_sizer��s^��
�+�C��t��A��Q�J�D�
��
�
�1�t�8���4�K����
���$��J�J�q�M���:�r2i��c�j�[S/5n[S5H>nUSUS---(dMURXS--	S-5 US==SU--ss'M@ [S5HAnUSUS---(dMURXS--	S-5 US==SSU---ss'MC [U5$)Nrzr��r�rrr�)r�rr}rS)r�r6�scratchr�s    r/�_encode_copy_operationr��s�������G�
�1�X���4�1�q�5�=� � ��N�N�E��U�N�d�2�3��A�J�!�q�&� �J���1�X���D�A��E�M�!�!��N�N�F�!�e�O�t�3�4��A�J�!��A��,�&�J����>�r2c#�# �[U[5(aSRU5n[U[5(aSRU5n[U[5(de[U[5(de[	[U55v� [	[U55v� [
SXS9nUR5H�up4pVnUS:Xa9UnXT-
n	U	S:�a-[U	[5n
[X�5v� X�-
nX�-n	U	S:�aM-US:XdUS:XdMTXv-
nUnUS:�a2[S/5v� [U5X�S-v� US-nUS-
nUS:�aM2[U/5v� [U5X�U-v� M� g7f)	z�Use python difflib to work out how to transform base_buf to target_buf.

Args:
  base_buf: Base buffer
  target_buf: Target buffer
r2N)�isjunk�ar��equalr�replacerr�)r�r�r�rSr�r{r	�get_opcodesr3�
_MAX_COPY_LENr��
memoryview)
�base_buf�
target_buf�seq�opcode�i1�i2�j1�j2�
copy_start�copy_len�to_copyr�rIs
             r/rFrF�sw����(�D�!�!��8�8�H�%���*�d�#�#��X�X�j�)�
��h��&�&�&�&��j�%�(�(�(�(�
�S��]�
+�+�
�S��_�
-�-�
���
@�C�"%�/�/�"3���B�B��W���J��w�H��Q�,��h�
�6��,�Z�A�A��%�
��#��	�Q�,�
�Y��&�H�"4���A��A��c�'��S�E�l�"� ��,�Q�S��9�9��S����S���	�c�'�
���*���Z�(���U�3�3�3#4�s�DE:�	
E:�<E:�%E:c��[U[5(dSRU5n[U[5(dSRU5n/nSn[U5nSnU"X5upcU"X5upsU[U5:XdUS[U535eX4:Ga
[	XUS-5nUS-
nUS-(a�Sn	[S5H1n
USU
--(dM[	XUS-5nUS-
nX�U
S---n	M3 Sn[S	5H4n
USSU
---(dM[	XUS-5nUS-
nX�U
S---nM6 US:XaS
nX�-U:d
X�-U:�dX�:�aOIUR
X	X�-5 O+US:waUR
XX8-5 X8-
nO[S5eX4:aGM
X4:wa[SXS
<35eU[U5:wa[S5eU$)zrBased on the similar function in git's patch-delta.c.

Args:
  src_buf: Source buffer
  delta: Delta instructions
r2rc��SnSnU(a;[XUS-5nUS-
nX$S-U--nUS-
nUS-(dX!4$U(aM;X!4$)Nrri���r%rz)r~)rQr#r�r��cmds     r/�get_delta_header_size�*apply_delta.<locals>.get_delta_header_size�sh����
����e�E�A�I�.�/�C��Q�J�E��5�[�Q�&�&�D�
��F�A���:���{���e��{�r2z vs rrzr�r�r��zInvalid opcode 0zdelta not empty: Nzdest size incorrect)	r�rSr�r{r~rr}rr�)
�src_bufrQ�outr#�delta_lengthr��src_size�	dest_sizer��cp_offr�r<�cp_sizes
             r/r�r��s���g�u�%�%��(�(�7�#���e�U�#�#�������
�C�
�E��u�:�L�
�,�E�9�O�H�,�U�:��I��s�7�|�#�D��z��c�'�l�^�%D�D�#�
�
��%���	�*�+��
��
����:��F��1�X���!�q�&�>�>��E�%�!�)�4�5�A��Q�J�E��A��E�l�*�F�	�
�G��1�X���!��A��,�'�'��E�%�!�)�4�5�A��Q�J�E��Q��U�|�+�G�	�
�!�|�!��� �7�*��#�h�.��&���J�J�w��(8�9�:�
�A�X��J�J�u�U�[�1�2��L�E�!�"4�5�5�=�
�@
��� 1�%��-�1B�C�D�D��M�#�&�&��3�4�4��Jr2r?r@c
���[U5nURS5 UR[R"SS55 [	S5nUHupEnU[USS5==S-
ss'M! /n[
S5H<nUR[R"SX855 X8S-==X8-
ss'M> UHupEnURU5 M UH,upEnUR[R"SU55 M. UHwupEnUS	:a(UR[R"SU55 M4UR[R"SS	[U5-55 URU5 My UH)nUR[R"S
U55 M+ [U5S:XdeURU5 UR5$)z�Write a new pack index file.

Args:
  f: File-like object to write to
  entries: List of tuples with object name (sha), offset_in_pack, and
    crc32_checksum.
  pack_checksum: Checksum of the pack file.
Returns: The SHA of the index file written
r�r�r�c��gr�r;r;r2r/r��%write_pack_index_v2.<locals>.<lambda>>	s��r2Nrr�r�r�s>Qr�)
r�rr�rSrr~rr{r}r�)	r�r?r@r�r�r�r��
largetabler�s	         r/r�r�/	s���	�1�
�A��G�G�J���G�G�F�K�K��a� �!�$/�	�$:�M�(/�$��n��c�$�r��(�m�$��)�$�)0��J�
�5�\��	������E�=�#3�4�5��!�e��
� 0�0���)0�$��n�	����
�)0�(/�$��n�	������E�>�2�3�)0�(/�$��n��E�>�
�G�G�F�K�K��v�.�/�
�G�G�F�K�K��u�s�:��'>�?�@����f�%�)0���	������E�6�*�+���}���#�#�#��G�G�M���;�;�=�r2c���\rSrSr%Sr\\/\4\S'\\/\	4\S'\\\S'\\	\S'S8S\\
S	S4S
jjr\S5r
\S5rS
r\S	\4Sj5r\S	\	4Sj5rS9SjrSrSrSrS	\4SjrS	\4SjrSrS9SjrS9SjrS	\4SjrSr S\S	\!4Sjr"S\S	\#\\44Sjr$S\S	\%4Sjr&S	\'\%4Sjr(S S!.S"\)\*S#\!S	\'\%4S$jjr+S S S S%.S"\)\*S&\!S#\!S'\!S	\'\,4
S(jjr-S:S)jr.S8S*\\S	\4S+jjr/S,\S	\#\\\\044S-jr1S8S.\S/\S	\#\\)\44S0jjr2S8S1\\3S	\'\44S2jjr5S8S1\\3S	\'\44S3jjr6S S4S5.S,\S&\!S'\!S	\,4S6jjr7S7r8g);r�iZ	zA Git pack object.�
_data_load�	_idx_load�_data�_idxNrjr4c�^�UTlSTlSTlTRS-TlTRS-TlU4SjTlU4SjTlUTlg)Nrrc�.>�[TR5$r+)r:�
_data_pathros�r/r��Pack.__init__.<locals>.<lambda>k	s���(�4�?�?�";r2c�.>�[TR5$r+)r��	_idx_pathros�r/r�r�l	s�������!@r2)�	_basenamer�r�r�r�r�r�rj)r.rArjs`  r/r0�
Pack.__init__c	sP���"�����
���	����&�0����.�.�7�2���;���@���.��r2c�.�U"S5nXlX#lU$)zMCreate a new pack object from callables to load pack data and
index objects.
�)r�r�)rR�data_fn�idx_fnrs    r/�from_lazy_objects�Pack.from_lazy_objectso	s��
�"�g�� ���
��
r2c�j�U"S5nXlSUlX#lSUlUR	5 U$)z:Create a new pack object from pack data and index objects.r�N)r�r�r�r��check_length_and_checksum)rRr�r�rs    r/�from_objects�Pack.from_objectsy	s6���"�g���	��������
��%�%�'��
r2c�6�URR5$)z2The SHA over the SHAs of the objects in this pack.)r#r,ros r/r��	Pack.name�	s���z�z�&�&�(�(r2c��URc8UR(deUR5UlUR5 UR$)z The pack data object being used.)r�r�r�ros r/r��	Pack.data�	s>���:�:���?�?�"�?����*�D�J��*�*�,��z�z�r2c��URc(UR(deUR5UlUR$)z<The index being used.

Note: This may be an in-memory index
)r�r�ros r/r#�
Pack.index�	s2���9�9���>�>�!�>����(�D�I��y�y�r2c��URbURR5 URbURR5 ggr+)r�r1r�ros r/r1�
Pack.close�	s9���:�:�!��J�J�����9�9� ��I�I�O�O��!r2c��U$r+r;ros r/rN�Pack.__enter__�	rPr2c�$�UR5 gr+rRrSs    r/rW�
Pack.__exit__�	rYr2c�l�[U[U55=(a URUR:H$r+)r�r0r#r�s  r/r��Pack.__eq__�	s%���$��U��,�J����u�{�{�1J�Jr2c�,�[UR5$)zNumber of entries in this pack.)r{r#ros r/rs�Pack.__len__�	s���4�:�:��r2c�P�URRSUR<S3$)N�(r])r�r5r�ros r/r��
Pack.__repr__�	s%���.�.�)�)�*�!�D�N�N�+=�Q�?�?r2c�,�[UR5$)z7Iterate over all the sha1s of the objects in this pack.)r�r#ros r/rn�
Pack.__iter__�	s���D�J�J��r2c�r�[UR5[UR5:Xd4S[UR5S[UR5S35eURR5nURR	5nX:wa[[
U5[
U55eg)z@Sanity check the length and checksum of the pack index and data.zLength mismatch: z (index) != z (data)N)r{r#r�rr�rr#)r.�idx_stored_checksum�data_stored_checksums   r/r��Pack.check_length_and_checksum�	s����4�:�:��#��I�I�#
�
�	T�
�s�4�:�:��/�|�C��	�	�N�;K�7�S�	T�
�#�j�j�:�:�<��#�y�y�<�<�>���6�"��.�/��/�0��
�7r2c��URR5 URR5 UR5HnUR5 M g)zlCheck the integrity of this pack.

Raises:
  ChecksumMismatch: if a checksum for the index or data is wrong
N)r#r5r��iterobjectsrAs  r/r5�
Pack.check�	s>��	
�
�
�����	�	�����#�#�%�C��I�I�K�&r2c�6�URR5$r+)r�r�ros r/r��Pack.get_stored_checksum�	s���y�y�,�,�.�.r2c�P�UR5Vs/sHoS4PM sn$s snfr+)r�)r.rIs  r/�pack_tuples�Pack.pack_tuples�	s'��#'�#3�#3�#5�6�#5�a�D�	�#5�6�6��6s�
#r
c�\�URRU5 g![a gf=f)z3Check whether this pack contains a particular SHA1.TF)r#rr�rKs  r/rL�Pack.__contains__�	s.��	��J�J�$�$�T�*����	��	�s��
+�+c��URRU5nURRU5up4UR	X#U5upVUSRU54$r�)r#rr�r��resolve_objectr�)r.r
r��obj_typer?r�r�s       r/�get_raw�Pack.get_raw�	sU�����)�)�$�/���	�	�/�/��7�
���.�.�v��E�������&�)�)�)r2c�R�URU5up#[R"X#US9$)zRetrieve the specified SHA1.)r�)r�r �from_raw_string)r.r
r0�uncomps    r/rO�Pack.__getitem__�	s%���|�|�D�)����&�&�t��>�>r2c�d�[[RURURS95$)z&Iterate over the objects in this pack.rm)r�r�ror�rjros r/r��Pack.iterobjects�	s,����&�&�t�y�y�$�BV�BV�&�W�
�	
r2Fr_r-r`c�X^�U4Sj[RUTUURS95$)Nc3�L># �UHnURT;dMUv� M g7fr+r^)r��uor-s  �r/r��*Pack.iterobjects_subset.<locals>.<genexpr>�	s+����	
����u�u��}�
�B��s�$�	$r�)r�r�rjrcs ` r/rb�Pack.iterobjects_subset�	s7���	
�"�2�2���+� $� 4� 4�	3��	
�		
r2)rYr`rerYrec#�# �[[5n0n[U5nURUS9H�nUR	5n	X�UR
'[
U	5n
X�;axUR[:XaO[UR[5(deUR
UR-
nXkUl
[UlUv� URU
5 UR!UR
/5Hn[UlX�l
Uv� M M� U(aeU(dU(a[#U5egg![a X[RU5 GM*f=f7f�NrX)rr�rirhr�r�r#r�r�r�r�rur�r�r}�remover�r()
r.r-rYr`re�ofs_pending�ofsr7r�r�r.r��childs
             r/rg�Pack.iter_unpacked_subset�	s5���8C�4�7H�� "���4�y���*�*��*�E�H��,�,�.�C�#&���� ���_�F��~��)�)�Y�6�%�h�&9�&9�3�?�?�?�?�"*�/�/�H�4G�4G�"G�K�;�.1�.>��+�
2;��.������F�#�$������"�=��&/��#�#&� ���>�#F�*�����"�4�(�(�"&�}��$�!�#�0�7�7��A� �!�s+�B+E�.	D7�7BE�7E�E�E�Ec#�# �URR5VVVs0sH	up#oCX$4_M nnnnURRUS9H#nXVRup$X&lXFlUv� M% gs snnnf7fr)r#rr�rhr�r�rw)r.rYr�rrw�ofs_to_entriesr�s       r/rh�Pack.iter_unpacked 
sz���7;�z�z�7M�7M�7O�
�7O�"3�3�U�#���7O�	�
��	�	�/�/�\�/�J�H�)�/�/�:�L�S��M�"�N��N�	K��
�s�A=�A6�AA=�msgc���URS3n[US5nU(a"URU5 URS5 SSS5 U$!,(df   U$=f)z�Add a .keep file for the pack, preventing git from garbage collecting it.

Args:
  msg: A message written inside the .keep file; can be used later
    to determine whether or not a .keep file is obsolete.
Returns: The path of the .keep file, as a string.
z.keepry�
N)r�rr)r.r	�
keepfile_name�keepfiles    r/�keep�	Pack.keep*
sZ�� �>�>�*�%�0�
�
�]�D�
)�X�����s�#����u�%�*���	*�
)���s�*A�
Ar�c��URRU5nU(aURR	U5up4O0UR
(aURU5up4O[U5eX#U4$![a SnNgf=f)z8Get the object for a ref SHA, only looking in this pack.N)r#rr�r�r�rj)r.r�r�r0r?s     r/�get_ref�Pack.get_ref9
s���	��Z�Z�-�-�c�2�F���	�	�/�/��7�I�D�#�
�
!�
!��,�,�S�1�I�D�#��3�-���S� � ���	��F�	�s�A6�6B�Br�r0c�z�UnUnUn/nU[;a�Un	UcURnU[:Xa=Uup�XZ-
nURR	U5upg[U[5(deOoU[:XaeUup�[U[5(a[U5S:XdeU"U5upVn[U[5(deXY:Xa[[U55eURX�W45 U[;aM�Un
[U5H0up�n[X�5n
U	cMXm4URRU	'M2 Xm4$)zlResolve an object, possibly resolving deltas when necessary.

Returns: Tuple with object type and contents.
r�)r�rr�r�r�r�rur�rSr{r(r#r}�reversedr�r>)r.r�r0r?rr��	base_type�base_obj�delta_stack�prev_offset�delta_offsetrQrAr��
delta_types               r/r��Pack.resolve_objectH
sH�����	������;�&�%�K����,�,���I�%�(0�%��)�8��&*�i�i�&=�&=�k�&J�#�	�!�)�S�1�1�1�1��i�'�$,�!��!�(�E�2�2�s�8�}��7J�J�J�3:�8�3D�0���!�)�S�1�1�1�1��-�*�:�h�+?�@�@������>�?�#�;�&�*��.6�{�.C�*�K�U� ��/�F��&�7@�7H��	�	�'�'��4�/D�� � r2rFc�H�URRXRS9$)rlru)r�rrj�r.rFs  r/r?�Pack.entriesv
s)���y�y�$�$��/C�/C�%�
�	
r2c�H�URRXRS9$rt)r�rPrjrs  r/rP�Pack.sorted_entries�
s)���y�y�'�'��/C�/C�(�
�	
r2T)rYrec�T�URRU5nURRXBS9nUR[
:Xa_U(aX[
UR[5(deURRXER-
5Ul[UlU$)z�Get the unpacked object for a sha.

Args:
  sha: SHA of object to fetch
  include_comp: Whether to include compression data in UnpackedObject
rX)r#rr�r�r�r�r�r�rur%r�)r.r�rYrer�r�s      r/r]�Pack.get_unpacked_object�
s������)�)�#�.���9�9�3�3�F�3�V���!�!�Y�.�3D��h�1�1�3�7�7�7�7�"&�*�*�"8�"8��BU�BU�9U�"V�H��%.�H�"��r2)r�r�r�r�r�r�r�rjr+r3r)9r5r6r7r8r9rrr:r�r�r�r0rZr�r�r�r�r�r#r1rNrWr�rursrRr�rnr�r5rSr�r�rTrLrQr�r rOrr�r
rrbrZrgrhrr�rr�r�r7r?rPr]r:r;r2r/r�r�Z	s������"�h�,�/�0�0����Y��/�0�0��H���
�9�
��FJ�
/�)1�/�)B�
/�	
�
/���������)���h������y�������K����@�#�@� ��	�/�U�/�7����4��*�E�*�e�C��J�&7�*�?��?�'�?�

�X�g�.�
�BG�
��X�&�
�:>�
�	�'�	�
�$#�#�"'�
")��x� �")��	")�
�")� �
")�
�.�	!�")�H�
����
�3�
�
!�5�
!�U�8�C�=�#�?P�+P�%Q�
!� 48�,!��,!�!$�,!�	�s�H�U�O�#�	$�,!�^04�
� ��,�
�	�.�	!�
�04�
� ��,�
�	�.�	!�
�38�SW����+/��LP��	��r2r�)rrFr�c	��URS5 [UR5upVU(aCURS5 [URU[U5-5 UR
5 [USS9nURS[R5 /n[U5H�up�Ub'U"SU	S[U5S3RS55 [U
5S:XdeU"U
5up�UR5n
[URUUUUS	9nURX�U45 M� UR5nUR	U5 X�4$)
z�Extend a pack file with more objects.

The caller should make sure that object_ids does not contain any objects
that are already in the pack
rr�rezwriting extra base objects: r*r+r�r�)r�r)rr�rvr&rr{rr8r�rr�r�rrr}r�)r�r*r�rrF�_versionr��new_sha�
extra_entriesr��	object_idr�r�r�rwrs                r/�extend_packr(�
s;���F�F�1�I�,�Q�V�V�4��H��	���q�	��!�'�'�;��Z��#@�A�	
���	��q�#�.�G��F�F�1�b�k�k���M�"�*�-������/��s�!�C�
�O�3D�B�G�O�O�PW�X�
��9�~��#�#�#� ��+��������!�
�G�G����/�
��	���i��7�8�.� �~�~��H��G�G�H���"�"r2)r�r�r+)rrr�)ry)Nryr3r�)NNTTNN)NNTryN)�r9r|�collectionsrr�
contextlibr�iorr�cdifflibrr	�ModuleNotFoundError�difflibr�r��sysrr��collections.abcr
rr�hashlibr
�	itertoolsrrrr�typingrrrrrrrr�r��ImportError�platform�errorsrrr�r�	lru_cacherrErr r!r"r#r�r�r�rD�PACK_SPOOL_FILE_MAX_SIZErQrSrur�r�r�rRr��PackHint�	Exceptionr(r=rVrkr�r�rZrrTr�r�r�r�r�r�r7r�r9r\r�r�r�r�r�r�r�r!r�r8r:r�r�r�rnr�r�r�r
rrr!r#r&rir/r9r8r7rZrerVrmrrprjrzr�r�r�rFr�r��write_pack_indexr�r(�
dulwich._packr;r2r/�<module>r=s ��.��*��,�(�<�
�
�
���8�8���!��������H��<�<�7���H�5��#�M�M�
�	�
�	��)�$��"$��,���%��e�S�j� 1�4��;� >�?��e��L�M���E�7�E�#�/@�*@�$A�A�B��
�s�C�j�$�&�
'�
���h�u�o�%�&���y��"�h�"�,=�O�=�,0�0�:>��
�C�5�%�<�
 ��)1�#���
�4��9�h�s�m�#�$��"�)��
aI�aI�H�
��$�	A����u��%�A��A��A��	A�
�A�H
+�-��,F�&�.�u�c�8�C�=�0�1��Z
�Z
�z,O�i�,O�^t�I�t�n���2&V��&V�R"�e�C��H�o�"�(%�%��x��� 6�7�%�C�%�37����J���u�e�|�$�J���#����.�/�J��>�5� �!�
J�Z�IO�IO�X*C�'�*C�Z	��6d9�d9�N�C�L��h����h�V�/��?��?�$�^�4�?�#�%�g�.�#���0��@�>�,�.#�'+��
C�
�8�G�$�h�u�W�h�u�o�5M�/N�&O�O�
P�C��d�^�	C�
 ��}�C��
C�@*�
�")-�
�A�$�A��E�
�A��#�e�*�%�	A��n��
A�:"&�
�	�
�8�E�?�H�U�7�H�U�O�3K�-L�$M�M�
N���#���
�n���:!�
�8�G�$�h�u�W�h�x�>P�5P�/Q�&R�R�
S�!�
�g��!�,:>�&!�"�3�-�&!�X#�'+��
�
&,�
�8�G�$�h�u�W�h�u�o�5M�/N�&O�O�
P�&,��d�^�&,� ��}�	&,�
�&,��3���(�(�)�&,�X(,�"���(,�
�&7�$�&7���x��(�);�;�<�=�&7� ��}�&7��d�^�	&7�
�&7��
&7��#�e�*�%�&7��n��&7�R�G����(,�"���(,�%�$�%���x��(�);�;�<�=�%� ��}�	%�
�d�^�%��
%��%��#�e�*�%�%�X(,�"��
�
�8�G�$�h�u�W�h�u�o�5M�/N�&O�O�
P�� ��}�	�
�d�^���
�:Z�Z�B�
��
A�
�n�
%�A�:�6	��	��
�
�+4�\D�N%���(�%�9>�%�
�%�P'��G�G�^
�
�
3#��3#��H�
�3#��5�$�;��3#�l	����aU�(�'�'�(��2���H���vT�	��	�s5�Q.�/R�%R�.Q>�=Q>�R
�R
�R�R

Youez - 2016 - github.com/yon3zu
LinuXploit