a
    `Df v                     @   s  d gZ ddlmZ ddlZddlmZ ddlZddlZddlZddl	m
Z
mZ ddlZddlmZmZmZmZm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mZmZmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ej4dkr8ddl)m5Z5 nddl6m5Z5 ddl7m8Z8 e1rnddl9m:Z: ddl;m<Z< e=e>Z?G dd  d ej@e$ee#ZAdS )Commit    )defaultdictN)BytesIO)PopenPIPE)altzonedaylight	localtimetimetimezone)IStream)Git)Diffable)ActorStatsfinalize_process
hex_to_bin   )base)Tree)SerializableTraversableIterableObjaltz_to_utctz_strfrom_timestampparse_actor_and_date
parse_date)
AnyDictIOIteratorListSequenceTupleTYPE_CHECKINGUnioncast)      )Literal)PathLike)SymbolicReference)Repoc                       s  e Zd ZU dZdZdZdZdZdZe	d e
d< dZd	Zed  e
d
< dFdeeedf eedf eedf edef eedf eedf edef eeedf eed  df eedf eedf dd fddZed ed dddZedd edddZed dddZedd fddZeejdddZeejdd d!Z eeeef dd"d#Z!dGee"ee" f eed%d&d'Z#eedd(d)Z$edHdeed d*f ee"ee" f ee%d  d+d,d-Z&dIee"ee" f ee%d  d%d.d/Z'ee(dd0d1Z)ee*eef dd2d3Z+ee,eeef  dd4d5Z-ee*ee,e f dd6d7Z.edee/e0f e%d  d8d9d:Z1edJdeeef eede,d  f e2edef edef edeejf edeejf d d<
d=d>Z3e4d d?d@dAZ5e4d d?dBdCZ6ee,e ddDdEZ7  Z8S )Kr   a1  Wraps a git commit object.

    See :manpage:`gitglossary(7)` on "commit object":
    https://git-scm.com/docs/gitglossary#def_commit_object

    :note:
        This class will act lazily on some of its attributes and will query the value on
        demand only if it involves calling the git binary.
    ZGIT_AUTHOR_DATEZGIT_COMMITTER_DATEzi18n.commitencodingzUTF-8committype)treeauthorauthored_dateauthor_tz_offset	committercommitted_datecommitter_tz_offsetmessageparentsencodinggpgsighexshar6   Nr+   )repobinshar.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   returnc                    s   t  || || _|dur6t|ts6J dt| |durD|| _|durR|| _|dur`|| _|durn|| _	|dur||| _
|dur|| _|	dur|	| _|
dur|
| _|dur|| _|dur|| _|dur|| _dS )a  Instantiate a new :class:`Commit`. All keyword arguments taking ``None`` as
        default will be implicitly set on first query.

        :param binsha:
            20 byte sha1.

        :param tree:
            A :class:`~git.objects.tree.Tree` object.

        :param author:
            The author :class:`~git.util.Actor` object.

        :param authored_date: int_seconds_since_epoch
            The authored DateTime - use :func:`time.gmtime` to convert it into a
            different format.

        :param author_tz_offset: int_seconds_west_of_utc
            The timezone that the `authored_date` is in.

        :param committer:
            The committer string, as an :class:`~git.util.Actor` object.

        :param committed_date: int_seconds_since_epoch
            The committed DateTime - use :func:`time.gmtime` to convert it into a
            different format.

        :param committer_tz_offset: int_seconds_west_of_utc
            The timezone that the `committed_date` is in.

        :param message: string
            The commit message.

        :param encoding: string
            Encoding of the message, defaults to UTF-8.

        :param parents:
            List or tuple of :class:`Commit` objects which are our parent(s) in the
            commit dependency graph.

        :return:
            :class:`Commit`

        :note:
            Timezone information is in the same format and in the same sign as what
            :func:`time.altzone` returns. The sign is inverted compared to git's UTC
            timezone.
        Nz(Tree needs to be a Tree instance, was %s)super__init__r;   
