
                           S r SSKJr  SSKrSSKJrJr  SSKJr  SSKrSSK	r	SSK
Jr  SSKrSSKrSSKJr  SSKJrJr  SS	K	Jr  SSKr SSKrS
r\R.                  S:X  a  SrSSKJrJr  SSKJr  SSKJr  SSKJ r J!r!J"r"J#r#  Sr$Sr%\$\%4r&Sr'SRS jr( " S S\)5      r* " S S\+5      r,Sr-S\-4S jr.S r/S r0SRS jr1S r2S r3 " S  S!\+5      r4 " S" S#\45      r5 " S$ S%\45      r6 " S& S'\65      r7 " S( S)\65      r8S* r9S+ r:SSS\-4S, jr;S- r< " S. S/\+5      r= " S0 S1\=5      r>S2 r?SSS3 jr@ " S4 S5\+5      rA " S6 S7\+5      rB " S8 S9\B5      rC " S: S;\B5      rD " S< S=\+5      rE " S> S?\+5      rFS@ rGSTSA jrH   SUSB jrISC rJSRSD jrKSE rL SUSF jrMSTSG jrNSH rOSI rPSJrQSK rRSL rSSM rTSN rU\UrV " SO SP\+5      rW SSQKXJTrTJ3r3  g! \ a    Sr GNvf = f! \ a     gf = f)Va  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.
    )defaultdictN)BytesIOUnsupportedOperation)deque)chain)sha1)SEEK_CURSEEK_END)unpack_fromTFPlan9)ApplyDeltaErrorChecksumMismatch)GitFile)LRUSizeCache)ShaFile
hex_to_sha
sha_to_hexobject_header      
   c                     / n[        U5      S:X  d  US   S-  (       a^  U " S5      nUb  [        R                  " X15      nUR                  [	        USS 5      5        [        U5      S:X  a  MO  US   S-  (       a  M^  X!4$ )zJRead bytes marked with most significant bit.

Args:
  read: Read function
r         N)lenbinasciicrc32appendord)readr   retbs       lib/third_party/dulwich/pack.pytake_msb_bytesr%   ^   st     C
c(a-3r7T>GNN1,E

3q!u:	 c(a-3r7T>>
 :    c                       \ rS rSrS rSrg)PackFileDisappearedm   c                     Xl         g Nobjselfr-   s     r$   __init__PackFileDisappeared.__init__n   s    r&   r,   N)__name__
__module____qualname____firstlineno__r0   __static_attributes__ r&   r$   r(   r(   m   s    r&   r(   c                   J    \ rS rSrSr/ SQrS rS rS rS r	S r
S	 rS
 rSrg)UnpackedObjectr   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.
)
offset_shaobj_type_num
obj_chunkspack_type_num
delta_basecomp_chunksdecomp_chunks
decomp_lenr   c                     S U l         S U l        Xl        X l        S U l        / U l        X0l        X@l        U[        ;   a  S U l	        S U l
        g Xl	        U R
                  U l
        X l        g r+   )r;   r<   r?   r@   rA   rB   rC   r   DELTA_TYPESr=   r>   )r/   r?   r@   rC   r   s        r$   r0   UnpackedObject.__init__   sd    	*$$
K' $D"DO -"00DO(Or&   c                 ~    U R                   c%  [        U R                  U R                  5      U l         U R                   $ )z%Return the binary SHA of this object.)r<   obj_shar=   r>   r/   s    r$   shaUnpackedObject.sha   s.    99 1 14??CDIyyr&   c                 X    [         R                  " U R                  U R                  5      $ )z"Return a ShaFile from this object.)r   from_raw_chunksr=   r>   rI   s    r$   sha_fileUnpackedObject.sha_file   s    &&t'8'8$//JJr&   c                 r    U R                   [        ;   a  U R                  U R                  4$ U R                  $ )z>Return the decompressed chunks, or (delta base, delta chunks).)r?   rE   r@   rB   rI   s    r$   _objUnpackedObject._obj   s1    ,OOT%7%788%%%r&   c                     [        U[        5      (       d  gU R                   H  n[        X5      [        X5      :w  d  M    g   gNFT)
isinstancer9   	__slots__getattr)r/   otherslots      r$   __eq__UnpackedObject.__eq__   s:    %00NNDt"ge&:: # r&   c                     X:X  + $ r+   r7   r/   rX   s     r$   __ne__UnpackedObject.__ne__   s    ""r&   c           	          U R                    Vs/ s H  o< S[        X5      < 3PM     nnU R                  R                  < SSR	                  U5      < S3$ s  snf )N=(z, ))rV   rW   	__class__r2   join)r/   sdatas      r$   __repr__UnpackedObject.__repr__   sG    9=HA1gd./H>>22DIIdODD Is   A)
r<   rA   r   rB   rC   r@   r>   r=   r;   r?   N)r2   r3   r4   r5   __doc__rV   r0   rJ   rN   rQ   rZ   r^   rh   r6   r7   r&   r$   r9   r9   r   s3    I)$K&#Er&   r9   i   c                    UR                   S::  a  [        S5      e[        R                  " 5       n/ nUR                  nSnUR
                  n U " U5      n	U	(       d  [        R                  " S5      eUR                  U	5        UR                  U	5      n
U[        U
5      -  nUR                  U
5        UR                  nU(       a:  [        U5      nUb  [        R
                  " U	SU*  U5      nU(       a	  U	SU*  US'   OUb  [        R
                  " X5      nM  Ub  US-  nXqR                   :w  a  [        R                  " S5      eXl        U(       a  XQl        U$ )aC  Read 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.
r   z+non-negative zlib data stream size expectedr   zEOF before end of zlib streamN    z.decompressed data does not match expected size)rC   
ValueErrorzlibdecompressobjrB   r   errorr   
decompressr   unused_datar   rA   )	read_someunpackedinclude_compbuffer_size
decomp_objrA   rB   rC   r   adddecompunusedlefts                r$   read_zlib_chunksr|      sJ   2 b FGG##%JK**MJNNE
$**<==3&&s+c&k!
V$''v;D  s6TE{E:"%fu+BNN3.E# $ (((jjIJJN*Mr&   c                     [        5       nU  H  nUR                  U5        M     UR                  5       R                  S5      $ )zReturn 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)iterrJ   names      r$   	iter_sha1r     s8     &C

4 ==?!!'**r&   c                 f    [        U S5       n[        X5      sSSS5        $ ! , (       d  f       g= f)zvLoad an index file by path.

Args:
  filename: 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     s$     
t	#D, 
		s   "
0c                 t    U R                  5       nUbU  Uc   [        R                  " U5      R
                  n[        (       a'   [        R                  " X![        R                  S9nX14$ U R                  5       n[        U5      nX14$ ! [        [        4 a    S n Nf = f! [        R                   a     NLf = f)N)access)filenor   AttributeErrorosfstatst_sizehas_mmapmmapACCESS_READrp   r!   r   )r   sizefdcontentss       r$   _load_file_contentsr     s    XXZ 
~<88B<''D8&99Rd6F6FG
  ~%vvxHx=D>! !.1  :: s#   B #B  BB B76B7c                     [        U5      u  p#USS S:X  a;  [        R                  " SUSS 5      S   nUS:X  a
  [        XX#S9$ [	        S	U-  5      e[        XX#S9$ )
zLoad 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   zUnknown pack index format %d)r   structunpack
PackIndex2KeyError
PackIndex1)r   r   r   r   versions        r$   r   r   2  sk     )+NH|z!--x!}5a8a<dXII9GCDD$EEr&   c                 x    X::  d   eX::  a.  X-   S-  nU" U5      nXR:  a  US-   n OXR:  a  US-
  nOU$ X::  a  M.  g)zFind 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   r   Nr7   )startendrJ   unpack_nameifile_shas         r$   bisect_find_shar   E  sU     <<
,[Qq>>EE^a%CH , r&   c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)	PackIndexi\  zAn 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      (       d  g[        U R                  5       UR                  5       5       H  u  u  n  nu  n  nX$:w  d  M    g   grT   )rU   r   zipiterentries)r/   rX   name1_name2s        r$   rZ   PackIndex.__eq__c  sX    %++,/ 1 1 3-
(MUAq=E1a ~	-

 r&   c                 .    U R                  U5      (       + $ r+   )rZ   r]   s     r$   r^   PackIndex.__ne__n  s    ;;u%%%r&   c                 ,    [        U R                  5      e)0Return the number of entries in this pack index.)NotImplementedError__len__rI   s    r$   r   PackIndex.__len__q  s    !$,,//r&   c                 >    [        [        U R                  5       5      $ )z#Iterate over the SHAs in this pack.)mapr   _itersharI   s    r$   __iter__PackIndex.__iter__u  s    :t}}//r&   c                 ,    [        U R                  5      e)Iterate over the entries in this pack index.

