
    chu                         S r SSKJrJrJr  SSKJr  SSKJrJ	r	J
r
  SSKJr  SSKJr  SSKrSSKrSr " S	 S
\\\\5      rg)z/Module containing a database to deal with packs    )
FileDBBase	ObjectDBR	CachingDB)	LazyMixin)	BadObjectUnsupportedOperationAmbiguousObjectName)
PackEntity)reduceN)PackedDBc                   |   ^  \ rS rSrSrS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S jrS rS rSrU =r$ )r       z-A database operating on a set of object packsi  c                 @   > [         TU ]  U5        SU l        SU l        g Nr   )super__init__
_hit_count	_st_mtime)self	root_path	__class__s     `C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\gitdb/db/pack.pyr   PackedDB.__init__)   s     #     c                 N    US:X  a  [        5       U l        U R                  SS9  g g )N	_entitiesT)force)listr   update_cache)r   attrs     r   _set_cache_PackedDB._set_cache_3   s)    ;!VDND) r   c                 :    U R                   R                  S SS9  g )Nc                     U S   $ r    )ls    r   <lambda>)PackedDB._sort_entities.<locals>.<lambda>:   s    !A$r   T)keyreverse)r   sort)r   s    r   _sort_entitiesPackedDB._sort_entities9   s    =r   c                 
   U R                   U R                  -  S:X  a  U R                  5         U R                   H<  nUS   " U5      nUc  M  US==   S-  ss'   U =R                   S-  sl         US   U4s  $    [	        U5      e)ay  :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_infoPackedDB._pack_info<   s     ??T000A5! NNDGCLE Q11$Q'' # nr   c                 H     U R                  U5        g! [         a     gf = f)NTF)r5   r   )r   r2   s     r   
has_objectPackedDB.has_objectY   s(    	OOC  		s    
!!c                 J    U R                  U5      u  p#UR                  U5      $ N)r5   info_at_indexr   r2   entityr4   s       r   infoPackedDB.infoa   s#    ,##E**r   c                 J    U R                  U5      u  p#UR                  U5      $ r;   )r5   stream_at_indexr=   s       r   streamPackedDB.streame   s#    ,%%e,,r   c              #      #    U R                  5        HI  nUR                  5       nUR                  n[        UR	                  5       5       H  nU" U5      v   M     MK     g 7fr;   )entitiesr4   r2   rangesize)r   r>   r4   sha_by_indexs       r   sha_iterPackedDB.sha_iteri   sI     mmoFLLNE 99Luzz|,"5)) - &s   AA!c                     U R                    Vs/ s H#  oS   R                  5       R                  5       PM%     nn[        S US5      $ s  snf )Nr0   c                 
    X-   $ r;   r%   )xys     r   r'   PackedDB.size.<locals>.<lambda>t   s    15r   r   )r   r4   rH   r   )r   r3   sizess      r   rH   PackedDB.sizer   sA    48NNCNDa%%'NC(%33 Ds   *A	c                     [        5       e)zStoring 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   storePackedDB.storez   s     #$$r   c                    [         R                  " U R                  5       5      nU(       d  UR                  U R                  ::  a  gUR                  U l        [        [        R                  " [         R                  R                  U R                  5       S5      5      5      nU R                   Vs1 s H#  oDS   R                  5       R                  5       iM%     nnX5-
   H_  n[        U5      nU R                  R                  UR                  5       R                  5       XwR                  5       R                  /5        Ma     XS-
   Ha  nSn[!        U R                  5       H.  u  pUS   R                  5       R                  5       U:X  d  M,  U	n  O   US:w  d   eU R                  U	 Mc     U R#                  5         gs  snf )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-*.packr0   T)osstatr   st_mtimer   setglobpathjoinr   packr
   appendrH   r4   sha_to_index	enumerater,   )
r   r   rZ   
pack_filesr3   our_pack_files	pack_filer>   	del_indexis
             r   r   PackedDB.update_cache   sW    wwt~~'($..8 277<<0@-#PQR
<@NNKNDq',,.--/NK %5I  	*FNN!!6;;=#5#5#7A\A\"]^	 6 )5II$T^^47<<>&&(I5 !I 5 ?"?y) 6 	3 Ls   1*F>c                 J    U R                    Vs/ s H  oS   PM	     sn$ s  snf )z=:return: list of pack entities operated upon by this databaser0   )r   )r   r3   s     r   rF   PackedDB.entities   s     $(NN3NDQN333s    c                    SnU R                    He  nUS   R                  5       R                  X5      nUc  M*  US   R                  5       R                  U5      nU(       a  X6:w  a  [	        U5      eUnMg     U(       a  U$ [        U5      e)as  :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: Nr0   )r   r4   partial_sha_to_indexr2   r	   r   )r   partial_binshacanonical_length	candidater3   
item_indexr2   s          r   partial_to_complete_sha PackedDB.partial_to_complete_sha   s     	NNDa==n_J%1gmmo))*5!1-n==	 #  ''r   )r   r   r   )F)__name__
__module____qualname____firstlineno____doc__r1   r   r!   r,   r5   r8   r?   rC   rJ   rH   rU   r   rF   rr   __static_attributes____classcell__)r   s   @r   r   r       sT    7
 N*>:+-*4%+Z4( (r   r   )rx   gitdb.db.baser   r   r   
gitdb.utilr   	gitdb.excr   r   r	   
gitdb.packr
   	functoolsr   rY   r]   __all__r   r%   r   r   <module>r      sJ   
 6  !  "  	 

l(z9i l(r   