Ë
    ómxiu  ã                   ó„   — d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlZddlZdZ G d	„ d
eeee«      Zy)z/Module containing a database to deal with packsé    )Ú
FileDBBaseÚ	ObjectDBRÚ	CachingDB)Ú	LazyMixin)Ú	BadObjectÚUnsupportedOperationÚAmbiguousObjectName)Ú
PackEntity)ÚreduceN)ÚPackedDBc                   óp   ‡ — e Zd ZdZdZˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zdd„Zd„ Zd„ Zˆ xZS )r   z-A database operating on a set of object packsiô  c                 ó@   •— t         ‰| �  |«       d| _        d| _        y ©Nr   )ÚsuperÚ__init__Ú
_hit_countÚ	_st_mtime)ÚselfÚ	root_pathÚ	__class__s     €úD/home/htdocs/ttos/venv/lib/python3.12/site-packages/gitdb/db/pack.pyr   zPackedDB.__init__)   s    ø€ Ü‰Ñ˜Ô#ð ˆŒØˆ�ó    c                 óR   — |dk(  r"t        «       | _        | j                  d¬«       y y )NÚ	_entitiesT)Úforce)Úlistr   Úupdate_cache)r   Úattrs     r   Ú_set_cache_zPackedDB._set_cache_3   s)   € Ø�;ÒÜ!›VˆDŒNØ×Ñ DÐÕ)ð r   c                 ó@   — | j                   j                  d„ d¬«       y )Nc                 ó   — | d   S r   © )Úls    r   ú<lambda>z)PackedDB._sort_entities.<locals>.<lambda>:   s
   € ¨!¨A©$€ r   T)ÚkeyÚreverse)r   Úsort)r   s    r   Ú_sort_entitieszPackedDB._sort_entities9   s   € Ø�‰×Ñ¡¸ÐÕ=r   c                 ó  — | j                   | j                  z  dk(  r| j                  «        | j                  D ]:  } |d   |«      }|€Œ|dxx   dz  cc<   | xj                   dz  c_         |d   |fc S  t	        |«      ‚)a©  :return: tuple(entity, index) for an item at the given sha
        :param sha: 20 or 40 byte sha
        :raise BadObject:
        **Note:** This method is not thread-safe, but may be hit in multi-threaded
            operation. The worst thing that can happen though is a counter that
            was not incremented, or the list being in wrong order. So we safe
            the time for locking here, lets see how that goesr   é   é   )r   Ú_sort_intervalr(   r   r   )r   ÚshaÚitemÚindexs       r   Ú
_pack_infozPackedDB._pack_info<   s‡   € ð �?‰?˜T×0Ñ0Ñ0°AÒ5Ø×ÑÔ!ð —N‘Nò 	(ˆDØ�D˜‘G˜C“LˆEØÑ Ø�Q“˜1‘“Ø—’ 1Ñ$•Ø˜Q™ Ð'Ò'ð	(ô ˜‹nÐr   c                 óF   — 	 | j                  |«       y# t        $ r Y yw xY w)NTF)r0   r   )r   r-   s     r   Ú
has_objectzPackedDB.has_objectY   s(   € ð	Ø�O‰O˜CÔ ØøÜò 	Ùð	ús   ‚ ”	 Ÿ c                 óL   — | j                  |«      \  }}|j                  |«      S ©N)r0   Úinfo_at_index©r   r-   Úentityr/   s       r   ÚinfozPackedDB.infoa   s%   € ØŸ™¨Ó,‰ˆ�Ø×#Ñ# EÓ*Ð*r   c                 óL   — | j                  |«      \  }}|j                  |«      S r4   )r0   Ústream_at_indexr6   s       r   ÚstreamzPackedDB.streame   s%   € ØŸ™¨Ó,‰ˆ�Ø×%Ñ% eÓ,Ð,r   c              #   ó¾   K  — | j                  «       D ]F  }|j                  «       }|j                  }t        |j	                  «       «      D ]  } ||«      –— Œ ŒH y ­wr4   )Úentitiesr/   r-   ÚrangeÚsize)r   r7   r/   Úsha_by_indexs       r   Úsha_iterzPackedDB.sha_iteri   sT   è ø€ Ø—m‘m“oò 	*ˆFØ—L‘L“NˆEØ Ÿ9™9ˆLÜ˜uŸz™z›|Ó,ò *�Ù" 5Ó)Ó)ñ*ñ	*ùs   ‚AAc                 ó˜   — | j                   D �cg c]#  }|d   j                  «       j                  «       ‘Œ% }}t        d„ |d«      S c c}w )Nr+   c                 ó   — | |z   S r4   r"   )ÚxÚys     r   r$   zPackedDB.size.<locals>.<lambda>t   s
   €  1 q¡5€ r   r   )r   r/   r?   r   )r   r.   Úsizess      r   r?   zPackedDB.sizer   sB   € Ø48·N±NÖC¨D��a‘—‘“×%Ñ%Õ'ÐCˆÐCÜÑ(¨%°Ó3Ð3ùò Ds   �(Ac                 ó   — t        «       ‚)z§Storing individual objects is not feasible as a pack is designed to
        hold multiple objects. Writing or rewriting packs for single objects is
        inefficient)r   )r   Úistreams     r   ÚstorezPackedDB.storez   s   € ô #Ó$Ð$r   c                 ój  — t        j                  | j                  «       «      }|s|j                  | j                  k  ry|j                  | _        t        t        j                  t         j                  j                  | j                  «       d«      «      «      }| j                  D �ch c]#  }|d   j                  «       j                  «       ’Œ% }}||z
  D ]_  }t        |«      }| j                  j                  |j                  «       j                  «       ||j                  «       j                  g«       Œa ||z
  D ]]  }d}t!        | j                  «      D ]-  \  }	}|d   j                  «       j                  «       |k(  sŒ+|	} n |dk7  sJ ‚| j                  |= Œ_ | j#                  «        yc c}w )aÆ  
        Update our cache with the actually existing packs on disk. Add new ones,
        and remove deleted ones. We keep the unchanged ones

        :param force: If True, the cache will be updated even though the directory
            does not appear to have changed according to its modification timestamp.
        :return: True if the packs have been updated so there is new information,
            False if there was no change to the pack databaseFzpack-*.packr+   éÿÿÿÿT)ÚosÚstatr   Úst_mtimer   ÚsetÚglobÚpathÚjoinr   Úpackr
   Úappendr?   r/   Úsha_to_indexÚ	enumerater(   )