Returns: iterator over tuples with object name, offset in packfile and
    crc32 checksum.
)r   r   rI   s    r$   r   PackIndex.iterentriesy  s     "$"2"233r&   c                 ,    [        U R                  5      e)`Return the SHA1 checksum stored for the corresponding packfile.

Returns: 20-byte binary digest
)r   get_pack_checksumrI   s    r$   r   PackIndex.get_pack_checksum  s    
 "$"8"899r&   c                     [        U5      S:X  a  [        U5      n U R                  U5      $ ! [         a*    [	        U R
                  SS5      nUS;   a  [        U 5      ee f = f)zReturn the index 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.
(   closedNNT)r   r   _object_indexrm   rW   	_contentsr(   )r/   rJ   r   s      r$   object_indexPackIndex.object_index  se     s8r>S/C	%%c** 	T^^Xt<F%)$//		s	   - 4A!c                 ^    U R                  5        H  u  p#nX1:X  d  M  Us  $    [        U5      e)z<Return the SHA1 corresponding to the index in the pack file.)r   r   )r/   indexr   r;   r   s        r$   object_sha1PackIndex.object_sha1  s2     &*%5%5%7!T5 &8 5/!r&   c                 ,    [        U R                  5      e)MSee object_index.

Args:
  sha: A *binary* SHA string. (20 characters long)_
)r   r   r/   rJ   s     r$   r   PackIndex._object_index       "$"4"455r&   c                 4    [        U R                  5       5      $ )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   rI   s    r$   objects_sha1PackIndex.objects_sha1  s    
 ))r&   c                 ,    [        U R                  5      e)z9Yield all the SHA1's of the objects in the index, sorted.)r   r   rI   s    r$   r   PackIndex._itersha  s    !$--00r&   r7   N)r2   r3   r4   r5   rj   rZ   r^   r   r   r   r   r   r   r   r   r   r6   r7   r&   r$   r   r   \  s>    	&004:""6*1r&   r   c                   F    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rSrg)MemoryPackIndexi  z-Pack index that is stored entirely in memory.Nc                     0 U l         0 U l        U H"  u  p4nX@R                   U'   X0R                  U'   M$     Xl        X l        g)z~Create a new MemoryPackIndex.

Args:
  entries: Sequence of name, idx, crc32 (sorted)
  pack_checksum: Optional pack checksum
N)_by_sha	_by_index_entries_pack_checksum)r/   entriespack_checksumr   idxr   s         r$   r0   MemoryPackIndex.__init__  sF      'Du!$LL"&NN3 !(  +r&   c                     U R                   $ r+   )r   rI   s    r$   r   !MemoryPackIndex.get_pack_checksum  s    """r&   c                 ,    [        U R                  5      $ r+   )r   r   rI   s    r$   r   MemoryPackIndex.__len__  s    4==!!r&   c                 &    U R                   U   S   $ Nr   )r   r   s     r$   r   MemoryPackIndex._object_index  s    ||C ##r&   c                      U R                   U   $ r+   )r   )r/   r   s     r$   r   MemoryPackIndex.object_sha1  s    ~~e$$r&   c                 ,    [        U R                  5      $ r+   )r   r   rI   s    r$   r   MemoryPackIndex._itersha  s    DLL!!r&   c                 ,    [        U R                  5      $ r+   )r   r   rI   s    r$   r   MemoryPackIndex.iterentries  s    DMM""r&   )r   r   r   r   r+   )r2   r3   r4   r5   rj   r0   r   r   r   r   r   r   r6   r7   r&   r$   r   r     s(    7,#"$%"#r&   r   c                      ^  \ rS rSrSrSS jr\S 5       rU 4S jrS r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rSrU =r$ )FilePackIndexi  a  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.
c                     Xl         Uc  [        US5      U l        OX l        Uc$  [        U R                  U5      u  U l        U l        gX4sU l        U l        g)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   r   _size)r/   filenamer   r   r   s        r$   r0   FilePackIndex.__init__  sP     " < 40DJJ)<TZZ)N&DNDJ*2&DNDJr&   c                     U R                   $ r+   r   rI   s    r$   r   FilePackIndex.path      ~~r&   c                    > [        U[        5      (       a  U R                  UR                  :w  a  g[        [        U ]  U5      $ )NF)rU   r   _fan_out_tablesuperrZ   )r/   rX   rd   s     r$   rZ   FilePackIndex.__eq__  s;     um,,##u';';;]D077r&   c                     U R                   R                  5         [        U R                  SS 5      b  U R                  R                  5         g g )Nclose)r   r  rW   r   rI   s    r$   r  FilePackIndex.close  s:    

4>>7D1=NN  " >r&   c                      U R                   S   $ )r   r   )r  rI   s    r$   r   FilePackIndex.__len__  s    ""2&&r&   c                 ,    [        U R                  5      e)zUnpack 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$   r  FilePackIndex._unpack_entry  r   r&   c                 ,    [        U R                  5      e)z)Unpack the i-th name from the index file.)r   _unpack_namer  s     r$   r  FilePackIndex._unpack_name  s    !$"3"344r&   c                 ,    [        U R                  5      e)z2Unpack the i-th object offset from the index file.)r   _unpack_offsetr  s     r$   r  FilePackIndex._unpack_offset  s    !$"5"566r&   c                 ,    [        U R                  5      e)zAUnpack the crc32 checksum for the ith object from the index file.)r   _unpack_crc32_checksumr  s     r$   r  $FilePackIndex._unpack_crc32_checksum   s    !$"="=>>r&   c              #   h   #    [        [        U 5      5       H  nU R                  U5      v   M     g 7fr+   )ranger   r  r  s     r$   r   FilePackIndex._itersha$  s)     s4y!A##A&& "   02c              #   h   #    [        [        U 5      5       H  nU R                  U5      v   M     g7f)r   N)r  r   r  r  s     r$   r   FilePackIndex.iterentries(  s+      s4y!A$$Q'' "r  c                     / n[        S5       HH  nU R                  XS-  -   XS-   S-  -    nUR                  [        R                  " SU5      S   5        MJ     U$ )N   r   r   >Lr   )r  r   r   r   r   )r/   start_offsetr"   r   fanout_entrys        r$   _read_fan_out_table!FilePackIndex._read_fan_out_table1  s_    uA>>1u$|1uk'AL JJv}}T<8;<	 
 
r&   c                 d    U R                  5       nU R                  5       nX:w  a  [        X!5      eg)z;Check that the stored checksum matches the actual checksum.Ncalculate_checksumget_stored_checksumr   r/   actualstoreds      r$   checkFilePackIndex.check:  4    ((*))+"622 r&   c                 N    [        U R                  SS 5      R                  5       $ )z\Calculate the SHA1 checksum over this pack index.