isinstancer   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   )selfr:   r;   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   	__class__ _/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/git/objects/commit.pyr>   m   s4    ?zCommit.__init__)r   .)r,   r<   c                 C   s
   t |jS N)tupler6   )clsr,   rC   rC   rD   _get_intermediate_items   s    zCommit._get_intermediate_items)r:   r,   r<   c                 C   s>   t  }|| | }|d |jt| j||}|jS )zCalculate the sha of a commit.

        :param repo:
            :class:`~git.repo.base.Repo` object the commit should be part of.

        :param commit:
            :class:`Commit` object for which to generate the sha.
        r   )	r   
_serializetellseekodbstorer   r-   r;   )rG   r:   r,   streamZ	streamlenistreamrC   rC   rD   _calculate_sha_   s    

zCommit._calculate_sha_)kwargsr<   c                    sf    fdd j D }|D ]}| j vrtdq||  j j jfi |}  j||_|S )zCreate new commit object from an existing commit object.

        Any values provided as keyword arguments will replace the corresponding
        attribute in the new object.
        c                    s   i | ]}|t  |qS rC   )getattr).0kr@   rC   rD   
<dictcomp>       z"Commit.replace.<locals>.<dictcomp>zinvalid attribute name)	__slots__
ValueErrorupdaterB   r:   NULL_BIN_SHArP   r;   )r@   rQ   attrsattrname
new_commitrC   rU   rD   replace   s    