r   r   rM   Ú
pack_filesr.   Úour_pack_filesÚ	pack_filer7   Ú	del_indexÚis
             r   r   zPackedDB.update_cache„   sq  € ô �w‰w�t—~‘~Ó'Ó(ˆÙ˜Ÿ™¨$¯.©.Ò8ØàŸ™ˆŒô œŸ™¤2§7¡7§<¡<°·±Ó0@À-Ó#PÓQÓRˆ
Ø<@¿N¹NÖK°D˜$˜q™'Ÿ,™,›.×-Ñ-Õ/ÐKˆÐKð % ~Ñ5ò 	_ˆIô   	Ó*ˆFØ�N‰N×!Ñ! 6§;¡;£=×#5Ñ#5Ó#7¸ÀÇÁÃ×A\ÑA\Ð"]Õ^ð		_ð )¨:Ñ5ò 		+ˆIØˆIÜ$ T§^¡^Ó4ò ‘��4Ø˜‘7—<‘<“>×&Ñ&Ó(¨IÓ5Ø !�IÙðð  ’?Ð"�?Ø—‘˜yÑ)ð		+ð 	×ÑÔØùò3 Ls   Â)(F0c                 óF   — | j                   D �cg c]  }|d   ‘Œ	 c}S c c}w )z=:return: list of pack entities operated upon by this databaser+   )r   )r   r.   s     r   r=   zPackedDB.entities±   s   € à$(§N¡NÖ3˜D��Q“Ò3Ð3ùÒ3s   �c                 óþ   — d}| j                   D ]^  }|d   j                  «       j                  ||«      }|€Œ)|d   j                  «       j                  |«      }|r||k7  rt	        |«      ‚|}Œ` |r|S t        |«      ‚)a£  :return: 20 byte sha as inferred by the given partial binary sha
        :param partial_binsha: binary sha with less than 20 bytes
        :param canonical_length: length of the corresponding canonical representation.
            It is required as binary sha's cannot display whether the original hex sha
            had an odd or even number of characters
        :raise AmbiguousObjectName:
        :raise BadObject: Nr+   )r   r/   Úpartial_sha_to_indexr-   r	   r   )r   Úpartial_binshaÚcanonical_lengthÚ	candidater.   Ú
item_indexr-   s          r   Úpartial_to_complete_shaz PackedDB.partial_to_complete_shaµ   s‹   € ð ˆ	Ø—N‘Nò 	 ˆDØ˜a™Ÿ™›×=Ñ=¸nÐN^Ó_ˆJØÑ%Ø˜1‘g—m‘m“o×)Ñ)¨*Ó5�Ù ¨cÒ!1Ü-¨nÓ=Ð=Ø‘	ð	 ñ ØÐô ˜Ó'Ð'r   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r   r   r(   r0   r2   r8   r;   rA   r?   rI   r   r=   rc   Ú__classcell__)r   s   @r   r   r       sO   ø„ á7ð
 €Nôò*ò>òò:ò+ò-ò*ò4ò%ó+òZ4ö(r   r   )rg   Úgitdb.db.baser   r   r   Ú
gitdb.utilr   Ú	gitdb.excr   r   r	   Ú
gitdb.packr
   Ú	functoolsr   rL   rP   Ú__all__r   r"   r   r   ú<module>ro      sJ   ðñ
 6÷ñ õ !÷ñ õ "å ã 	Û à
€ô
l(ˆz˜9 i°õ l(r   