Returns: This is a 20-byte binary digest
N)r   r   digestrI   s    r$   r(   FilePackIndex.calculate_checksumA  s#    
 DNN4C()0022r&   c                 2    [        U R                  SS 5      $ )r   ir1  bytesr   rI   s    r$   r   FilePackIndex.get_pack_checksumH  s    
 T^^C,--r&   c                 2    [        U R                  SS 5      $ )zPReturn the SHA1 checksum stored for this index.

Returns: 20-byte binary digest
r1  Nr5  rI   s    r$   r)  !FilePackIndex.get_stored_checksumO  s    
 T^^CD)**r&   c                     [        U5      S:X  d   e[        USS 5      nUS:X  a  SnOU R                  US-
     nU R                  U   n[        X4XR                  5      nUc  [        U5      eU R                  U5      $ )r      Nr   r   )r   r    r  r   r  r   r  )r/   rJ   r   r   r   r   s         r$   r   FilePackIndex._object_indexV  s     3x2~~#bq'l!8E''a0E!!#&E->->?93-""1%%r&   )r   r   r   r   NNN)r2   r3   r4   r5   rj   r0   propertyr   rZ   r  r   r  r  r  r  r   r   r$  r-  r(  r   r)  r   r6   __classcell__rd   s   @r$   r   r     sq    	:$  8#
'657?'(33.+& &r&   r   c                   H   ^  \ rS rSrSrS	U 4S jjrS rS rS rS r	Sr
U =r$ )
r   ii  zVersion 1 Pack Index file.c                 h   > [         [        U ]  XX45        SU l        U R	                  S5      U l        g )Nr   r   )r  r   r0   r   r$  r  r/   r   r   r   r   rd   s        r$   r0   PackIndex1.__init__l  s.    j$(H"66q9r&   c                 H    [        SU R                  SUS-  -   5      u  p#X2S 4$ )N>L20s      r   r   )r/   r   r;   r   s       r$   r  PackIndex1._unpack_entryq  s+    $WdnnyQQSV>TUd##r&   c                 :    SUS-  -   S-   nU R                   X"S-    $ )NrG  rH  r   r;  )r   r/   r   r;   s      r$   r  PackIndex1._unpack_nameu  s(    B'!+~~f{33r&   c                 F    SUS-  -   n[        SU R                  U5      S   $ )NrG  rH  r!  r   rI  rL  s      r$   r  PackIndex1._unpack_offsety  s(    B'48;;r&   c                     g r+   r7   r  s     r$   r  !PackIndex1._unpack_crc32_checksum}  s    r&   )r  r   r=  r2   r3   r4   r5   rj   r0   r  r  r  r  r6   r?  r@  s   @r$   r   r   i  s$    $:
$4< r&   r   c                   H   ^  \ rS rSrSrS	U 4S jjrS rS rS rS r	Sr
U =r$ )
r   i  zVersion 2 Pack Index file.c                   > [         [        U ]  XX45        U R                  S S S:w  a  [	        S5      e[        SU R                  S5      u  U l        U R                  S:w  a  [	        SU R                  -  5      eU R                  S5      U l        SU l	        U R                  S	[        U 5      -  -   U l        U R                  S[        U 5      -  -   U l        U R                  S[        U 5      -  -   U l        g )
Nr   r   zNot a v2 pack index filer   r   Version was %dr   i  r;  )r  r   r0   r   AssertionErrorr   r   r$  r  _name_table_offsetr   _crc32_table_offset_pack_offset_table_offset_pack_offset_largetable_offsetrC  s        r$   r0   PackIndex2.__init__  s    j$(H>>"1+ !;<<%eT^^Q?<<1 !1DLL!@AA"66q9"/#'#:#:R#d)^#K )-)A)AAD	M)Q&.2.L.LqSVT
 P
 /
+r&   c                 f    U R                  U5      U R                  U5      U R                  U5      4$ r+   )r  r  r  r  s     r$   r  PackIndex2._unpack_entry  s6    a "''*
 	
r&   c                 H    U R                   US-  -   nU R                  X"S-    $ Nr;  )rW  r   rL  s      r$   r  PackIndex2._unpack_name  s)    ((1r61~~f{33r&   c                     U R                   US-  -   n[        SU R                  U5      S   nUS-  (       a/  U R                  US-  S-  -   n[        SU R                  U5      S   nU$ )Nr   r!  r           ir   z>Q)rY  r   r   rZ  rL  s      r$   r  PackIndex2._unpack_offset  sl    //!a%7T4>>6:1=W88Fk<RVW;WWF t~~v>qAFr&   c                 V    [        SU R                  U R                  US-  -   5      S   $ )Nr!  r   r   )r   r   rX  r  s     r$   r  !PackIndex2._unpack_crc32_checksum  s+    41I1IAPQE1QRSTUUr&   )rX  r  rW  rZ  rY  r   r=  rR  r@  s   @r$   r   r     s&    $

4V Vr&   r   c                     U " S5      nU(       d  gUSS S:w  a  [        SU-  5      e[        SUS5      u  nUS;  a  [        S	U-  5      e[        SUS
5      u  nX#4$ )zRead 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).
   NNNr      PACKzInvalid pack header %rr   )r      rU  r   )rV  r   )r!   headerr   num_objectss       r$   read_pack_headerrm    st     "XFbqzW5>??UFA.JWf-788 2N[!!r&   c                 t    [        U [        5      (       a  [        U 5      $ [        [	        [        U 5      5      $ r+   )rU   r6  r   sumr   )chunkss    r$   chunks_lengthrq    s+    &%  6{3sF#$$r&   c                 $   Uc  U nU(       a  SnOSn[        XS9u  peUS   S-	  S-  nUS   S-  n[        USS 5       H  u  pXS-  U	S-  S-   -  -  nM     [        U5      nU[        :X  aT  [        XS9u  peU[        U5      -  nUS	   S
-  (       a  [        eUS   S-  nUSS  H  n
US-  nUS-  nXS-  -  nM     UnO7U[
        :X  a+  U " S5      nU(       a  [        R                  " X5      nUS-  nOSn[        X}X5      n[        UUUUS9nX4$ )am  Unpack 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   )r   r   r      r      r   r   r;  )rv   ru   )
r%   	enumerater   	OFS_DELTArV  	REF_DELTAr   r   r9   r|   )read_allrs   compute_crc32ru   zlib_bufsizer   r6  type_numr   r   byteraw_basedelta_base_offsetr@   rt   rz   s                   r$   unpack_objectr    s[   < 	!(8LEaA%H8d?DU12Y'1q5A+.. ( 5zH9%h<CJ9t  !!HtO!"ID"!#,  '
	Y	b\
NN:5EB
hD@H !	F r&   c                 P    U u  pU[         ;   a  [        US   5      $ [        U5      $ )zBCompute the size of a unresolved object for use with LRUSizeCache.r   )rE   rq  )valuenumr-   s      r$   _compute_object_sizer    s+    JS
kSV$$r&   c                   ^    \ rS rSrSrS\4S jrS rS r\	S 5       r
S rS	 rS
 rSS jrSrg)PackStreamReaderi  zpClass to read a pack stream.

The pack is read from a ReceivableProtocol using read() or recv() as
appropriate.
Nc                     Xl         Uc  Xl        OX l        [        5       U l        SU l        [        5       U l        [        5       U l        X0l	        g r   )
rx  rs   r   rJ   _offsetr   _rbufr   _trailer_zlib_bufsize)r/   rx  rs   rz  s       r$   r0   PackStreamReader.__init__  s?     %N&N6Y
)r&   c                    U" U5      n[        U5      nU =R                  U-  sl        [        U R                  5      nUS:  a  UnSnO[        XE-   S-
  S5      nUnU R                  R                  [        [        [        U5       Vs/ s H  oR                  R                  5       PM     sn5      5      5        U R                  R                  X7* S 5        U R                  R                  USU*  5        U$ s  snf )a  Read 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;  r   N)r   r  r  maxrJ   r   r6  	bytearrayr  popleftextend)	r/   r!   r   rg   ntnto_popto_addr   s	            r$   _readPackStreamReader._read+  s     Dz I7FF"a(FF)eFmLm]]224mLMN	
 	T'(^, 	Xvg' Ms   #C9c                     U R                   nUR                  5       nUR                  S[        5        UR                  5       nUR                  U5        X2-
  $ r   )r  tellseekr
   )r/   bufr   r   s       r$   _buf_lenPackStreamReader._buf_lenK  sB    jj
