yL iihUgdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZmZmZmZmZmZmZmZmZmZdd lmZmZer$dd lmZdd lmZdd l m!Z!dd l"m#Z#ddl$m%Z%ddl&m'Z'edZ(ejRGddejTZ+e+jXZ,ee+jXe-d< e+j\Z.ee+j\e-d< ej^dZ0dede1fdZ2d$de1de3dee1fdZ4GddZ5edd Z6Gd!d"ee6Z7Gd#dZ8y)%) DiffConstants NULL_TREEINDEXDiffable DiffIndexDiffN)handle_process_output)defenc)Blob)mode_str_to_int)finalize_process hex_to_bin) AnyIteratorListMatchOptionalTuple TYPE_CHECKINGTypeVarUnioncast)LiteralPathLike)Popen)Git) IndexObject)Commit)Tree)Repo)ADCMRTUcVeZdZdZej Z ej Zy)raySpecial objects for :meth:`Diffable.diff`. See the :meth:`Diffable.diff` method's ``other`` parameter, which accepts various values including these. :note: These constants are also available as attributes of the :mod:`git.diff` module, the :class:`Diffable` class and its subclasses and instances, and the top-level :mod:`git` module. N)__name__ __module__ __qualname____doc__enumautorrN/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/git/diff.pyrr0s/  I DIIKEr0rrrs \\([0-9]{3})matchobjreturncj|jd}t|d}tt|f}|S)N)groupintbytes bytearray)r2values r1 _octal_replr<bs1 NN1 E qME )UH% &E Lr0path has_ab_prefixcj|dk(ry|jdrV|jdrE|ddjddjddjd djd d }tj t |}|r)|jd s|jd sJ|dd}|S)Ns /dev/null"r5s\n s\t s\"s\\\sa/sb/) startswithendswithreplace_octal_byte_resubr<)r=r>s r1 decode_pathrKis | tt!4Abz!!&%088GOOPVX\]eefmotu   k4 0Du%)???ABx Kr0c eZdZUdZdZded< eZ eZ eZ de e e dfde e e dffdZ edd fd e e d d edfd e e e e ee dfdfdededdf dZy)raGCommon interface for all objects that can be diffed against another object of compatible type. :note: Subclasses require a :attr:`repo` member, as it is the case for :class:`~git.objects.base.Object` instances. For practical reasons we do not derive from :class:`~git.objects.base.Object`. r/r repoargsr3c|S)z :return: Possibly altered version of the given args list. This method is called right before git command execution. Subclasses can use it to alter the behaviour of the superclass. r/)selfrNs r1_process_diff_argszDiffable._process_diff_argss  r0NFotherrrpaths. create_patchkwargsDiffIndex[Diff]c Jg}|jd|jdtfddDs|jd|r#|jd|jdn"|jd|jd |jd |t|ttfs|g}|j j j}|tur|jd d n|turE|jd d |jd d|j j j}nF|D|jd d |jd ||j j j}|jd ||r"|jd|j|dd<||j|i}|rtjntj }||j |} |j#| S)aCCreate diffs between two items being trees, trees and index or an index and the working tree. Detects renames automatically. :param other: This the item to compare us with. * If ``None``, we will be compared to the working tree. * If a :class:`~git.types.Tree_ish` or string, it will be compared against the respective tree. * If :const:`INDEX`, it will be compared against the index. * If :const:`NULL_TREE`, it will compare against the empty tree. This parameter defaults to :const:`INDEX` (rather than ``None``) so that the method will not by default fail on bare repositories. :param paths: This a list of paths or a single path to limit the diff to. It will only include at least one of the given path or paths. :param create_patch: If ``True``, the returned :class:`Diff` contains a detailed patch that if applied makes the self to other. Patches are somewhat costly as blobs have to be read and diffed. :param kwargs: Additional arguments passed to :manpage:`git-diff(1)`, such as ``R=True`` to swap both sides of the diff. :return: A :class:`DiffIndex` representing the computed diff. :note: On a bare repository, `other` needs to be provided as :const:`INDEX`, or as an instance of :class:`~git.objects.tree.Tree` or :class:`~git.objects.commit.Commit`, or a git command error will occur. z --abbrev=40z --full-indexc3&K|]}|v ywNr/).0xrUs r1 z Diffable.diff..sL11;Ls) find_renames no_renamesr$z-Mz-pz --no-ext-diffz--rawz-zz --no-colorrz--cachedz-rz--rootz--T as_process)appendany isinstancetuplelistrMgitdiffrinsertr diff_treeextendrQr_index_from_patch_format_index_from_raw_formatwait) rPrRrSrTrUrNdiff_cmdproc diff_methodindexs ` r1rfz Diffable.diffs\13 M" N#L(KLL KK   KK  KK ( KK KK  L!  Zt}%EGE99==%% E> KK: & i  KK4 KK8 $yy}}..H   KK4 KK5 !yy}}..H At  KK  KK  $|006A&A7Cd33IdId DIIt,  r0)r)r*r+r, __slots____annotations__rrIndexrrrrQrstrrboolrrfr/r0r1rrysI LRI E E  5:-./  eHj() * DIMQ" _]FHc4?@_XtH~uXs]/CTIJ_ _  _  _r0rT_Diffr)boundc,eZdZdZdZ dedeefdZy)rzAn index for diffs, allowing a list of :class:`Diff`\s to be queried by the diff properties. The class improves the diff handling convenience. )r!r#r"r%r$r& change_typer3c#K||jvrtd|z|D]}|j|k(r||dk(r|jr|-|dk(r|jr|C|dk(r|jr|Y|dk(r|j r|o|dk(su|j s|js|j |jk7s|yw)a :return: Iterator yielding :class:`Diff` instances that match the given `change_type` :param change_type: Member of :attr:`DiffIndex.change_type`, namely: * 'A' for added paths * 'D' for deleted paths * 'R' for renamed paths * 'M' for paths with modified data * 'T' for changed in the type paths zInvalid change type: %sr!r"r#r%r$N)ry ValueErrornew_file deleted_file copied_file renamed_filea_blobb_blob)rPrydiffidxs r1iter_change_typezDiffIndex.iter_change_type.s d.. .6DE E G""k1 #(8(8 #(<(< #(;(; #(<(< #7>>gnn`g`n`nNn  sBC C# C0C CN) r)r*r+r,ryLit_change_typerrvrr/r0r1rrs+ 1KO@Pr0rc xeZdZdZej dej ejzZdZ dZ dZ ddde e d e e d eee d fd eee d fd ee ed fdee ed fdededede e de e deee d fde ede edd f dZdedefdZdedefdZdefdZdefdZede efdZede efdZede efd Zede efd!Zedefd"Zedefd#Ze d$e d%e d&e de e fd'Z!e ddd(ed)de"dfd*Z#e$d+e ddd,e"ddd fd-Z%e d/d.Z&y )0raA Diff contains diff information between two Trees. It contains two sides a and b of the diff. Members are prefixed with "a" and "b" respectively to indicate that. Diffs keep information about the changed blob objects, the file mode, renames, deletions and new files. There are a few cases where ``None`` has to be expected as member variable value: New File:: a_mode is None a_blob is None a_path is None Deleted File:: b_mode is None b_blob is None b_path is None Working Tree Blobs: When comparing to working trees, the working tree blob will have a null hexsha as a corresponding object does not yet exist. The mode will be null as well. The path will be available, though. If it is listed in a diff, the working tree version of the file must differ from the version in the index or tree, and hence has been modified. s ^diff[ ]--git [ ](?P"?[ab]/.+?"?)[ ](?P"?[ab]/.+?"?)\n (?:^old[ ]mode[ ](?P\d+)\n ^new[ ]mode[ ](?P\d+)(?:\n|$))? (?:^similarity[ ]index[ ]\d+%\n ^rename[ ]from[ ](?P.*)\n ^rename[ ]to[ ](?P.*)(?:\n|$))? (?:^new[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^deleted[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^similarity[ ]index[ ]\d+%\n ^copy[ ]from[ ].*\n ^copy[ ]to[ ](?P.*)(?:\n|$))? (?:^index[ ](?P[0-9A-Fa-f]+) \.\.(?P[0-9A-Fa-f]+)[ ]?(?P.+)?(?:\n|$))? (?:^---[ ](?P[^\t\n\r\f\v]*)[\t\r\f\v]*(?:\n|$))? (?:^\+\+\+[ ](?P[^\t\n\r\f\v]*)[\t\r\f\v]*(?:\n|$))? (0000000000000000000000000000000000000000s)rra_modeb_mode a_rawpath b_rawpathr|r}r~raw_rename_from raw_rename_torfryscorerMr rr a_blob_idN b_blob_idrrr|r}r~rrrfryrr3ct|t|tsJ|t|tsJ||_||_|r t |nd|_|r t |nd|_|rX|rV|jD]G}|j|jtdk(s'|jr|j}n||||jk(rd|_n1t|t!||j |j"|_||||jk(rd|_n1t|t!||j |j&|_||_| |_| |_| t| tsJ| t| tsJ| xsd|_| xsd|_| |_||_||_y)NrH)moder=)rbr9rrr rr submodulesr=decoder module_existsmodule NULL_HEX_SHArr ra_pathrb_pathr|r}r~rrrfryr)rPrMrrrrrrr|r}r~rrrfryr submodules r1__init__z Diff.__init__s$ Jy%$@@@ Jy%$@@@""17of-T 17of-T  I!__  >>Y%5%5fi%HH ..0(//1     T->-> >DKtZ %:SWS^S^_DK   T->-> >DKtZ %:SWS^S^_DK& ".!,&*_e*LLL$ =%(HHH.6$*2d 9D r0rRc\|jD]}t||t||k7syy)NFT)rqgetattr)rPrRnames r1__eq__z Diff.__eq__s3NN DtT"geT&:: r0c||k( SrYr/)rPrRs r1__ne__z Diff.__ne__sEM""r0cRttfdjDS)Nc36K|]}t|ywrY)r)rZnrPs r1r\z Diff.__hash__..sCq'$*Cs)hashrcrqrPs`r1__hash__z Diff.__hash__sECDNNCCDDr0cd}|jr||jjz}n%|jr||jjz}d}d}d}t|j|jfdD]C\}}|rd||j|j fz}nd|z}t t||}||z }E|dd|zzz }|jr|d z }|jr|d z }|jr|d |jd |jz }|jr|d |jzz }|jr|d|jzz }|jrS|dz } |t!|jt"r|jj%t&n |jz }|dz }||zS#t($r|dz }YwxYw)Nz%sr)lhsrhsz %s: %o | %sz %s: None =z file deleted in rhsz file added in rhsz file z copied from z file renamed from %rz file renamed to %rz ---zOMITTED BINARY DATA)rr=rziprhexshamaxlenr}r|r~rr rename_from rename_torfrbr9rr UnicodeDecodeError)rPhmsgline line_lengthbrs r1__str__z Diff.__str__s  ;; !! !A [[ !! !A dkk2NC DAq&!QVVQXX)>>#a'c$i5K 4KC  TC+% %%    * *C == ( (C    dkkJ JC    +d.>.>> >C >> )DNN: :C 99 7NC -:dii3Otyy''/UYU^U^^ 7NC3w & -,, -s"AF44GGc^|jr |jjtdSdSNrH)rrr rs r1rz Diff.a_path$;?>>t~~$$VY7StSr0c^|jr |jjtdSdSr)rrr rs r1rz Diff.b_pathrr0c^|jr |jjtdSdSr)rrr rs r1rzDiff.rename_froms)AEAUAUt##**69=_[__r0c^|jr |jjtdSdSr)rrr rs r1rzDiff.rename_tos)?C?Q?Qt!!((;[W[[r0cRtjdtd|jS)aDeprecated, use :attr:`renamed_file` instead. :return: ``True`` if the blob of our diff has been renamed :note: This property is deprecated. Please use the :attr:`renamed_file` property instead. z9Diff.renamed is deprecated, use Diff.renamed_file insteadrE) stacklevel)warningswarnDeprecationWarningrrs r1renamedz Diff.renamed#s'  G     r0c4|j|jk7S)z::return: ``True`` if the blob of our diff has been renamed)rrrs r1rzDiff.renamed_file5s4>>11r0 path_match rename_matchpath_fallback_matchcV|r t|S|r t|dS|r t|Sy)NF)r>)rK)clsrrrs r1_pick_best_pathzDiff._pick_best_path:s2 z* * |5A A 23 3r0rn)rzGit.AutoInterruptcg}t||jdtddj|}t }d}d}d\}} d\} } |j j |D]D} | j\} }}}}}}}}}}} }} t|t|t|}}}|j||| }|j| ||} |)||j| j|d_ |xs|xs|xr | xs|xs|} | xs|xs |xs| xr| } |jt||| |xr|jt|xr|jt| xr| jt| xr| jt|||||ddd| }| }G|r|r||jd|d_ |S)aCreate a new :class:`DiffIndex` from the given process output which must be in patch format. :param repo: The repository we are operating on. :param proc: :manpage:`git-diff(1)` process to read from (supports :class:`Git.AutoInterrupt ` wrapper). :return: :class:`DiffIndex` NFdecode_streamsr0)NNrA)r r`r joinr re_headerfinditergroupsrurendstartrfrrr )rrMrn text_listtextrpprevious_headerheaderrrrr_headera_path_fallbackb_path_fallbackold_modenew_moderr new_file_modedeleted_file_modecopied_file_namerrr|r}r~s r1rjzDiff._index_from_patch_formatGs""$ dI$4$4d& J#**62#**62#)-FA)>& J#**62#**62)/Y #D" LL A@ r0cRtt|fddtdS)a!Create a new :class:`DiffIndex` from the given process output which must be in raw format. :param repo: The repository we are operating on. :param proc: Process to read output from. :return: :class:`DiffIndex` c*j|SrY)r)bytrrprMs r1z-Diff._index_from_raw_format..s--c4?r0NFr)rr r )rrMrnrps`` @r1rkzDiff._index_from_raw_formats*"'[  ?     r0)rMr rnrr3rV)'r)r*r+r,recompileVERBOSE MULTILINErr NULL_BIN_SHArqrr9rrtrurr8robjectrrrrpropertyrrrrrr classmethodrrrj staticmethodrrkr/r0r1rrOsB  $ R\\!'I.LLI";;E?;E? ; eT)* ; eT)* ;eS$&';eS$&';;;;"%; ;C$%;o.; }!;" #;zFt#F#t#E#E++ZT TTT TT`Xc]``\8C=\\!!!"2d22  e Z_ dlmrds  ZFZ%@\:]ZbklrbsZZxFuFFF9VCTFY]FFPr0)T)9__all__r-rrgit.cmdr git.compatr git.objects.blobr git.objects.utilr git.utilr rtypingrrrrrrrrrr git.typesrr subprocessrrgit.objects.basergit.objects.commitrgit.objects.treer git.repo.baser runiqueEnumrrrrrrrIr9r<rurKrrvrrr/r0r1rs? S R )!,1   ( ,)%";< DII 8/<.E.E 7=** +E'4&9&9w}""#9,-%E e D HUO  ^^B  (.V .dxxr0