zCommit.replace)attrr<   c                    sH   |t jv r8| jj| j\}}| _}| t|	  nt
 | d S rE   )r   rX   r:   rL   rN   r;   size_deserializer   readr=   _set_cache_)r@   r`   Z_binshaZ	_typenamerN   rA   rC   rD   rd      s    
zCommit._set_cache_)r<   c                 C   s   t | j| jS rE   )r   r0   r1   rU   rC   rC   rD   authored_datetime   s    zCommit.authored_datetimec                 C   s   t | j| jS rE   )r   r3   r4   rU   rC   rC   rD   committed_datetime   s    zCommit.committed_datetimec                 C   s4   t | jtr| jddd S | jddd S dS )z):return: First line of the commit message
r   r      
N)r?   r5   strsplitrU   rC   rC   rD   summary  s    zCommit.summary )pathsrQ   r<   c                 K   sH   |r(t | jjj| jd|fi | S t | jjj| jfi | S )a  Count the number of commits reachable from this commit.

        :param paths:
            An optional path or a list of paths restricting the return value to commits
            actually containing the paths.

        :param kwargs:
            Additional options to be passed to :manpage:`git-rev-list(1)`. They must not
            alter the output style of the command, or parsing will yield incorrect
            results.

        :return:
            An int defining the number of reachable commits
        --)lenr:   gitrev_listr9   
splitlines)r@   rm   rQ   rC   rC   rD   count
  s    $zCommit.countc                 C   s   | j j| S )z
        :return:
            String describing the commits hex sha based on the closest
            `~git.refs.reference.Reference`.

        :note:
            Mostly useful for UI purposes.
        )r:   rp   name_revrU   rC   rC   rD   rt     s    
zCommit.name_revr*   )r:   revrm   rQ   r<   c                 K   sj   d|v rt ddg}|rDt|ttjfr2|f}nt|}|| |jj||fddi|}| 	||S )a  Find all commits matching the given criteria.

        :param repo:
            The :class:`~git.repo.base.Repo`.

        :param rev:
            Revision specifier. See :manpage:`git-rev-parse(1)` for viable options.

        :param paths:
            An optional path or list of paths. If set only :class:`Commit`\s that
            include the path or paths will be considered.

        :param kwargs:
            Optional keyword arguments to :manpage:`git-rev-list(1)` where:

            * ``max_count`` is the maximum number of commits to fetch.
            * ``skip`` is the number of commits to skip.
            * ``since`` selects all commits since some date, e.g. ``"1970-01-01"``.

        :return:
            Iterator yielding :class:`Commit` items.
        prettyz<--pretty cannot be used as parsing expects single sha's onlyrn   
as_processT)
rY   r?   ri   osr)   rF   extendrp   rq   _iter_from_process_or_stream)rG   r:   ru   rm   rQ   Z	args_listZ	paths_tupprocrC   rC   rD   
iter_items+  s    
zCommit.iter_itemsc                 K   s8   | dd}|dkrd}||d< | j| j| |fi |S )a  Iterate _all_ parents of this commit.

        :param paths:
            Optional path or list of paths limiting the :class:`Commit`\s to those that
            contain at least one of the paths.

        :param kwargs:
            All arguments allowed by :manpage:`git-rev-list(1)`.

        :return:
            Iterator yielding :class:`Commit` objects which are parents of ``self``
        skipr   r   )getr|   r:   )r@   rm   rQ   r}   rC   rC   rD   iter_parents_  s
    zCommit.iter_parentsc                 C   s   | j sb| jjj| jddddd}d}| dd D ]&}|d\}}}|d|||f 7 }q4|}n"| jjj| j d	 j| jdddd
}t	| j|S )zCreate a git stat from changes between this commit and its first parent
        or from all changes done if this is the very first commit.

        :return:
            :class:`Stats`
        rn   T)numstat
no_renamesrootrl   r   N	z	%s	%s	%s
r   )r   r   )
r6   r:   rp   Z	diff_treer9   rr   rj   diffr   Z_list_from_string)r@   textZtext2lineZ
insertionsZ	deletionsfilenamerC   rC   rD   statst  s    "zCommit.statsc                 C   s$   t jdtdd dd | j D S )al  Deprecated. Get the trailers of the message as a dictionary.

        :note:
            This property is deprecated, please use either :attr:`trailers_list` or
            :attr:`trailers_dict`.

        :return:
            Dictionary containing whitespace stripped trailer information.
            Only contains the latest instance of each trailer key.
        zWCommit.trailers is deprecated, use Commit.trailers_list or Commit.trailers_dict instead   )
stacklevelc                 S   s   i | ]\}}||d  qS )r   rC   )rS   rT   vrC   rC   rD   rV     rW   z#Commit.trailers.<locals>.<dictcomp>)warningswarnDeprecationWarningtrailers_dictitemsrU   rC   rC   rD   trailers  s    zCommit.trailersc                 C   s   g d}| j jj|dtd}|t| j d d}|	 }|sJg S g }|
dD ]*}|
dd\}}||	 |	 f qX|S )	a  Get the trailers of the message as a list.

        Git messages can contain trailer information that are similar to :rfc:`822`
        e-mail headers. See :manpage:`git-interpret-trailers(1)`.

        This function calls ``git interpret-trailers --parse`` onto the message to
        extract the trailer information, returns the raw trailer data as a list.

        Valid message with trailer::

            Subject line

            some body information

            another information

            key1: value1.1
            key1: value1.2
            key2 :    value 2 with inner spaces

        Returned list will look like this::

            [
                ("key1", "value1.1"),
                ("key1", "value1.2"),
                ("key2", "value 2 with inner spaces"),
            ]

        :return:
            List containing key-value tuples of whitespace stripped trailer information.
        )rp   zinterpret-trailersz--parseT)rw   rO   r   utf8rg   :r   )r:   rp   executer   communicateri   r5   encodedecodestriprj   append)r@   cmdr{   trailerZtrailer_listtkeyvalrC   rC   rD   trailers_list  s    !zCommit.trailers_listc                 C   s.   t t}| jD ]\}}|| | qt|S )a  Get the trailers of the message as a dictionary.

        Git messages can contain trailer information that are similar to :rfc:`822`
        e-mail headers. See :manpage:`git-interpret-trailers(1)`.

        This function calls ``git interpret-trailers --parse`` onto the message to
        extract the trailer information. The key value pairs are stripped of leading and
        trailing whitespaces before they get saved into a dictionary.

        Valid message with trailer::

            Subject line

            some body information

            another information

            key1: value1.1
            key1: value1.2
            key2 :    value 2 with inner spaces

        Returned dictionary will look like this::

            {
                "key1": ["value1.1", "value1.2"],
                "key2": ["value 2 with inner spaces"],
            }


        :return:
            Dictionary containing whitespace stripped trailer information, mapping
            trailer keys to a list of their corresponding values.
        )r   listr   r   dict)r@   dr   r   rC   rC   rD   r     s    #zCommit.trailers_dict)r:   proc_or_streamr<   c                 c   s   t |dr&tt|}|jdur>|j}nt |dr>tt|}|}|j}| }|sPq| }t|dkrt|dd\}}t|dksJ d| | |t	|V  qDt |drtt|}t
| dS )a  Parse out commit information into a list of :class:`Commit` objects.

        We expect one line per commit, and parse the actual commit information directly
        from our lighting fast object database.

        :param proc:
            :manpage:`git-rev-list(1)` process instance - one sha per line.

        :return:
            Iterator supplying :class:`Commit` objects
        waitNreadline(   r   zInvalid line: %s)hasattrr%   r   stdoutr   r   r   ro   rj   r   r   )rG   r:   r   rN   r   r   r9   _rC   rC   rD   rz     s&    






z#Commit._iter_from_process_or_streamF)
r:   r.   r5   parent_commitsheadr/   r2   author_datecommit_dater<   c
                 C   s
  |du r0z|j jg}W qX ty,   g }Y qX0 n(|D ]"}
t|
| s4td|
d|  q4| }tj}|prt|}|pt	|}t
t }tot jdk}|rtnt}|| jd}|rt|\}}n|rt|\}}n
|| }}|| jd}|	rt|	\}}n|rt|\}}n
|| }}| jd\}}|||| j}t|tsXtdt|trn||}| || j||||||||||}| |||_|rddl}z|j j ||d W nF ty   |j!j"j#||j j$|d	| d}|j j%|d
| d Y n0 |S )a  Commit the given tree, creating a :class:`Commit` object.

        :param repo:
            :class:`~git.repo.base.Repo` object the commit should be part of.

        :param tree:
            :class:`~git.objects.tree.Tree` object or hex or bin sha.
            The tree of the new commit.

        :param message:
            Commit message. It may be an empty string if no message is provided. It will
            be converted to a string, in any case.

        :param parent_commits:
            Optional :class:`Commit` objects to use as parents for the new commit. If
            empty list, the commit will have no parents at all and become a root commit.
            If ``None``, the current head commit will be the parent of the new commit
            object.

        :param head:
            If ``True``, the HEAD will be advanced to the new commit automatically.
            Otherwise the HEAD will remain pointing on the previous commit. This could
            lead to undesired results when diffing files.

        :param author:
            The name of the author, optional.
            If unset, the repository configuration is used to obtain this value.

        :param committer:
            The name of the committer, optional.
            If unset, the repository configuration is used to obtain this value.

        :param author_date:
            The timestamp for the author field.

        :param commit_date:
            The timestamp for the committer field.

        :return:
            :class:`Commit` object representing the new commit.

        :note:
            Additional information about the committer and author are taken from the
            environment or from the git configuration. See :manpage:`git-commit-tree(1)`
            for more information.
        NzParent commit 'z' must be of type r   rl   .z)conf_encoding could not be coerced to str)Zlogmsgzcommit (initial): %szcommit: Switching to %s)&r   r,   rY   r?   Zconfig_readerrx   environr   r2   r/   intr
   r   r	   tm_isdstr   r   r~   env_author_dater   env_committer_dateconf_encodingrj   	get_valuedefault_encodingri   	TypeErrorr.   r[   rP   r;   git.refsZ
set_commitrefsZHeadcreaterefZset_reference)rG   r:   r.   r5   r   r   r/   r2   r   r   pZcrenvZ	unix_timeZis_dstoffsetZauthor_date_strZauthor_timeZauthor_offsetZcommitter_date_strZcommitter_timeZcommitter_offsetZenc_sectionZ
enc_optionr   r^   rp   ZmasterrC   rC   rD   create_from_tree'  sz    ;





zCommit.create_from_tree)rN   r<   c           	      C   sX  |j }|d| j d | jD ]}|d| d q | j}|j}| j}d}||d||j| jt	| j
f | j |j}||d||j| jt	| jf | j | j| jkr|d| j d zF| dr|d	 | jd
d
D ]}|d| d
 d qW n ty   Y n0 |d t| jtrJ|| j| j n
|| j | S )Nztree %s
asciiz
parent %s
z%s %s <%s> %s %s
r/   r2   zencoding %s
r8   s   gpgsigrg    rh   )writer.   r   r6   r/   namer2   emailr0   r   r1   r7   r3   r4   r   __getattribute__r8   rstriprj   AttributeErrorr?   r5   ri   )	r@   rN   r   r   aanamecfmtZsiglinerC   rC   rD   rI     sb    
		
zCommit._serializec              	   C   s  |j }t| jt|  d tjd> d| _g | _d }| }|dsL|}qx| j	t
| | jt| d d q6t| j| _|}| }| }|dr| }|dr| }qq| j| _d| _|}| }|r|d	d
 dkr||dd d  | jd| _n|d	d dkr||dd d  d }	d}
| }|sNq|d	d dkrp| }d}
q|	|dd  7 }	q>|	d| jd| _|
rq|  }qz"t|| jd\| _| _| _W n( ty   tjd|| jdd Y n0 z"t|| jd\| _| _| _W n( tyD   tjd|| jdd Y n0 | | _z| j| jd| _W n* ty   tjd| j| jdd Y n0 | S )Nr      rl   s   parentr   s	   mergetag     r   
   s	   encoding ignore   s   gpgsig rh   FTr_   z3Failed to decode author line '%s' using encoding %s)exc_infoz6Failed to decode committer line '%s' using encoding %sz/Failed to decode message '%s' using encoding %s)r   r   r:   r   rj   Ztree_idr.   r6   
startswithr   r-   r   rF   r   r7   r8   r   findr   r   r/   r0   r1   UnicodeDecodeError_loggererrorr2   r3   r4   rc   r5   )r@   rN   r   	next_lineZparent_lineZauthor_lineZcommitter_lineencbufsigZis_next_headerZsigbufrC   rC   rD   rb     s    &
,


$

zCommit._deserializec                 C   s8   g }| j r4td| j tj}|D ]}|t|  q |S )a  Search the commit message for any co-authors of this commit.

        Details on co-authors:
        https://github.blog/2018-01-29-commit-together-with-co-authors/

        :return:
            List of co-authors for this commit (as :class:`~git.util.Actor` objects).
        z^Co-authored-by: (.*) <(.*?)>$)r5   refindall	MULTILINEr   r   )r@   
co_authorsresultsr/   rC   rC   rD   r   n  s    
zCommit.co_authors)NNNNNNNNNNN)rl   )rl   )rl   )NFNNNN)9__name__
__module____qualname____doc__r   r   r   r   r-   r(   __annotations__rX   Z_id_attribute_r!   bytesr$   r   r   r   floatri   r>   classmethodr"   rH   rP   r   r_   rd   propertydatetimere   rf   rk   r)   rs   rt   r   r|   r   r   r   r   r   r    r   r   r   r   rz   boolr   r   rI   rb   r   __classcell__rC   rC   rA   rD   r   C   s   
           








Z	  3$3' 0      


 ";j)B__all__collectionsr   r   ior   loggingrx   r   
subprocessr   r   sysr
   r   r   r	   r   r   Zgitdbr   Zgit.cmdr   Zgit.diffr   Zgit.utilr   r   r   r   rl   r   r.   r   utilr   r   r   r   r   r   typingr   r   r   r   r    r!   r"   r#   r$   r%   version_infor(   Ztyping_extensionsZ	git.typesr)   r   r*   Zgit.repor+   	getLoggerr   r   ZObjectr   rC   rC   rC   rD   <module>   s6    0
