yL iч(dgZddlZddlmZmZddlmZddlmZddl m Z ddl m Z ddl mZmZmZmZmZmZdd lmZmZmZmZmZmZmZmZmZdd lmZm Z erdd l!m"Z"dd l m#Z#dd l m$Z$ddl%m&Z&eddZ'dddee dfde fdZ(GddZ)y)SymbolicReferenceN)BadName BadObject)defenc)Object)Commit)RefLog)LockedFDassure_directory_exists hex_to_bin join_pathjoin_path_nativeto_native_path_linux) AnyIteratorList TYPE_CHECKINGTupleTypeTypeVarUnioncast) AnyGitObjectPathLike)GitConfigParser)Actor) RefLogEntry)Repo T_References)boundreporpathreturnc@|}|dvr |jS|jS)z2Find the git dir that is appropriate for the path.)HEAD ORIG_HEAD FETCH_HEADindexlogs)git_dir common_dir)r!r"names W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/git/refs/symbolic.py_git_dirr.3s&VD CC|| ??cpeZdZdZdZdZdZdZdZdZ dIdd d e d e d d fdZ d e fdZd e fdZded e fdZded e fdZd efdZed e fdZed e fdZedd d e fdZedd d eee e ffdZedd dee d fd e fdZede d d fdZ edd dee d fd eee d fed e fffdZ!edd dee d fd eee d fed e fffdZ"d e#fdZ$dJdZ% dKd ee&de fd!ee d fd dfd"Z' dKd#ee#de fd!ee d fd dfd$Z(edJd%Z)e)jTd ee&de fd dfd&Z)ed e#fd'ZejTd#ee#de fd dfd(ZdLd)Z+ dKd*ee#de fd!ee d fd dfd+Z,edLd,Z-e-jTd*ee#de fd dfd-Z-e-Z.d e fd.Z/ed e fd/Z0dMd0Z1 dKd1e2d2ee d fd3ee2d fd d4fd5Z3d6ed d4fd7Z4ed ee dfd e fd8Z5edd d e d d fd9Z6e dKd:e7e8dd d e d;e dZ9e dNd:e7e8dd d e ded:e7e8dd d e d e8fdGZ?d e fdHZ@y )OraSpecial case of a reference that is symbolic. This does not point to a specific commit, but to another :class:`~git.refs.head.Head`, which itself specifies a commit. A typical example for a symbolic reference is :class:`~git.refs.head.HEAD`. r!r"FTz refs/remotesr,r!rr" check_pathr#Nc ||_||_yNr1)selfr!r"r3s r-__init__zSymbolicReference.__init__Ls  r/c,t|jSr5strr"r6s r-__str__zSymbolicReference.__str__Ps499~r/cPd|jjd|jdS)Nz) __class____name__r"r;s r-__repr__zSymbolicReference.__repr__Ss"&.."9"9499EEr/othercnt|dr)tt|}|j|jk(Sy)Nr"F)hasattrrrr"r6rAs r-__eq__zSymbolicReference.__eq__Vs/ 5& !*E2E99 * *r/c||k( Sr5rDs r-__ne__zSymbolicReference.__ne__\sEM""r/c,t|jSr5)hashr"r;s r-__hash__zSymbolicReference.__hash___sDIIr/c,t|jS)z :return: In case of symbolic references, the shortest assumable name is the path itself. r9r;s r-r,zSymbolicReference.namebs499~r/cjtt|j|j|jSr5)rr.r!r"r;s r-abspathzSymbolicReference.abspathks"DII > JJr/cVtjj|jdS)N packed-refs)osr"joinr+)clsr!s r-_get_packed_refs_pathz'SymbolicReference._get_packed_refs_pathosww||DOO];;r/c #K t|j|dd5}|D]}|j}|s|jdr$|jdrd|vrt d|zK|dd k(rTt t ttft|jd d  d d d y #1swYy xYw#t$rYy wxYww) zReturn an iterator yielding pairs of sha1/path pairs (as strings) for the corresponding refs. :note: The packed refs file will be kept open as long as we iterate. rtUTF-8encoding#z# pack-refs with:peeledz-PackingType of packed-Refs not understood: %rr^ N) openrTstrip startswith TypeErrorrrr:tuplesplitOSError)rSr!fplines r-_iter_packed_refsz#SymbolicReference._iter_packed_refsss c//5tgN KRTKD::?HTXDX"+,[^b,b"cc Aw#~ uS#Xdjja6H0IJJ1K K K K6  sLCCBB<3C;C<CCCC CCCCref_pathc8 |j||\}}||S)a :return: hexsha stored in the reference at the given `ref_path`, recursively dereferencing all intermediate references as required :param repo: The repository containing the reference at `ref_path`. ) _get_ref_info)rSr!rihexshas r-dereference_recursivez'SymbolicReference.dereference_recursives."00x@ FH! r/cd}d}t|D]}|dvrtd|d|dk(r*||dk(rtd|d|dk(r}td|d|dk(r%|dk(rtd|d |Std|d |d k(r|d k(rtd|d t|dkst|dk(rtd|d|}|}|dk(rtd|d|dk(rtd|d|d k(r|td|dtdt|j dDrtd|dy)z|Check a ref name for validity. This is based on the rules described in :manpage:`git-check-ref-format(1)`. Nz ~^:?*[\zInvalid reference 'z': references cannot contain spaces, tildes (~), carets (^), colons (:), question marks (?), asterisks (*), open brackets ([) or backslashes (\)./z<': references cannot start with a period (.) or contain '/.'z!': references cannot contain '..'z!': references cannot contain '//'z3': references cannot start with forward slashes '/'{@z!': references cannot contain '@{' z5': references cannot contain ASCII control charactersz*': references cannot end with a period (.)z1': references cannot end with a forward slash (/)z': references cannot be '@'c3>K|]}|jdyw)z.lockN)endswith).0 components r- z:SymbolicReference._check_ref_name_valid..sW##G,WszJ': references cannot have slash-separated components that end with '.lock')r: ValueErrorordanyrd)ripreviousone_before_previouscs r-_check_ref_name_validz'SymbolicReference._check_ref_name_valids &*04X AK )(4lmc#x3$-hZ7st_$':8*De%fggcs?$':8*De%fgg%$-hZ7jkch#o #6xj@b!cddQ"A#  #6xj@u!vww"* H5 8 s?28*Q>QRU>VW W%hZ0 Xr/cb|r|j|d}t||} ttjj |t |dd5}|jj}dddj}t|dk7sJ |td|z|ddk(rd|dfS|jj|dr|ddfStd |z#1swY|xYw#t$r'|j|D]\}}||k7r ||f}nYwxYw) :return: *(str(sha), str(target_ref_path))*, where: * *sha* is of the file at rela_path points to if available, or ``None``. * *target_ref_path* is the reference we point to, or ``None``. NrVrWrXrzReference at %r does not existzref:r^z-Failed to parse reference information from %r)rr.r_rQr"rRr:readrstriprdlenrerhrzre_hexsha_onlymatch) rSr!ritokensrepodirrfvalueshar"s r-_get_ref_info_helperz&SymbolicReference._get_ref_info_helpersL   % %h /:>4* bggll7CM:D7S +WY ((* +[[]Fv;!# ## >=HI I !9 &)$ $    $ $VAY /1It$ $H8STT; + +  !2248  T8#d   s)5C>C27(C>2C;7C>>-D.-D.c&|j||S)r)r)rSr!ris r-rkzSymbolicReference._get_ref_info s''h77r/c tj|jt|j |j|j S)z :return: The object our ref currently refers to. Refs can be cached, they will always point to the actual object as it gets re-created on each query. )r new_from_shar!r rmr"r;s r- _get_objectzSymbolicReference._get_objects;""499j9S9STXT]T]_c_h_h9i.jkkr/c|j}|jdk(r |j}|jtjk7rt d|z|S)z :return: :class:`~git.objects.commit.Commit` object we point to. This works for detached and non-detached :class:`SymbolicReference` instances. The symbolic reference will be dereferenced recursively. tagz?QF Gs*6CC'C""C'rct|tr |j}d} |j}|r|j ||S|j j||S#t$rY?wxYw)axSet the object we point to, possibly dereference our symbolic reference first. If the reference does not exist, it will be created. :param object: A refspec, a :class:`SymbolicReference` or an :class:`~git.objects.base.Object` instance. * :class:`SymbolicReference` instances will be dereferenced beforehand to obtain the git object they point to. * :class:`~git.objects.base.Object` instances must represent git objects (:class:`~git.types.AnyGitObject`). :param logmsg: If not ``None``, the message will be used in the reflog entry to be written. Otherwise the reflog is not altered. :note: Plain :class:`SymbolicReference` instances may not actually point to objects by convention. :return: self T)rrr is_detachedrz set_reference_get_referencer)r6rrrs r-rzSymbolicReference.set_objectXsy8 f/ 0]]F  **K %%ff5 5""$//??   s A A,+A,c"|jS)zQuery or set commits directly)rr;s r-rzSymbolicReference.commit!!r/c$|j|Sr5)r)r6rs r-rzSymbolicReference.commitv&&r/c"|jS)z-Return the object our ref currently refers to)rr;s r-rzSymbolicReference.objectrr/c$|j|Sr5)r)r6rs r-rzSymbolicReference.objectrr/c|j|j|j\}}|t|d||j |j|S)z :return: :class:`~git.refs.reference.Reference` object we point to :raise TypeError: If this symbolic reference is detached, hence it doesn't point to a reference, but to a commit. z2 is a detached symbolic reference as it points to )rkr!r"rb from_path)r6rtarget_ref_paths r-rz SymbolicReference._get_referencesP $11$))TYYG_  "X\^abc c~~dii99r/refcd}d}t|trd|jz}nit|tr|}|j}nJt|t r, |j j|dz}|j}ntd|z|7|jr+|jtjk7rtd|zd}| |jj }|j$}t'|d t)|}|j+dd } | j-|j/d d z|j||j5|||S#ttf$r}td|z|d}~wwxYw#t$rtj"}YwxYw#t0$r|j3wxYw) aSet ourselves to the given `ref`. It will stay a symbol if the `ref` is a :class:`~git.refs.reference.Reference`. Otherwise a git object, specified as a :class:`~git.objects.base.Object` instance or refspec, is assumed. If it is valid, this reference will be set to it, which effectively detaches the reference if it was a purely symbolic one. :param ref: A :class:`SymbolicReference` instance, an :class:`~git.objects.base.Object` instance (specifically an :class:`~git.types.AnyGitObject`), or a refspec string. Only if the ref is a :class:`SymbolicReference` instance, we will point to it. Everything else is dereferenced to obtain the actual object. :param logmsg: If set to a string, the message will be used in the reflog. Otherwise, a reflog entry is not written for the changed reference. The previous commit of the entry will be the commit we point to now. See also: :meth:`log_append` :return: self :note: This symbolic reference will not be dereferenced. For that, see :meth:`set_object`. Nzref: %sz^{}z Could not extract object from %szUnrecognized Value: %rzRequire commit, got %rr/T)is_file)writestreamzutf-8 )rrr"rrlr:r!rrrrz_points_to_commits_onlyrrrbrbinsha NULL_BIN_SHArNr r r_rencode BaseExceptionrollback log_append) r6rr write_valuerr oldbinshafpathlfdfds r-rzSymbolicReference.set_referencesB  c, -#chh.K V $C**K S ! Rii))#+6!jj 5;< < ?t;;FKK@W4s:; ;   0 KK..  t4uo XXDX .  HH[''058 9 JJL   OOIv . Iw' R !Cc!IJPQQ R  0"//  0  LLN  s6*E# F 3F(#F2FF F%$F%(Gc"|jSr5)rr;s r- referencezSymbolicReference.references""$$r/c$|j|Sr5)r)r6rs r-rzSymbolicReference.references!!#&&r/cH |jy#ttf$rYywxYw)z :return: ``True`` if the reference is valid, hence it can be read and points to a valid object or reference. TF)rrerzr;s r-is_validzSymbolicReference.is_valids,   KK$  s !!c< |jy#t$rYywxYw)z :return: ``True`` if we are a detached reference, hence we point to a specific commit instead to another reference. FT)rrbr;s r-rzSymbolicReference.is_detacheds#  HH  s  cRtjtj|S)ad :return: :class:`~git.refs.log.RefLog` for this reference. Its last entry reflects the latest change applied to this reference. :note: As the log is parsed every time, its recommended to cache it for use instead of calling this method repeatedly. It should be considered read-only. )r from_filer"r;s r-logzSymbolicReference.logs D 122r/rmessage newbinsharc |jj}||jj }|d}t j|t j||||S#t$r|jj }YmwxYw)aAppend a logentry to the logfile of this ref. :param oldbinsha: Binary sha this ref used to point to. :param message: A message describing the change. :param newbinsha: The sha the ref points to now. If None, our current commit sha will be used. :return: The added :class:`~git.refs.log.RefLogEntry` instance. r2) r committerrzr! config_readerrr append_entryr")r6rrrcommitter_or_readers r-rzSymbolicReference.log_append(s. `. rp)rrr"_common_path_defaultr:ra)rSr" full_ref_paths r- to_full_pathzSymbolicReference.to_full_path[s_ d- .99D '' 4y##C$<$.s%Pddkk&&9%Ps!)rrQr"rRr+existsremoverTr_decoder partitionr`raappend writelinesrer isfile)rSr!r"rabs_pathpack_file_pathreader new_lines made_changedropped_last_line line_bytesrg_line_refr reflog_paths r-deletezSymbolicReference.deletels((. 77<<? 77>>( # IIh !66t>#3 !OOC0MX4M 15Ft_bOc%,,T205-$'+ ,0)%1 12nd3Qr %Pi%PPQkk#dM":; 77>>+ & IIk " 'I118QQ  sC F<B F$F<1F0 F<$F-)F<0F95F<< GGrSresolverforcecxt||}|j|}tjj ||} |} |r|j t |} |stjj| rt | } t| trt | j} |sd| z} t| d5} | jjtj} ddd | k7rtd|d| d| |||}|j!| ||S#1swY?xYw)a3Internal method used to create a new symbolic reference. If `resolve` is ``False``, the reference will be taken as is, creating a proper symbolic reference. Otherwise it will be resolved to the corresponding object and a detached symbolic reference will be created instead. zref: rNz Reference at z! does already exist, pointing to z, requested was )r.rrQr"rRrr:rrrr_rrrr`rer)rSr!r"rrrrr*r abs_ref_pathtarget target_datar existing_datars r-_createzSymbolicReference._creates 4&((. ww||G];  ^^C N3F 5f+K&"34!&++. % 3 lD) AR " 0 0 8 > > @  A +$m[B $ & &&)  A As 2D00D9kwargsc B|j|||j|||S)aFCreate a new symbolic reference: a reference pointing to another reference. :param repo: Repository to create the reference in. :param path: Full path at which the new symbolic reference is supposed to be created at, e.g. ``NEW_HEAD`` or ``symrefs/my_new_symref``. :param reference: The reference which the new symbolic reference should point to. If it is a commit-ish, the symbolic ref will be detached. :param force: If ``True``, force creation even if a symbolic reference with that name already exists. Raise :exc:`OSError` otherwise. :param logmsg: If not ``None``, the message to append to the reflog. If ``None``, no reflog entry is written. :return: Newly created symbolic reference :raise OSError: If a (Symbolic)Reference with the same name but different contents already exists. :note: This does not alter the current HEAD, index or working tree. )r_resolve_ref_on_create)rSr!r"rrrrs r-createzSymbolicReference.creates%R{{4s'A'A9eU[\\r/new_pathc|j|}|j|k(r|Stjjt |j ||}tjjt |j |j|j}tjj |r|syt|d5}|jj}dddt|d5}|jj}dddk7rtd|ztj|tjj|} tjj| stj| tj||||_|S#1swYxYw#1swYxYw)awRename self to a new path. :param new_path: Either a simple name or a full path, e.g. ``new_name`` or ``features/new_name``. The prefix ``refs/`` is implied for references and will be set as needed. In case this is a symbolic ref, there is no implied prefix. :param force: If ``True``, the rename will succeed even if a head with the target name already exists. It will be overwritten in that case. :return: self :raise OSError: If a file at path but with different contents already exists. rNzFile at path %r already exists)rr"rQrRr.r!rr_rr`rerdirnameisdirmakedirsrename) r6rr new_abs_path cur_abs_pathfd1f1fd2f2dnames r-rzSymbolicReference.renamesZ&$$X. 99 Kww||HTYY$A8L ww||HTYY $BDIIN 77>>, ',-,))+B,,-,))+B,8!"B\"QRR IIl # -ww}}U# KK  , -  ),,,,s G?G G  G common_pathc #K| |j}t}tjt |j |D]\}}}d|j tjvr|Dcgc] }|dk(s | }}|rdg|dd|D]T} | dk(r tt|| } |j| jt|j dzdV|j|D]1\} } | jt|s!|j| 3t|D]} |j!|| ycc}w#t"$rY+wxYww)NrefsrrPrpr2)rsetrQwalkrr+rdseprr addreplacerhrar:sortedrrz)rSr!r rela_pathsrootdirsfilesdrefs_idfr_sha rela_pathr"s r- _iter_itemszSymbolicReference._iter_items1si  22KU "$)9$//;)W!X b D$TZZ//&*:a6k1:: &xDH b %/ $0BCx//0DT__0UX[0[]_`a  b b #44T: *OD)##C $45y) *:& D mmD$// +;0  sCA.E#0 E;E?BE#!E#8E E# E E#E  E#argsc4d|j||DS)aFind all refs in the repository. :param repo: The :class:`~git.repo.base.Repo`. :param common_path: Optional keyword argument to the path which is to be shared by all returned Ref objects. Defaults to class specific portion if ``None``, ensuring that only refs suitable for the actual class are returned. :return: A list of :class:`SymbolicReference`, each guaranteed to be a symbolic ref which is not detached and pointing to a valid ref. The list is lexicographically sorted. The returned objects are instances of concrete subclasses, such as :class:`~git.refs.head.Head` or :class:`~git.refs.tag.TagReference`. c3^K|]%}|jtus |jr"|'ywr5)r>rr)rwrs r-ryz/SymbolicReference.iter_items..ts%waPaAaijivivws#--)r)rSr!rrrs r- iter_itemszSymbolicReference.iter_itemsYs6x3??4=wwr/c|std|zddlm}m}m}m}m}|||||tfD]8} |||} | jtur| jr td| cStd|z#t$rYTwxYw)aMake a symbolic reference from a path. :param path: Full ``.git``-directory-relative path name to the Reference to instantiate. :note: Use :meth:`to_full_path` if you only have a partial path of a known Reference type. :return: Instance of type :class:`~git.refs.reference.Reference`, :class:`~git.refs.head.Head`, or :class:`~git.refs.tag.Tag`, depending on the given path. zCannot create Reference from %rr^)r%HeadRemoteReference TagReference Referencez$SymbolicRef was detached, we drop itz8Could not find reference type suitable to handle path %r) rzr2r%rrr r!rr>r) rSr!r"r%rrr r!ref_typeinstances r-rzSymbolicReference.from_pathvs >EF F KJ         H #D$/%%)::x?S?S$%KLL#O (SVZZ[[   s3A44 B?Bcdt|jj|jdzS)zB:return: True if this symbolic reference points to a remote branchrp)r:r"ra_remote_common_path_defaultr;s r- is_remotezSymbolicReference.is_remotes&499~(()I)IC)OPPr/)F)r#rr5)r#r)r#r )r%NF)Ar? __module__ __qualname____doc__ __slots__rrrr%_id_attribute_rboolr7r:r<r@rrErHintrKpropertyr,rN classmethodrTrrrhrrm staticmethodrrrkrrrrrrrsetterrrrrrrrbytesrrrrrrrrrrrrrr&rGr/r-rr;s!I"""0NV8RVF#FFt #F#t##cKKK<%:-U uS$YtSy!11 2-U-U^88543H8USXY\^bYbScejkoqtkteuSuMv88l\l($($f1367$c4i $  $R$(+@l$7<=+@c4i +@  +@Z"" ]]'U6+>#CD'I\''" "" ]]'U<1Dc#IJ'Ob'' :"$(P *x x  x ,  xx8*\tL)*\*\x*\L*\*\XQ4Qr/)*__all__rQ gitdb.excrr git.compatrgit.objects.basergit.objects.commitr git.refs.logr git.utilr r r r rrtypingrrrrrrrrr git.typesrr git.configrrrgit.reporrr.rrGr/r-r>s   (#%   -*((~-@A 6x~!68j Qj Qr/