Hhhj{r&   c                 <    U R                   U R                  5       -
  $ r+   )r  r  rI   s    r$   r;   PackStreamReader.offsetS  s    ||dmmo--r&   c                     U R                  5       nX!:  a  U R                  R                  U5      $ U R                  R                  5       n[        5       U l        X0R	                  U R
                  X-
  5      -   $ )z)Read, blocking until size bytes are read.)r  r  r!   r   r  rx  )r/   r   buf_lenbuf_datas       r$   r!   PackStreamReader.readW  sX    --/?::??4((::??$Y
**T]]DNCCCr&   c                     U R                  5       nU(       a1  U R                  R                  U5      nX:  a  [        5       U l        U$ U R	                  U R
                  U5      $ )z7Read up to size bytes, blocking until one byte is read.)r  r  r!   r   r  rs   )r/   r   r  rg   s       r$   recvPackStreamReader.recv`  sJ    --/::??4(D$Y
Kzz$..$//r&   c                     U R                   $ r+   _num_objectsrI   s    r$   r   PackStreamReader.__len__j  s       r&   c              #     #    [        U R                  5      u  o l        Uc  g[        U R                  5       H  nU R                  n[        U R                  U R                  UU R                  S9u  pVXEl        [        5       nUR                  U5        UR                  U R                  R                  5       5        UR                  S5        Xpl
        Uv   M     U R                  5       S:  a  U R                  S5        [        U R                  5      nXR                  R!                  5       :w  a-  [#        [%        U5      U R                  R'                  5       5      eg7f)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.
N)rs   ry  rz  r   r;  )rm  r!   r  r  r;   r  r  r  r   writer  r  r  r  r  rJ   r2  r   r   r   )	r/   ry  pack_versionr   r;   rt   rz   r  pack_shas	            r$   read_objectsPackStreamReader.read_objectsm  s    ( +;499*E''t(()A[[F,		))+!//	 H %O )CIIfIIdjjoo'(HHQKJN# *& ==?R
 IIbMT]]+xx((":h#79K9K9MNN )s   EE!)r  r  r  r  r  rx  rs   rJ   )F)r2   r3   r4   r5   rj   _ZLIB_BUFSIZEr0   r  r  r>  r;   r!   r  r   r  r6   r7   r&   r$   r  r    sH     ,0m *@ . .D0!4Or&   r  c                   B   ^  \ rS rSrSrSU 4S jjrU 4S jrS rSrU =r	$ )PackStreamCopieri  zClass 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                 @   > [         [        U ]  XS9  X0l        X@l        g)al  Initialize 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.
)rs   N)r  r  r0   outfile_delta_iter)r/   rx  rs   r  
delta_iterrd   s        r$   r0   PackStreamCopier.__init__  s#     	.x.M%r&   c                 d   > [         [        U ]  X5      nU R                  R	                  U5        U$ )z:Read data from the read callback and write it to the file.)r  r  r  r  r  )r/   r!   r   rg   rd   s       r$   r  PackStreamCopier._read  s,    %t24>4 r&   c                     U R                   (       a3  U R                  5        H  nU R                   R                  U5        M      gU R                  5        H  nM     g)zVerify a pack stream and write it to the output file.

See PackStreamReader.iterobjects for a list of exceptions this may
throw.
N)r  r  record)r/   rt   r   s      r$   verifyPackStreamCopier.verify  sL      --/  ''1 0 &&( )r&   )r  r  r+   )
r2   r3   r4   r5   rj   r0   r  r  r6   r?  r@  s   @r$   r  r    s    &  r&   r  c                    [        5       nUR                  [        U [        U5      5      5        [	        U[
        5      (       a!  UR                  U5        UR                  5       $ U H  nUR                  U5        M     UR                  5       $ )z5Compute the SHA for a numeric type and object chunks.)r   r   r   rq  rU   r6  r2  )typerp  rJ   chunks       r$   rH   rH     sl    
&CJJ}T=#89:&%  

6 ::< EJJu ::<r&   c                 n   [        5       nU R                  S[        5        U R                  5       nUS:  a  XR-   U:  d  X%:  a  [	        SXU4-  5      eXR-   U-
  nU R                  U5        U(       aB  U R                  [        Xc5      5      nUR                  U5        U[        U5      -  nU(       a  MB  U$ )ah  Hash 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.
r   zOAttempt to read beyond file length. start_ofs: %d, end_ofs: %d, file length: %d)	r   r  r
   r  rV  r!   minr   r   )r   	start_ofsend_ofsrv   rJ   lengthtodorg   s           r$   compute_file_shar    s     &CFF1hVVXF!(949I:=FQW<XY
 	
 i'DFF9
vvc$,-

4D	 $ Jr&   c                       \ rS rSrSrSS jr\S 5       r\S 5       r\	SS j5       r
\	S 5       rS	 rS
 rS rS rS rS rS rS rSS jrS S jrS rSS jrSS jrSS jrSS jrS!S jrS rS rS rS r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.
Nc                     Xl         X0l        SU l        Uc  [        U R                   S5      U l        OX l        [        U R                  R                  5      u  o@l        [        S[        S9U l
        SU l        g)a9  Create 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.
rg  Nr   i  @)compute_size)r   r   _header_sizer   r   rm  r!   r  r   r  _offset_cachepack)r/   r   r   r   r   s        r$   r0   PackData.__init__  sf     "
< 6DJJ'7

'H$#)+?
 	r&   c                 T    [         R                  R                  U R                  5      $ r+   )r   r   basenamer   rI   s    r$   r   PackData.filename(  s    ww//r&   c                     U R                   $ r+   r   rI   s    r$   r   PackData.path,  r  r&   c                 "    U " [        U5      XS9$ )N)r   r   )str)clsr   r   s      r$   	from_filePackData.from_file0  s    3t9433r&   c                     U " US9$ )N)r   r7   )r  r   s     r$   	from_pathPackData.from_path4  s    D!!r&   c                 8    U R                   R                  5         g r+   )r   r  rI   s    r$   r  PackData.close8  s    

r&   c                     U $ r+   r7   rI   s    r$   	__enter__PackData.__enter__;      r&   c                 $    U R                  5         g r+   r  r/   exc_typeexc_valexc_tbs       r$   __exit__PackData.__exit__>      

r&   c                 "   [        U[        5      (       a!  U R                  5       UR                  5       :H  $ [        U[        5      (       aD  [	        U 5      [	        U5      :w  a  g[        U R                  5       U5       H  u  p#X#:w  d  M    g   ggrT   )rU   r  r)  listr   r   iterobjects)r/   rX   o1o2s       r$   rZ   PackData.__eq__A  sx    eX&&++-1J1J1LLLeT""4yCJ&d..0%88  9 r&   c                 >   U R                   b  U R                   $ [        R                  R                  U R                  5      U l         U R                   U R
                  :  a1  SU R                  U R                   U R
                  4-  n[        U5      eU R                   $ )Nz(%s is too small for a packfile (%d < %d))r   r   r   getsizer   r  rV  )r/   errmsgs     r$   	_get_sizePackData._get_sizeM  s~    ::!::WW__T^^4
::)))?

!!C F
 !((zzr&   c                     U R                   $ )z+Returns the number of objects in this pack.r  rI   s    r$   r   PackData.__len__Z  s       r&   c                 F    [        U R                  SS9R                  5       $ )zKCalculate the checksum for this pack.

Returns: 20-byte binary SHA1 digest
r1  )r  )r  r   r2  rI   s    r$   r(  PackData.calculate_checksum^  s    
  

C8??AAr&   c                    U R                   c  [        U5      e U R                   R                  R                  U5      nU(       a  U R	                  U5      u  p4OQU R                   b9  U R                   R
                  (       a  U R                   R                  U5      u  p4O[        U5      eX#U4$ ! [         a    Sn N~f = f)z8Get the object for a ref SHA, only looking in this pack.N)r  r   r   r   get_object_atresolve_ext_ref)r/   rJ   r;   r  r-   s        r$   get_refPackData.get_refe  s     993-	YY__11#6F **62ID#YY"tyy'@'@		11#6ID#3-S    	F	s   %B/ /B>=B>c                     UnUnUn/ nU[         ;   a  Un	Uc  U R                  nU[        :X  a3  Uu  pXZ-
  nU R                  U5      u  pg[	        U[
        5      (       d   eOVU[        :X  aL  Uu  p[	        U[        5      (       a  [        U5      S:X  d   eU" U5      u  pVn[	        U[
        5      (       d   eUR                  XW45        U[         ;   a  M  Un[        U5       H&  u  pn[        X5      nU	c  M  Xm4U R                  U	'   M(     Xm4$ )zlResolve an object, possibly resolving deltas when necessary.

Returns: Tuple with object type and contents.
r;  )rE   r  rv  r  rU   intrw  r6  r   r   reversedapply_deltar  )r/   r;   r  r-   r  base_offset	base_typebase_objdelta_stackprev_offsetdelta_offsetdeltar  rp  
delta_types                  r$   resolve_objectPackData.resolve_objectv  s*    	;&%K,,I%(0%)8&*&8&8&E#	!)S1111i'$,!!(E22s8}7JJJ3:83D0!)S1111>? ;&& .6{.C*KU /F &2;2C"";/ /D   r&   c              #     #    U R                   R                  U R                  5        [        SU R                  S-   5       H  nU R                   R                  5       n[        U R                   R                  US9u  pVUb  U" X0R                  5        UUR                  UR                  5       UR                  4v   U R                   R                  [        U5      * [        5        M     g 7f)Nr   ry  )r   r  r  r  r  r  r  r!   r?   rQ   r   r   r	   )r/   progressry  r   r;   rt   rz   s          r$   r  PackData.iterobjects  s     

))*q$++a/0AZZ__&F,

} H #--.&&	  JJOOS[L(3 1s   C*C,c              #     #    U R                   R                  U R                  5        U R                  c  g [	        U R                  5       Hq  nU R                   R                  5       n[        U R                   R                  SS9u  p4X#l        Uv   U R                   R                  [        U5      * [        5        Ms     g 7f)NFr  )r   r  r  r  r  r  r  r!   r;   r   r	   )r/   r   r;   rt   rz   s        r$   _iter_unpackedPackData._iter_unpacked  s      	

))*$t(()AZZ__&F,TZZ__ERH$ONJJOOS[L(3 *s   B?Cc              #      #    U R                   nU R                  b  U R                  R                  OSn[        R	                  XS9n[        U5       H  u  pVUb  U" XR5        Uv   M     g7f)zYield 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)
Nr  )r  r  r  PackIndexerfor_pack_dataru  )r/   r  rl  r  indexerr   results          r$   r   PackData.iterentries  sd      ''7;yy7L$))33RV++D+R"7+IA#(L ,s   A)A+c                 6    [        U R                  US95      nU$ )zReturn entries in this pack, sorted by SHA.

Args:
  progress: Progress function, called with current and total
    object count
Returns: List of tuples with (sha, offset, crc32)
r  )sortedr   )r/   r  r"   s      r$   sorted_entriesPackData.sorted_entries  s!     T%%x%89
r&   c                     U R                  US9n[        US5       n[        XCU R                  5       5      sSSS5        $ ! , (       d  f       g= f)zCreate a version 1 file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
r  wbN)r  r   write_pack_index_v1r(  r/   r   r  r   r   s        r$   create_index_v1PackData.create_index_v1  B     %%x%8Xt$&q43J3J3LM %$$   A  
Ac                     U R                  US9n[        US5       n[        XCU R                  5       5      sSSS5        $ ! , (       d  f       g= f)zCreate a version 2 index file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
r  r"  N)r  r   write_pack_index_v2r(  r$  s        r$   create_index_v2PackData.create_index_v2  r'  r(  c                 z    US:X  a  U R                  X5      $ US:X  a  U R                  X5      $ [        SU-  5      e)zCreate an  index file for this data file.

Args:
  filename: Index filename.
  progress: Progress report function
Returns: Checksum of index file
r   r   zunknown index format %d)r%  r+  rm   )r/   r   r  r   s       r$   create_indexPackData.create_index  sE     a<'';;\'';;6@AAr&   c                 x    U R                   R                  S[        5        U R                   R                  S5      $ )z1Return the expected checksum stored in this pack.r1  r;  )r   r  r
   r!   rI   s    r$   r)  PackData.get_stored_checksum  s'    

X&zzr""r&   c                 d    U R                  5       nU R                  5       nX:w  a  [        X!5      eg)z#Check the consistency of this pack.Nr'  r*  s      r$   r-  PackData.check	  r/  r&   c                     XR                   :  d   eU R                  R                  U5        [        U R                  R                  SS9u  p#UR
                  UR                  UR                  4$ )zGiven offset in the packfile return compressed data 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.
T)ru   )r  r   r  r  r!   r?   r@   rA   r/   r;   rt   r   s       r$   get_compressed_data_atPackData.get_compressed_data_at  sa     *****

#DJJOO$G""  
 	
r&   c                     U R                   U   $ ! [         a     Of = fXR                  :  d   eU R                  R	                  U5        [        U R                  R                  5      u  p#UR                  UR                  5       4$ )zGiven 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.
)	r  r   r  r   r  r  r!   r?   rQ   r5  s       r$   r  PackData.get_object_at   sw    	%%f-- 		*****

#DJJOO4&&88s    
)r   r   r  r  r  r   r  rh  r+   r   )Nr   )!r2   r3   r4   r5   rj   r0   r>  r   r   classmethodr  r  r  r  r  rZ   r  r   r(  r  r  r  r  r   r  r%  r+  r.  r)  r-  r6  r  r6   r7   r&   r$   r  r    s    4, 0 0   4 4 " "
!B!"(!T4$4  	
N
NB#
3
 9r&   r  c                   z    \ rS rSrSrSrSrSS jr\SS j5       r	S r
S rS	 rS
 rS rS rS rS rS rS rSrg)DeltaChainIteratori1  ap  Abstract 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)
FNc                     Xl         X l        [        [        5      U l        [        [        5      U l        / U l        0 U l        / U l        g r+   )	r   _resolve_ext_refr   r  _pending_ofs_pending_ref	_full_ofs_shas	_ext_refs)r/   file_objr  s      r$   r0   DeltaChainIterator.__init__I  s<    
 /'-'-
r&   c                     U " S US9nUR                  U5        UR                  5        H  nUR                  U5        M     U$ )Nr  )set_pack_datar  r  )r  	pack_datar  walkerrt   s        r$   r   DeltaChainIterator.for_pack_dataR  s@    T?;Y'!002HMM(# 3r&   c                 @   UR                   nUR                  nU[        :X  a-  X1R                  -
  nU R                  U   R                  U5        g U[        :X  a)  U R                  UR                     R                  U5        g U R                  R                  X245        g r+   )	r?   r;   rv  r@   r?  r   rw  r@  rA  )r/   rt   r{  r;   r  s        r$   r  DeltaChainIterator.recordZ  s    ))y  #6#66Kk*11&9"h11299&ANN!!6"45r&   c                 &    UR                   U l         g r+   )r   )r/   rH  s     r$   rG   DeltaChainIterator.set_pack_datae  s    __
r&   c              #      #    U R                    H"  u  pU R                  XS 5       H  nUv   M	     M$     U R                  5        H  nUv   M	     U R                  (       a   eg 7fr+   )rA  _follow_chain_walk_ref_chainsr?  )r/   r;   r{  r  s       r$   _walk_all_chains#DeltaChainIterator._walk_all_chainsh  s_      $F,,VtD E !/ ++-FL .$$$$$s   A"A$c                     U R                   (       a/  [        U R                    Vs/ s H  n[        U5      PM     sn5      eg s  snf r+   )r@  r   r   )r/   rf   s     r$   _ensure_no_pending%DeltaChainIterator._ensure_no_pendingp  s9    43D3DE3DaJqM3DEFF Es   Ac              #     #    U R                   (       d  U R                  5         g [        U R                  R	                  5       5       H  u  pXR                  ;  a  M   U R                  U5      u  p4U R                  R                  U5        U R                  R                  U5        U H   nU R                  XSU5       H  nUv   M	     M"     M     U R                  5         g ! [
         a     M  f = f7fr+   )
r>  rU  r  r@  itemsr   rC  r   poprP  )r/   base_shapendingr{  rp  
new_offsetr  s          r$   rQ  #DeltaChainIterator._walk_ref_chainst  s     $$##%!'(9(9(?(?(A!BH000#'#8#8#B  NN!!(+!!(+%
"00vNF L O & "C  	!   	s+   AC4C#2A1C4#
C1-C40C11C4c                     U$ r+   r7   r/   rt   s     r$   _resultDeltaChainIterator._result  s    r&   c                 N   U R                   R                  U5        [        U R                   R                  U R                  U R
                  S9u  pEXl        Uc  UR                  U:X  d   e U$ UR                  [        ;   d   eX$l	        [        X4R                  5      Ul        U$ )N)ru   ry  )r   r  r  r!   _include_comp_compute_crc32r;   r?   rE   r=   r  rB   r>   )r/   r;   r=   base_chunksrt   r   s         r$   _resolve_object"DeltaChainIterator._resolve_object  s    

#JJOO++--

 !))\999
  ))[888$0!"-k;Q;Q"RHr&   c              #   `  ^#    XU4/nU H  u  pnU R                  XU5      mU R                  T5      v   [        U R                  R	                  TR
                  / 5      U R                  R	                  TR                  5       / 5      5      nUR                  U4S jU 5       5        M     g 7f)Nc              3   V   >#    U  H  nUTR                   TR                  4v   M      g 7fr+   )r=   r>   ).0r\  rt   s     r$   	<genexpr>3DeltaChainIterator._follow_chain.<locals>.<genexpr>  s+      "+J X22H4G4GH"+s   &))	rf  r`  r   r?  rY  r;   r@  rJ   r  )r/   r;   r=   re  r  	unblockedrt   s         @r$   rP   DeltaChainIterator._follow_chain  s      {3415-F+++F+NH,,x((!!%%hoor:!!%%hllnb9I KK "+  26s   B+B.c                 "    U R                  5       $ r+   )rR  rI   s    r$   r   DeltaChainIterator.__iter__  s    $$&&r&   c                     U R                   $ r+   )rC  rI   s    r$   ext_refsDeltaChainIterator.ext_refs  s    ~~r&   )rC  r   rA  r?  r@  r>  rB  r+   )r2   r3   r4   r5   rj   rd  rc  r0   r:  r  r  rG  rR  rU  rQ  r`  rf  rP  r   rr  r6   r7   r&   r$   r<  r<  1  s_    ( NM  	6%%G". "'r&   r<  c                   "    \ rS rSrSrSrS rSrg)r  i  z/Delta chain iterator that yields index entries.Tc                 P    UR                  5       UR                  UR                  4$ r+   )rJ   r;   r   r_  s     r$   r`  PackIndexer._result  s    ||~x>>r&   r7   N)r2   r3   r4   r5   rj   rd  r`  r6   r7   r&   r$   r  r    s    9N?r&   r  c                       \ rS rSrSrS rSrg)PackInflateri  z1Delta chain iterator that yields ShaFile objects.c                 "    UR                  5       $ r+   )rN   r_  s     r$   r`  PackInflater._result  s      ""r&   r7   N)r2   r3   r4   r5   rj   r`  r6   r7   r&   r$   rx  rx    s
    ;#r&   rx  c                   :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g)
