yL i0 ddgZddlmZddlmZddlZddlZddlm Z ddl m Z m Z m Z ddlmZmZmZmZmZmZmZddlmZmZmZmZmZdd lmZerdd lmZdd l m!Z!m"Z"dd l#m$Z$Gd dee%e%eee&e&fe%fZ'Gddee'e Z(y)RefLog RefLogEntry)mmapN)defenc) Serializablealtz_to_utctz_str parse_date)ActorLockedFDLockFileassure_directory_exists bin_to_hexfile_contents_ro_filepathto_native_path)IteratorListTuple TYPE_CHECKINGUnion)PathLike)BytesIO)GitConfigParserSectionConstraint)SymbolicReferenceceZdZdZej dZdZdefdZ defdZ e defdZ e defdZ e defd Ze deeeffd Ze defd Zed ed edededededdfdZededdfdZy)rz;Named tuple allowing easy access to the revlog data fields.z^[0-9A-Fa-f]{40}$returnc"|jS)z1Representation of ourselves in git reflog format.)formatselfs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/git/refs/log.py__repr__zRefLogEntry.__repr__1s{{}c |j}|j}dj|j|j|j |j |dt|d|jS)z9:return: A string suitable to be placed in a reflog file.z{} {} {} <{}> {!s} {} {} r) actortimer oldhexsha newhexshanameemailrmessage)r!actr(s r"rzRefLogEntry.format5s]jjyy,33 NN NN HH II G d1g & LL  r$c |dS)z>The hexsha to the commit the ref pointed to before the change.rrr s r"r)zRefLogEntry.oldhexshaC Awr$c |dS)zAThe hexsha to the commit the ref now points to, after the change.r&rr s r"r*zRefLogEntry.newhexshaHr0r$c |dS)z!Actor instance, providing access.rr s r"r'zRefLogEntry.actorMr0r$c |dS)z~Time as tuple: * [0] = ``int(time)`` * [1] = ``int(timezone_offset)`` in :attr:`time.altzone` format rr s r"r(zRefLogEntry.timeRs Awr$c |dS)z=Message describing the operation that acted on the reference.rr s r"r-zRefLogEntry.message[r0r$r)r*r'r( tz_offsetr-cbt|tstd|zt|||||f|fS)z/:return: New instance of a :class:`RefLogEntry`zNeed actor instance, got %s) isinstancer ValueErrorr)clsr)r*r'r(r8r-s r"newzRefLogEntry.new`s:%':UBC CIy%$ 9JGTUUr$linec|jt}|jdd}t|dk(r|dd}}n+t|dk(r|\}}nt dt |z|dd}|dd }||fD]+}|j j|rt d ||jd d } | d k(r t dtj|d | dz} t|| dzd\} } t||| | | f|fS)z:return: New :class:`RefLogEntry` instance from the given revlog line. :param line: Line bytes without trailing newline :raise ValueError: If `line` could not be parsed.  r&rNr3z5Line must have up to two TAB-separated fields. Got %s()QzInvalid hexsha: >RzMissing token: >) decodersplitlenr;repr_re_hexsha_onlymatchfindr _from_stringr r) r<r>line_strfieldsinfomsgr)r*hexsha email_endr'r(r8s r" from_linezRefLogEntry.from_lineps.;;v&a( v;! q 4#D [A ID#TW[\dWeef f"I BK  ), CF&&,,V4 !ABB C IIc2& ?/0 0""4Y]#;<$T)a-/%:;iIy%$ 9JCPQQr$N)__name__ __module__ __qualname____doc__recompilerK __slots__strr#rpropertyr)r*r r'rintr(r- classmethodr=bytesrUrr$r"rr*sIE bjj!56OI#    33ueCHo V V V V  V  V V  V V#RU#R}#R#Rr$cFeZdZdZdZddeedfddffd ZddeedfddfdZd dZ e deddfd Z e d d de fd Z e d ee defdeefdZe dededdfdZdeddfdZe d!deedddfdededede deddfdZd"dZd#dZd#dZxZS)$rakA reflog contains :class:`RefLogEntry`\s, each of which defines a certain state of the head in question. Custom query methods allow to retrieve log entries by date or by other criteria. Reflog entries are ordered. The first added entry is first in the list. The last entry, i.e. the last change of the head or reference, is last in the list. )_pathNfilepathrc&t||}|SN)super__new__)r<rdinst __class__s r"rhzRefLog.__new__sws# r$c8||_||jyy)zInitialize this instance with an optional filepath, from which we will initialize our data. The path is also used to write changes back using the :meth:`write` method.N)rc_read_from_file)r!rds r"__init__zRefLog.__init__s"    " r$c t|jdd} |j||j y#t$rYywxYw#|j wxYw)NT)stream allow_mmap)rrcOSError _deserializeclose)r!fmaps r"rlzRefLog._read_from_filesV ,TZZQUVD     d # JJL    JJLs=A A A  Ac||S)a+ :return: A new :class:`RefLog` instance containing all entries from the reflog at the given `filepath`. :param filepath: Path to reflog. :raise ValueError: If the file could not be read or was corrupted in some way. r)r<rds r" from_filezRefLog.from_files8}r$refrc~tj|jjdt |j S)a :return: String to absolute path at which the reflog of the given ref instance would be found. The path is not guaranteed to point to a valid file though. :param ref: :class:`~git.refs.symbolic.SymbolicReference` instance logs)ospjoinrepogit_dirrpath)r<rws r"r~z RefLog.paths*xx((&.2JKKr$rorc#Ktj}t|trt |}t|t sJ|} |j }|sy||j,w)a- :return: Iterator yielding :class:`RefLogEntry` instances, one for each line read from the given stream. :param stream: File-like object containing the revlog in its native format or string instance pointing to a file to read. N)rrUr:r]rrreadlinestrip)r<ro new_entry_streamr>s r" iter_entrieszRefLog.iter_entriessi )) fc "/7Ggt, ,,G##%DDJJL) ) sA-A/indexrc~t|d5}|dkr=tj|j|j cdddSt |dzD]&}|j }|rtd|dzdtjj cdddS#1swYyxYw)a\ :return: :class:`RefLogEntry` at the given index. :param filepath: Full path to the index file from which to read the entry. :param index: Python list compatible index, i.e. it may be negative to specify an entry counted from the end of the list. :raise IndexError: If the entry didn't exist. :note: This method is faster as it only parses the entry at index, skipping all other lines. Nonetheless, the whole file has to be read if the index is negative. rbrNr&zIndex file ended at line z , before given index was reached)openrrU readlinesrranger IndexError)r<rdrfpir>s r"entry_atzRefLog.entry_ats*(D ! 7Rqy",,R\\^E-B-H-H-JK 7 7 519% j{{}$'@QGg%hii j((6 7 7 7s9B3#B345B33B<ct|}t|d|jdd} |j||j y#t $r|j wxYw)zWrite the contents of the reflog instance to a file at the given filepath. :param filepath: Path to file. Parent directories are assumed to exist. Tis_file)writeroN)r r r _serializecommit BaseExceptionrollback)r!rdlfdrs r"to_filezRefLog.to_files_ x $7 XXDX .  OOB  JJL  LLN  s !AA* config_readerrr oldbinsha newbinshar-rc t|dk7st|dk7r tdt|d|jdd}t |t r|}nt j |}tt|jdt|jd|ttjtjf|f} |r|t|} | jt!|d} | j#| j%j't(| j+| j-| S| S#| j+| j-wxYw) aAppend a new log entry to the revlog at filepath. :param config_reader: Configuration reader of the repository - used to obtain user information. May also be an :class:`~git.util.Actor` instance identifying the committer directly or ``None``. :param filepath: Full path to the log file. :param oldbinsha: Binary sha of the previous commit. :param newbinsha: Binary sha of the current commit. :param message: Message describing the change to the reference. :param write: If ``True``, the changes will be written right away. Otherwise the change will not be written. :return: :class:`RefLogEntry` objects which was appended to the log. :note: As we are append-only, concurrent access is not a problem as we do not interfere with readers. z&Shas need to be given in binary formatTr rasciiab)rIr;r rHr:r committerrrrGr__timer(altzoner _obtain_lock_or_raiserrrencoderrs _release_lock) r<rrdrrr-r first_linerentrylffds r" append_entryzRefLog.append_entry*s4R y>R 3y>R#7EF F$7]]4(+ mU +%I 6I9%,,W59%,,W5UZZ\"EMM2    (#B  $ $ &h%B #..v67   " u    "s 2E"E>cj|j td|j|j|S)zkWrite this instance's data to the file we are originating from. :return: self zBInstance was not initialized with a path, use to_file(...) instead)rcr;rr s r"rz RefLog.writers/ :: ab b TZZ  r$c~|j}|D]+}||jjt-|Srf)rrrr)r!rores r"rzRefLog._serializes<  -A !((*##F+ , - r$cF|j|j||Srf)extendr)r!ros r"rrzRefLog._deserializes D%%f-. r$rf)rN)T)rr)rorrr)rVrWrXrYr\rrrhrmrlr`rvr]r~rrrrr_rrr raboolrrrrr __classcell__)rjs@r"rrsIuXt^4#x~!6#$#    h   L* Ls L L*%Y(<"=*(;BW**2 7 7 7 7 7FT$EU$57JDPQEE E  E  EE EEN  r$))__all__ros.pathr~rzrZr(r git.compatrgit.objects.utilrrr git.utilr r r r rrrtypingrrrrr git.typesrior git.configrrgit.refsrr]r_rrrr$r"rs ] #  ?>=* jR%S%sCx#=>jRZvT+  vr$