o
    ﯪgi                     @   s  U g d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ dd	lmZmZ erwdd
lmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ed Z(ej)G dd dej*Z+e+j,Z,ee+j, e-d< 	 e+j.Z.ee+j. e-d< 	 e/dZ0dede1fddZ2d'de1de3dee1 fddZ4G dd  d Z5ed!d"d#Z6G d$d% d%ee6 Z7G d&d" d"Z8dS )()DiffConstants	NULL_TREEINDEXDiffable	DiffIndexDiff    N)handle_process_output)defenc)Blob)mode_str_to_int)finalize_process
hex_to_bin)
AnyIteratorListMatchOptionalTupleTYPE_CHECKINGTypeVarUnioncast)LiteralPathLike)Popen)Git)IndexObject)Commit)Tree)Repo)ADCMRTUc                   @   s"   e Zd ZdZe Z	 e ZdS )r   ay  Special 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__enumautor   r    r-   r-   D/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/diff.pyr   0   s    r   r   r   s   \\([0-9]{3})matchobjreturnc                 C   s&   |  d}t|d}tt|f}|S )N      )groupintbytes	bytearray)r/   valuer-   r-   r.   _octal_replb   s   

r8   Tpathhas_ab_prefixc                 C   s   | dkrd S |  dr&| dr&| dd ddddd	dd
d} tt| } |r@|  ds:|  ds:J | dd  } | S )Ns	   /dev/null   "r1   s   \n   
s   \t   	s   \"s   \\   \s   a/s   b/   )
startswithendswithreplace_octal_byte_resubr8   )r9   r:   r-   r-   r.   decode_pathi   s   ,rF   c                   @   s   e Zd ZU dZdZded< 	 eZ	 eZ	 eZ	 de	e
ed f  de	e
ed f  fddZed	d
fde
edded	f de
ee	e eedf d	f dededdf
ddZd	S )r   aG  Common 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   repoargsr0   c                 C   s   |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-   )selfrH   r-   r-   r.   _process_diff_args   s   
zDiffable._process_diff_argsNFotherr   r   paths.create_patchkwargsDiffIndex[Diff]c           
         sj  g }| d | d t fdddD s| d |r)| d | d n
| d	 | d
 | d |durFt|ttfsF|g}| jjj}|tu rV|	dd n+|t
u rl|	dd |	dd | jjj}n|dur|	dd |	d| | jjj}|	d|  |r| d || d d< || |i  }|rtjntj}|| j|}	|  |	S )aC  Create 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-indexc                 3   s    | ]}| v V  qd S Nr-   ).0xrN   r-   r.   	<genexpr>   s    z Diffable.diff.<locals>.<genexpr>)find_renames
no_renamesr#   z-Mz-pz--no-ext-diffz--rawz-zz
--no-colorNr   z--cachedz-rz--rootz--T
as_process)appendany
isinstancetuplelistrG   gitdiffr   insertr   	diff_treeextendrJ   r   _index_from_patch_format_index_from_raw_formatwait)
rI   rK   rL   rM   rN   rH   diff_cmdprocdiff_methodindexr-   rS   r.   r^      sD   .










zDiffable.diff)r'   r(   r)   r*   	__slots____annotations__r   r   Indexr   r   r   rJ   r   strr   boolr   r^   r-   r-   r-   r.   r   y   s<   
 		

r   T_Diffr   )boundc                   @   s,   e Zd ZdZdZ	 dedee fddZdS )r   zAn 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_typer0   c                 c   s    || j vrtd| | D ]J}|j |kr|V  q|dkr$|jr$|V  q|dkr/|jr/|V  q|dkr:|jr:|V  q|dkrE|jrE|V  q|dkrX|jrX|jrX|j|jkrX|V  qdS )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
        zInvalid change type: %sr    r!   r"   r$   r#   N)rp   
ValueErrornew_filedeleted_filecopied_filerenamed_filea_blobb_blob)rI   rp   diffidxr-   r-   r.   iter_change_type.  s$   

 zDiffIndex.iter_change_typeN)	r'   r(   r)   r*   rp   Lit_change_typer   rn   ry   r-   r-   r-   r.   r     s
    	r   c                    @   s  e Zd ZdZedejejB ZdZ	dZ