SHA1Readeri  AWrapper for file-like object that remembers the SHA1 of its data.c                 0    Xl         [        S5      U l        g Nr&   r   r   r/   r   s     r$   r0   SHA1Reader.__init__  s    I	r&   Nc                 r    U R                   R                  U5      nU R                  R                  U5        U$ r+   )r   r!   r   r   )r/   r  rg   s      r$   r!   SHA1Reader.read  s+    vv{{3		r&   c                     U R                   R                  S5      nXR                  R                  5       :w  a-  [	        U R                  R                  5       [        U5      5      eg r_  )r   r!   r   r2  r   r   r   )r/   r,  s     r$   	check_shaSHA1Reader.check_sha  sJ    RYY%%''"499#6#6#8*V:LMM (r&   c                 6    U R                   R                  5       $ r+   )r   r  rI   s    r$   r  SHA1Reader.close  s    vv||~r&   c                 6    U R                   R                  5       $ r+   r   r  rI   s    r$   r  SHA1Reader.tell      vv{{}r&   r  r+   )r2   r3   r4   r5   rj   r0   r!   r  r  r  r6   r7   r&   r$   r|  r|    s    K
N
r&   r|  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)
SHA1Writeri  r}  c                 >    Xl         SU l        [        S5      U l        g )Nr   r&   r   r  r   r  s     r$   r0   SHA1Writer.__init__  s    I	r&   c                     U R                   R                  U5        U R                  R                  U5        U =R                  [        U5      -  sl        g r+   )r   r   r   r  r  r   )r/   rg   s     r$   r  SHA1Writer.write  s6    		Ts4y r&   c                     U R                   R                  5       n[        U5      S:X  d   eU R                  R	                  U5        U =R
                  [        U5      -  sl        U$ r_  )r   r2  r   r   r  r  r   s     r$   	write_shaSHA1Writer.write_sha  sK    ii 3x2~~Ss3x
r&   c                 Z    U R                  5       nU R                  R                  5         U$ r+   )r  r   r  r   s     r$   r  SHA1Writer.close  s     nn
r&   c                     U R                   $ r+   )r  rI   s    r$   r;   SHA1Writer.offset  s    {{r&   c                 6    U R                   R                  5       $ r+   r  rI   s    r$   r  SHA1Writer.tell  r  r&   r  N)r2   r3   r4   r5   rj   r0   r  r  r  r;   r  r6   r7   r&   r$   r  r    s#    K
!

r&   r  c                    / nU S-  US-  -  nUS-  nU(       a'  UR                  US-  5        US-  nUS-  nU(       a  M'  UR                  U5        U [        :X  aO  US-  /nUS-  nU(       a+  US-  nUR                  SSUS-  -  5        US-  nU(       a  M+  UR                  U5        OU [        :X  a  [        U5      S:X  d   eX1-  n[        U5      $ )	zCreate 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   rs  r   rt  r   r   r   r;  )r   rv  insertr  rw  r   r  )r{  r@   r   rk  cr"   s         r$   pack_object_headerr    s     F	Q4"9%AQJD
a$h4K
 $ MM!9D !q
!OJJJq$*t"3451J j 	c	Y	:"$$$Vr&   c           	      $   U[         ;   a  Uu  pROSn[        [        X[        U5      5      5      n[        R
                  " X$5      nSnXg4 H>  n	U R                  U	5        Ub  UR                  U	5        [        R                  " X5      nM@     US-  $ )zWrite pack object to a file.

Args:
  f: File to write to
  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
Nr   rl   )
rE   r6  r  r   rn   compressr  r   r   r   )
r   r  objectrJ   compression_levelr@   rk  	comp_datar   rg   s
             r$   write_pack_objectr    s     {#
F
%dFDEFf8IE#	?JJtt+	 $
 :r&   c           
      Z   [        U S-   S5       n[        UUUUUS9u  pgSSS5        [        WR                  5        VV	s/ s H  u  pXS   U	S   4PM     sn	n5      n[        U S-   S5       nW[	        XVU5      4sSSS5        $ ! , (       d  f       Nk= fs  sn	nf ! , (       d  f       g= f)aj  Write a new pack data file.

Args:
  filename: Path to the new pack file (without .pack extension)
  objects: Iterable of (object, path) tuples to write.
    Should provide __len__
  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
.packr"  )delta_window_sizedeltifyr  Nr   r   .idx)r   write_pack_objectsr  rX  r*  )
r   objectsr  r  r  r   r   data_sumkvs
             r$   
write_packr  6  s    $ 
G#T	*a.//
 
+ GMMODO&1qA$!oODEG	F"D	)Q,QBB 
*	) 
+	* E	)	)s   B B
-B
B
B*c                     U R                  S5        U R                  [        R                  " SS5      5        U R                  [        R                  " SU5      5        g)z4Write a pack header for the given number of objects.ri  r   r   N)r  r   r  )r   rl  s     r$   write_pack_headerr  U  s<    GGGGGFKKq!"GGFKK{+,r&   c              #     #    Uc  [         n/ nU  H2  u  p4UR                  UR                  XCR                  5       * U45        M4     UR	                  5         [        5       nU H  u  pdpxUR                  5       n	U	n
SnU Hi  nUR                  U:w  a  M  [        UR                  5       U	5      n[        U5      [        U
5      :  d  MI  UR                  5       R                  5       nUn
Mk     XhR                  5       R                  5       X4v   UR                  U5        [        U5      U:  d  M  UR                  5         [        U5      U:  a  M!  M     g7f)zGenerate 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
N)DEFAULT_PACK_DELTA_WINDOW_SIZEr   r{  
raw_lengthsortr   as_raw_stringcreate_deltar   rJ   r2  
appendleftrY  )r  window_sizemagicr-   r   possible_basesr{  
neg_lengthorawwinnerwinner_basebaser
  s                 r$   deltify_pack_objectsr  \  s"     4 E	cllD>>+;*;SAB 	JJLWN).%
oo"D}}( !3!3!5s;E5zCK'"hhj//1 # (+==!!!$.!K/  .!K/ */s   CEA$E/EEc                 .    [        U 5      nUS U  5       4$ )zCreate pack data from objects

Args:
  objects: Pack objects
Returns: Tuples with (type_num, hexdigest, delta base, object chunks)
c              3      #    U  HA  u  pUR                   UR                  5       R                  5       S UR                  5       4v   MC     g 7fr+   )r{  rJ   r2  r  )rj  r  r   s      r$   rk  'pack_objects_to_data.<locals>.<genexpr>  s:      	
$	 ZZ)41BC$s   A	A)r   )r  counts     r$   pack_objects_to_datar    s'     LE	
$	
 r&   c                 z    Uc  SnU(       a  [        X5      n[        U5      nO[        U5      u  pe[        U UUUS9$ )a  Write a new pack data file.

Args:
  f: File to write to
  objects: Iterable of (object, path) tuples to write.
    Should provide __len__
  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
Fr  )r  r   r  write_pack_data)r   r  r  r  r  pack_contentspack_contents_counts          r$   r  r    sN      ,WH!'l-A'-J*	+	 r&   c                 \   0 n[        U 5      n [        X5        [        U5       H\  u  nu  pxpUb  U" SXa4-  R                  S5      5        U R	                  5       nU	b   XY   u  p[
        nX-
  U
4n
[        XXS9nX4XX'   M^     XPR                  5       4$ ! [         a    [        nX4n
 N9f = f)a7  Write a new pack data file.

Args:
  f: File to write to
  num_records: Number of records
  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
zwriting pack data: %d/%dr~   r  )
r  r  ru  r   r;   rv  r   rw  r  r  )r   num_recordsrecordsr  r  r   r   r{  	object_idr@   r  r;   r  
base_crc32r   s                  r$   r  r    s     G1Aa%5>w5G11H2a5EEMMgVW!2*1*='
 %+S1!!sX$_ 6H KKM!!  ($!'(s   BB+*B+c                    [        U 5      n [        S 5      nU H  u  pEnU[        USS 5      ==   S-  ss'   M!     [        S5       H<  nU R	                  [
        R                  " SX7   5      5        X7S-   ==   X7   -  ss'   M>     U H=  u  pEnUS::  d  [        S5      eU R	                  [
        R                  " SXT5      5        M?     [        U5      S	:X  d   eU R	                  U5        U R                  5       $ )
zWrite 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                      gr   r7   r7   r&   r$   <lambda>%write_pack_index_v1.<locals>.<lambda>      r&   Nr   r   r!  rl   z)pack format 1 only supports offsets < 2GbrF  r;  )
r  r   r    r  r  r   r  	TypeErrorr   r  )r   r   r   fan_out_tabler   r;   entry_checksumr   s           r$   r#  r#    s     	1A	*M*1&~c$r(m$)$ +2 5\	D-"234!e 00  +2&~*$GHH	GV23 +2 }###GGM;;=r&   c                     [        5       nU S-  nU S-  n U (       a'  UR                  US-  5        U S-  nU S-  n U (       a  M'  UR                  U5        U$ )Nrt  r   r   )r  r   )r   r"   r  s      r$   _delta_encode_sizer    sY    
+CtAQJD


1t84K
 $ JJqMJr&   i  c                 B   / nSn[        S5       H6  nU SUS-  -  -  (       d  M  UR                  XS-  -	  S-  5        USU-  -  nM8     [        S5       H9  nUSUS-  -  -  (       d  M  UR                  XS-  -	  S-  5        USSU-   -  -  nM;     [        U/U-   5      $ )Nr   r      r   r   r   )r  r   r  )r   r  scratchopr   s        r$   _encode_copy_operationr    s    G	B1X41q5=  NNEUNd23!q&LB  1XDAEM!!NNF!eOt34!A,B  bTG^$$r&   c                    [        U [        5      (       d   e[        U[        5      (       d   e[        5       nU[        [	        U 5      5      -  nU[        [	        U5      5      -  n[
        R                  " XS9nUR                  5        H  u  pEpgnUS:X  a:  Un	Xe-
  n
U
S:  a.  [        U
[        5      nU[        X5      -  nX-  n	X-  n
U
S:  a  M.  US:X  d  US:X  d  MU  X-
  nUnUS:  a6  UR                  S5        U[        XUS-    5      -  nUS-  nUS-  nUS:  a  M6  UR                  U5        U[        XX-    5      -  nM     [        U5      $ )zUse python difflib to work out how to transform base_buf to target_buf.

Args:
  base_buf: Base buffer
  target_buf: Target buffer
)ar#   equalr   replacer  rt  )rU   r6  r  r  r   difflibSequenceMatcherget_opcodesr  _MAX_COPY_LENr  r   )base_buf
target_bufout_bufseqopcodei1i2j1j2
copy_startcopy_lento_copyrf   r  s                 r$   r  r    sj    h&&&&j%((((kG!#h-00G!#j/22G

!
!H
;C"%//"3BB W JwHQ,h61*FF%
#	 Q,
 Y&H"4 AAc's#9ZAG%<==SS	 c'
 NN1y!677G3 #44 >r&   c                    [        U [        5      (       d  SR                  U 5      n [        U[        5      (       d  SR                  U5      n/ nSn[        U5      nS nU" X5      u  pcU" X5      u  psU[        U 5      :X  d   SU[        U 5      4-  5       eX4:  Ga  [	        XUS-    5      nUS-  nUS-  (       a  Sn	[        S5       H1  n
USU
-  -  (       d  M  [	        XUS-    5      nUS-  nXU
S-  -  -  n	M3     Sn[        S	5       H4  n
USSU
-   -  -  (       d  M  [	        XUS-    5      nUS-  nXU
S-  -  -  nM6     US:X  a  S
nX-   U:  d  X-   U:  d  X:  a  OIUR                  X	X-    5        O+US:w  a  UR                  XX8-    5        X8-  nO[        S5      eX4:  a  GM  X4:w  a  [        SXS -  5      eU[        U5      :w  a  [        S5      eU$ )zrBased on the similar function in git's patch-delta.c.

Args:
  src_buf: Source buffer
  delta: Delta instructions
r&   r   c                     SnSnU (       a;  [        XUS-    5      nUS-  nX$S-  U-  -  nUS-  nUS-  (       d   X!4$ U (       a  M;  X!4$ )Nr   r   ir   r   )r    )r
  r   r   r   cmds        r$   get_delta_header_size*apply_delta.<locals>.get_delta_header_sizeK  sh    eEAI./CQJE5[Q&&DFA:{ e {r&   z%d vs %dr   r   r   r   rj     zInvalid opcode 0zdelta not empty: %rNzdest size incorrect)	rU   r6  re   r   r    r  r   r   rq  )src_bufr
  outr   delta_lengthr  src_size	dest_sizer  cp_offr   xcp_sizes                r$   r  r  <  s    gu%%((7#eU##
CEu:L
 ,E9OH,U:Is7|#JZ8S\2J%JJ#

%	*+
:F1X!q&>>E%!)45AQJEAEl*F	 
 G1X!A,''E%!)45AQJEQU|+G	 
 !|! 7*#h.&JJw(89:AXJJuU[12LE!"455= 
@ 3eFmCDDM#&&344Jr&   c           
         [        U 5      n U R                  S5        U R                  [        R                  " SS5      5        [	        S 5      nU H  u  pEnU[        USS 5      ==   S-  ss'   M!     / n[        S5       H<  nU R                  [        R                  " SX8   5      5        X8S-   ==   X8   -  ss'   M>     U H  u  pEnU R                  U5        M     U H,  u  pEnU R                  [        R                  " SU5      5        M.     U Hw  u  pEnUS	:  a(  U R                  [        R                  " SU5      5        M4  U R                  [        R                  " SS	[        U5      -   5      5        UR                  U5        My     U H)  nU R                  [        R                  " S
U5      5        M+     [        U5      S:X  d   eU R                  U5        U R                  5       $ )zWrite 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                      gr   r7   r7   r&   r$   r  %write_pack_index_v2.<locals>.<lambda>  r  r&   Nr   r   r   rb  s   >Qr;  )
r  r  r   r  r   r    r  r   r   r  )	r   r   r   r  r   r;   r  
largetabler   s	            r$   r*  r*    s    	1AGGJGGFKKa !	*M*1&~c$r(m$)$ +2 J5\	E=#345!e 00  +2&~	 +2*1&~	E>23 +2*1&~GGGFKKv./GGFKKwZ'@ABf% +2 	E6*+ }###GGM;;=r&   c                       \ rS rSrSrSS jr\S 5       r\S 5       rS r	\
S 5       r\
S	 5       rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSS jrSrg)Packi  zA Git pack object.Nc                    ^  UT l         S T l        S T l        T R                   S-   T l        T R                   S-   T l        U 4S jT l        U 4S jT l        UT l        g )Nr  r  c                  .   > [        T R                  5      $ r+   )r  
_data_pathrI   s   r$   r  Pack.__init__.<locals>.<lambda>  s    (4??";r&   c                  .   > [        T R                  5      $ r+   )r   	_idx_pathrI   s   r$   r  r    s    !@r&   )	_basename_data_idxr  r  
_data_load	_idx_loadr  )r/   r  r  s   `  r$   r0   Pack.__init__  sN    !
	&0..72;@.r&   c                 .    U " S5      nXl         X#l        U$ )zLCreate a new pack object from callables to load pack data and
index objects. )r  r  )r  data_fnidx_fnr"   s       r$   from_lazy_objectsPack.from_lazy_objects  s     "g 
r&   c                     U " S5      nXl         X3R                   l        SUl        X#l        SUl        UR                  5         U$ )z:Create a new pack object from pack data and index objects.r  N)r  r  r  r  r  check_length_and_checksum)r  rg   r   r"   s       r$   from_objectsPack.from_objects  s?     "g			%%'
r&   c                 6    U R                   R                  5       $ )z2The SHA over the SHAs of the objects in this pack.)r   r   rI   s    r$   r   	Pack.name  s    zz&&((r&   c                     U R                   c5  U R                  5       U l         X R                   l        U R                  5         U R                   $ )z The pack data object being used.)r  r  r  r  rI   s    r$   rg   	Pack.data  s;     ::*DJ"JJO**,zzr&   c                 ^    U R                   c  U R                  5       U l         U R                   $ )z<The index being used.

Note: This may be an in-memory index
)r  r  rI   s    r$   r   
Pack.index  s&     99(DIyyr&   c                     U R                   b  U R                   R                  5         U R                  b  U R                  R                  5         g g r+   )r  r  r  rI   s    r$   r  
Pack.close  s9    ::!JJ99 IIOO !r&   c                     U $ r+   r7   rI   s    r$   r  Pack.__enter__  r  r&   c                 $    U R                  5         g r+   r  r  s       r$   r  Pack.__exit__  r  r&   c                 l    [        U [        U5      5      =(       a    U R                  UR                  :H  $ r+   )rU   r  r   r]   s     r$   rZ   Pack.__eq__  s%    $U,Ju{{1JJr&   c                 ,    [        U R                  5      $ )zNumber of entries in this pack.)r   r   rI   s    r$   r   Pack.__len__  s    4::r&   c                 R    U R                   R                  < SU R                  < S3$ )Nrb   rc   )rd   r2   r  rI   s    r$   rh   Pack.__repr__  s    >>22DNNCCr&   c                 ,    [        U R                  5      $ )z7Iterate over all the sha1s of the objects in this pack.)r   r   rI   s    r$   r   Pack.__iter__  s    DJJr&   c                    [        U R                  5      [        U R                  5      :X  d   eU R                  R                  5       nU R                  R	                  5       nX:w  a  [        [        U5      [        U5      5      eg)z@Sanity check the length and checksum of the pack index and data.N)r   r   rg   r   r)  r   r   )r/   idx_stored_checksumdata_stored_checksums      r$   r  Pack.check_length_and_checksum  sp    4::#dii.000"jj::<#yy<<>6".//0  7r&   c                     U R                   R                  5         U R                  R                  5         U R                  5        H  nUR                  5         M     g)zlCheck the integrity of this pack.

Raises:
  ChecksumMismatch: if a checksum for the index or data is wrong
N)r   r-  rg   r  r.   s     r$   r-  
Pack.check
  s>     	

		##%CIIK &r&   c                 6    U R                   R                  5       $ r+   )rg   r)  rI   s    r$   r)  Pack.get_stored_checksum  s    yy,,..r&   c                 \     U R                   R                  U5        g! [         a     gf = f)z3Check whether this pack contains a particular SHA1.TF)r   r   r   )r/   r   s     r$   __contains__Pack.__contains__  s.    	JJ##D) 		s    
++c                     U R                   R                  U5      nU R                  R                  U5      u  p4nU[        :X  a,  [        U R                   R                  X$-
  5      5      n[        nX4U4$ )zGet raw unresolved data for a SHA.

Args:
  sha1: SHA to return data for
Returns: Tuple with pack object type, delta base (if applicable),
    list of data chunks
)r   r   rg   r6  rv  r   r   rw  )r/   r   r;   obj_typer@   rp  s         r$   get_raw_unresolvedPack.get_raw_unresolved!  se     ((.)-)I)I&)Q&vy #DJJ$:$:6;N$OPJ Hf--r&   c                     U R                   R                  U5      nU R                  R                  U5      u  p4U R                  R	                  X#U5      u  pVUSR                  U5      4$ r  )r   r   rg   r  r  re   )r/   r   r;   rB  r-   r{  rp  s          r$   get_rawPack.get_raw0  sY    ((.		//79933FcJ&)))r&   c                 R    U R                  U5      u  p#[        R                  " X#US9$ )zRetrieve the specified SHA1.)rJ   )rF  r   from_raw_string)r/   r   r  uncomps       r$   __getitem__Pack.__getitem__6  s%    ||D)&&t>>r&   c                 d    [        [        R                  U R                  U R                  S95      $ )z&Iterate over the objects in this pack.r  )r   rx  r  rg   r  rI   s    r$   r  Pack.iterobjects;  s,    &&tyy$BVBV&W
 	
r&   c                 0     " S S[         5      nU" U 5      $ )zProvide an iterable for use with write_pack_objects.

Returns: Object that can iterate over (object, path) tuples
    and provides __len__
c                   &    \ rS rSrS rS rS rSrg)+Pack.pack_tuples.<locals>.PackTupleIterableiH  c                     Xl         g r+   r  )r/   r  s     r$   r0   4Pack.pack_tuples.<locals>.PackTupleIterable.__init__I  s     	r&   c                 ,    [        U R                  5      $ r+   )r   r  rI   s    r$   r   3Pack.pack_tuples.<locals>.PackTupleIterable.__len__L  s    499~%r&   c                 D    S U R                   R                  5        5       $ )Nc              3   (   #    U  H  oS 4v   M
     g 7fr+   r7   )rj  r  s     r$   rk  GPack.pack_tuples.<locals>.PackTupleIterable.__iter__.<locals>.<genexpr>P  s     C+BaD	+Bs   )r  r  rI   s    r$   r   4Pack.pack_tuples.<locals>.PackTupleIterable.__iter__O  s    C499+@+@+BCCr&   rS  N)r2   r3   r4   r5   r0   r   r   r6   r7   r&   r$   PackTupleIterablerQ  H  s    !&Dr&   r[  )r  )r/   r[  s     r$   pack_tuplesPack.pack_tuplesA  s    	D 	D !&&r&   c                     SU R                   -  n[        US5       nU(       a"  UR                  U5        UR                  S5        SSS5        U$ ! , (       d  f       U$ = f)zAdd 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%s.keepr"     
N)r  r   r  )r/   msgkeepfile_namekeepfiles       r$   keep	Pack.keepT  sW     "DNN2]D)Xs#u% * 	 *) s   *A
A)r  r  r  r  r  r  r  r  r+   )r2   r3   r4   r5   rj   r0   r:  r  r   r   r>  rg   r   r  r  r  rZ   r   rh   r   r  r-  r)  r?  rC  rF  rK  r  r\  rc  r6   r7   r&   r$   r  r    s    /   	 	)    KD 		/.*?

'&r&   r  )r  r   r+   )r   r   r  )Nr   )NNr   )Yrj   collectionsr   r   ior   r   r   r  r   	itertoolsr   r   syshashlibr   r	   r
   r   rn   r   r   ImportErrorplatformdulwich.errorsr   r   dulwich.filer   dulwich.lru_cacher   dulwich.objectsr   r   r   r   rv  rw  rE   r  r%   	Exceptionr(   r  r9   r  r|   r   r   r   r   r   r   r   r   r   r   rm  rq  r  r  r  r  rH   r  r  r<  r  rx  r|  r  r  r  r  r  r  r  r  r  r#  r  r  r  r  r  r*  write_pack_indexr  dulwich._packr7   r&   r$   <module>rs     s  , $  ,    	 
    H <<7H !  		)$ "$ ) 
LEV LE^  ',=@
+-,F&.W1 W1t"#i "#JK&I K&\ 2&V &VR"(% FRJOv JOZ(' (V	8w9v w9t	B BJ?$ ?#% # 0 @>8 C>-#!L$ IKB"B6	 %)XDN#L ' u6 up	 SA  HZA  		s$   
F; 2G
 ;GG
GG