bg0ddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z e Z ddl Z ddlmZn!#e$rddlmZmZeZddZYnwxYwejZejZejZejjZejZejZejjZejjZej Z ejj!Z!ejj"Z"ejj#Z#ej$Z$ej%Z%ej&Z&ej'Z'dZ(dZ)dd l*m+Z+m,Z,Gd d Z-d Z.ddZ/dZ0ddZ1ddZ2ddZ3dZ4dZ5GddZ6GddZ7dS)N)BytesIO)StaticWindowMapManagerSlidingWindowMapManagerSlidingWindowMapBuffer) unpack_from)unpackcalcsizec t|}n)#t$rt|}|t|<YnwxYwt|||||zSN)__calcsize_cacheKeyErrorr r)fmtdataoffsetsizes [/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/gitdb/util.pyrr!sj )#C(DD ) ) )C==D$( S ! ! ! )c4 56777s #66ctjdkrHtdD]0} ||i|cS#t$rt jdY-wxYw||i|S||i|S)Nwin32 g?)sysplatformrange Exceptiontimesleep)funcargskwargs_s r_retryr Ds |wr  A tT,V,,,,,    3 tT$V$$$tT$V$$$s-A Ac6ttjg|Ri|Sr )r osremove)rrs rr#r#Rs" ") -d - - -f - --) NULL_BIN_SHA NULL_HEX_SHAc6eZdZdZdZd dZdZdZdZdZ d S) _RandomAccessBytesIOzWrapper to provide required functionality in case memory maps cannot or may not be used. This is only really required in python 2.4_sioc.t||_dSr )rr))selfbufs r__init__z_RandomAccessBytesIO.__init__gsCLL r$c,t|j|Sr )getattrr)r,attrs r __getattr__z _RandomAccessBytesIO.__getattr__jsty$'''r$cDt|Sr )lengetvaluer,s r__len__z_RandomAccessBytesIO.__len__ms4==??###r$c6||Sr r6)r,is r __getitem__z _RandomAccessBytesIO.__getitem__ps}}q!!r$c:|||Sr r:)r,startends r __getslice__z!_RandomAccessBytesIO.__getslice__ss}}uSy))r$N)r*) __name__ __module__ __qualname____doc__ __slots__r.r3r8r<r@r$rr(r(ass??I!!!!((($$$"""*****r$r(cF t|S#t$r|cYSwxYw)z Return the integer representation of the byte string. This supports Python 3 byte arrays as well as standard strings. )ord TypeError)bs rbyte_ordrKws6 1vv s   r$c tj|S#t$rddl}||}|cYSwxYw)z`A python2.4 workaround for the sha/hashlib module fiasco **Note** From the dulwich project rN)hashlibsha1 NameErrorsha)sourcerPrNs rmake_sharRsS|F###  wwv s %>>c|dkrtdS tjd|S#t$rtd|zcYSwxYw)zB:return: a file-protocol accessible memory block of the given sizerr$)r(mmapOSError)rs rallocate_memoryrXse qyy#C(((2yT""" 222 $EDL11111 2s,A  A FTc| |rj tj|dtjS#t$r;tj|tj|jtjcYSwxYwn#t$rYnwxYwtj|tj|j}|rt|S|S)a:return: read-only contents of the file represented by the file descriptor fd :param fd: file descriptor opened for reading :param stream: if False, random access is provided, otherwise the stream interface is provided. :param allow_mmap: if True, its allowed to map the contents into memory, which allows large files to be handled and accessed efficiently. The file-descriptor will change its position if this is Falser)access)rV ACCESS_READrWr"fstatst_sizereadr()fdstream allow_mmapcontentss rfile_contents_rorcs   T TyQt/?@@@@ T T TyRXb\\%9$BRSSSSSS T  T      wr28B<</00H .#H--- Os-A/ &AA+(A/*A++A// A<;A<c tj|tjttddz|z} t |||t |S#t |wxYw)a<Get the file contents at filepath as fast as possible :return: random access compatible memory of the given filepath :param stream: see ``file_contents_ro`` :param allow_mmap: see ``file_contents_ro`` :param flags: additional flags to pass to os.open :raise OSError: If the file could not be opened **Note** for now we don't try to use O_NOATIME directly as the right value needs to be shared per database in fact. It only makes a real difference for loose object databases anyway, and they use it with the help of the ``flags`` parameterO_BINARYr)r"openO_RDONLYr0rcclose)filepathr`raflagsr_s rfile_contents_ro_filepathrks^ 2;Z)C)CCeK L LBFJ77 b b s AA,cTtt||S)z :return: a buffer compatible object which uses our mapped memory manager internally ready to read the whole given filepath)rj)rmman make_cursor)rirjs rsliding_ro_bufferros% "$"2"28"<"))r$Fc|jtd|jz||_ttdd}tjtjztjz|z} t j||tdd}|st j |n||_ n7#t$r*}td|z|d}~wwxYw|j U t j|j tj|z|_ n'#t|xYw|rddlm}||j S|j S) a Open the file descriptor for reading or writing, both in binary mode. :param write: if True, the file descriptor will be opened for writing. Other wise it will be opened read-only. :param stream: if True, the file descriptor will be wrapped into a simple stream object which supports only reading or writing :return: fd to read from or write to. It is still maintained by this instance and must not be closed directly :raise IOError: if the lock could not be retrieved :raise OSError: If the actual file could not be opened for reading **note** must only be called onceNzCalled %s multiple timesrer600z Lock at %r could not be obtained)FDStream)rAssertionErrorrfr0r"O_WRONLYO_CREATO_EXCLrintrhrrWrrgr# gitdb.streamr)r,writer`binarylockmoder_ers rrfz LockedFD.open,sp ; " !;di!GHH H Z++;+bi7&@ \++--xUAGGB   \ \ \2;3GHH t))++,,,   - - - - - -8DH%% %8Os%&AB;; C/%C**C/:,D''$E c2|ddS)zWhen done writing, call this function to commit your changes into the actual file. The file descriptor will be closed, and the lockfile handled. **Note** can be called multiple timesT successfulN _end_writingr7s rcommitzLockedFD.commitas! T*****r$c2|ddS)zAbort your operation without any changes. The file descriptor will be closed, and the lock released. **Note** can be called multiple timesFrNrr7s rrzLockedFD.rollbackis! U+++++r$Tc|jtd|jdStj|jd|_|}|jry|rwt jdkr(t|j rt|j tj ||j t|j tdddSt|dS)z,Handle the lock according to the write mode Nz-Cannot end operation if it wasn't started yetr644r)rrrr"rhrrrisfilerr#renamechmodr)r,rlockfiles rrzLockedFD._end_writingps ;  !PQQ Q 8  F %%'' ; : |w&&$.))+4>*** Ih / / / $.#eQ-- 0 0 0 0 0 8     r$N)FF)T) rArBrCrDrEr.rrrfrrrrFr$rrr s B B/I  ***2222j+++,,,r$r)r)r$)FT)FTr)8binasciir"rVrrerrnoiorsmmaprrrrmrMstructr ImportErrorrr dictr a2b_hexrwb2a_hexrrENOENTpathexistsmkdirrisdirrrdirnamebasenamejoinr^rrhfsyncr r# gitdb.constr%r&r(rKrRrXrcrkrortrxrzrrFr$rrs     8""""""" 8 8 8''''''''tvv888888 8"             '/ 7  w| w    % % %... ********,     2 2 2":(KKKK        @~~~~~~~~~~s?AA