dZdddee d	ee d
eeedf deeedf deeedf deeedf dedededee dee deeedf dee dee ddf ddZdedefddZdedefddZdefdd Zdefd!d"Zedee fd#d$Zedee fd%d&Zedee fd'd(Zedee fd)d*Zedefd+d,Zedefd-d.Ze d/ed0ed1edee fd2d3Z!e ddd4ed5 de"d  fd6d7Z#e$d8eddd9e"d  ddfd:d;Z%e d@d>d?Z&dS )Ar   a  A 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<a_path_fallback>"?[ab]/.+?"?)[ ](?P<b_path_fallback>"?[ab]/.+?"?)\n
                                (?:^old[ ]mode[ ](?P<old_mode>\d+)\n
                                   ^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
                                (?:^similarity[ ]index[ ]\d+%\n
                                   ^rename[ ]from[ ](?P<rename_from>.*)\n
                                   ^rename[ ]to[ ](?P<rename_to>.*)(?:\n|$))?
                                (?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
                                (?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
                                (?:^similarity[ ]index[ ]\d+%\n
                                   ^copy[ ]from[ ].*\n
                                   ^copy[ ]to[ ](?P<copied_file_name>.*)(?:\n|$))?
                                (?:^index[ ](?P<a_blob_id>[0-9A-Fa-f]+)
                                    \.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
                                (?:^---[ ](?P<a_path>[^\t\n\r\f\v]*)[\t\r\f\v]*(?:\n|$))?
                                (?:^\+\+\+[ ](?P<b_path>[^\t\n\r\f\v]*)[\t\r\f\v]*(?:\n|$))?
                            (0000000000000000000000000000000000000000s                       )rv   rw   a_modeb_mode	a_rawpath	b_rawpathrr   rs   rt   raw_rename_fromraw_rename_tor^   rp   scorerG   r   r~   r   	a_blob_idN	b_blob_idr|   r}   rr   rs   rt   r   r   r^   rp   r   r0   c                 C   sn  |d u st |tsJ |d u st |tsJ || _|| _|r"t|nd | _|r+t|nd | _|rK|rK|jD ]}|j|	t
dkrJ| rH| } nq5|  |d u sV|| jkrZd | _nt|t|| j| jd| _|  |d u sr|| jkrvd | _nt|t|| j| jd| _|| _|	| _|
| _|d u st |tsJ |d u st |tsJ |pd | _|pd | _|| _|| _|| _d S )NrC   )moder9   )rZ   r5   r~   r   r   r|   r}   
submodulesr9   decoder	   module_existsmoduleNULL_HEX_SHArv   r
   r   a_pathrw   b_pathrr   rs   rt   r   r   r^   rp   r   )rI   rG   r~   r   r   r   r|   r}   rr   rs   rt   r   r   r^   rp   r   	submoduler-   r-   r.   __init__  s>   



zDiff.__init__rK   c                 C   s*   | j D ]}t| |t||kr dS qdS )NFT)ri   getattr)rI   rK   namer-   r-   r.   __eq__  s
   
zDiff.__eq__c                 C   s
   | |k S rP   r-   )rI   rK   r-   r-   r.   __ne__  s   
zDiff.__ne__c                    s   t t fdd jD S )Nc                 3   s    | ]}t  |V  qd S rP   )r   )rQ   nrI   r-   r.   rT     s    z Diff.__hash__.<locals>.<genexpr>)hashr[   ri   r   r-   r   r.   __hash__  s   zDiff.__hash__c                 C   sV  d}| j r|| j j; }n	| jr|| jj; }d}d }d}t| j | jfdD ]\}}|r4d||j|jf }nd| }tt||}||7 }q$|dd|  7 }| jrS|d	7 }| j	rZ|d
7 }| j
rg|d| j| jf 7 }| jrq|d| j 7 }| jr{|d| j 7 }| jr|d7 }z|t| jtr| jtn| j7 }W n ty   |d7 }Y nw |d7 }|| S )Nz%s r   )lhsrhsz
%s: %o | %sz	
%s: None
=z
file deleted in rhsz
file added in rhsz
file %r copied from %rz
file renamed from %rz
file renamed to %rz
---zOMITTED BINARY DATA)rv   r9   rw   zipr   hexshamaxlenrs   rr   rt   r   r   rename_from	rename_tor^   rZ   r5   r   r	   UnicodeDecodeError)rI   hmsglineline_lengthbr   r-   r-   r.   __str__  sD   
&zDiff.__str__c                 C      | j r
| j tdS d S NrC   )r~   r   r	   r   r-   r-   r.   r        zDiff.a_pathc                 C   r   r   )r   r   r	   r   r-   r-   r.   r     r   zDiff.b_pathc                 C   r   r   )r   r   r	   r   r-   r-   r.   r     r   zDiff.rename_fromc                 C   r   r   )r   r   r	   r   r-   r-   r.   r     r   zDiff.rename_toc                 C   s   t jdtdd | jS )a  Deprecated, 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 insteadr@   )
stacklevel)warningswarnDeprecationWarningru   r   r-   r-   r.   renamed#  s   zDiff.renamedc                 C   s   | j | jkS )z::return: ``True`` if the blob of our diff has been renamed)r   r   r   r-   r-   r.   ru   5  s   zDiff.renamed_file
path_matchrename_matchpath_fallback_matchc                 C   s,   |rt |S |rt |ddS |rt |S d S )NF)r:   )rF   )clsr   r   r   r-   r-   r.   _pick_best_path:  s   zDiff._pick_best_pathrf   )r   zGit.AutoInterruptc                 C   sx  g }t ||jdtdd d|}t }d}d}d\}}	d\}
}| j|D ]}| \}}}}}}}}}}}}}}	t|t|t|}}}| 	|||}| 	|	||}	|durg||
 |  |d _|pr|pr|or|pr|pr|}
|p||p||p||	o||
}|t|||	|o|t|o|t|
o|
t|o|t|||||ddd |}|}q&|r|r||
 d |d _|S )a  Create 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 <git.cmd.Git.AutoInterrupt>` wrapper).

        :return:
            :class:`DiffIndex`
        NFdecode_streams    )NNr<   )r   rX   r   joinr   	re_headerfinditergroupsrm   r   endstartr^   r   r   r	   )r   rG   rf   	text_listtextrh   previous_headerheaderr   r   r|   r}   _headera_path_fallbackb_path_fallbackold_modenew_moder   r   new_file_modedeleted_file_modecopied_file_namer   r   rr   rs   rt   r-   r-   r.   rb   G  sv   

zDiff._index_from_patch_formatlines_bytesrh   c                 C   s  |  t}|d\}}}|dD ]}|sq|d\}}}|d}|d d\}}	}
}}tt|d }d|dd  }| rGt	|nd }|
d}|t}|t}d	}d	}d	}d }d }|d
krkd }d}nC|dkrtd }
d}n:|dkrd}|dd\}}|t}|t}n!|dkr|dd\}}|t}|t}||}}n|dkr	 t||||
|||	|||||d||}|| qd S )N:z :    r   r   r1   r   Fr!   Tr    r"   r$   r%   )r   r	   	partitionsplitrstripr   rz   r   isdigitr4   stripencoder   rX   )r   rG   rh   lines_r   metar9   r   r   r   r   _change_typerp   	score_strr   r   r   rs   rr   rt   r   r   
a_path_str
b_path_strr^   r-   r-   r.   _handle_diff_line  sp   







zDiff._handle_diff_liner   rO   c                    s(   t  t| fdddtdd S )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                    s     | S rP   )r   )bytr   rh   rG   r-   r.   <lambda>  s    z-Diff._index_from_raw_format.<locals>.<lambda>NFr   )r   r   r   )r   rG   rf   r-   r   r.   rc     s   zDiff._index_from_raw_format)rG   r   rf   r   r0   rO   )'r'   r(   r)   r*   recompileVERBOSE	MULTILINEr   r   NULL_BIN_SHAri   r   r5   r   rl   rm   rz   r4   r   objectr   r   r   r   propertyr   r   r   r   r   ru   classmethodr   r   rb   staticmethodr   rc   r-   r-   r-   r.   r   O  s    !
	

=-  \ H)T)9__all__r+   r   r   git.cmdr   
git.compatr	   git.objects.blobr
   git.objects.utilr   git.utilr   r   typingr   r   r   r   r   r   r   r   r   r   	git.typesr   r   
subprocessr   r   git.objects.baser   git.objects.commitr   git.objects.treer   git.repo.baser   rz   uniqueEnumr   r   rj   r   r   rD   r5   r8   rm   rF   r   rn   r   r   r-   r-   r-   r.   <module>   sB   
0
 "2