a
    ˆÀàg>  ã                   @   s  d dl m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mZ d dlmZm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 erÔd dlmZm Z  d dlm!Z! d dlm"Z"m#Z# e
j$Z$e
j%Z%e &e'¡Z(e )d¡Z*dd„ Z+G dd„ deƒZ,e -e,¡ dS )é    )Úabsolute_importN)Úparse)Úrequest)Ú
BadCommandÚInstallationError)Údisplay_pathÚhide_url)Úmake_command)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)ÚRemoteNotFoundErrorÚVersionControlÚ!find_path_to_setup_from_repo_rootÚvcs)ÚOptionalÚTuple)Ú
HiddenText)ÚAuthInfoÚ
RevOptionsz^[a-fA-F0-9]{40}$c                 C   s   t t | ¡ƒS ©N)ÚboolÚ
HASH_REGEXÚmatch)Úsha© r   úN/var/www/sistema_ama/venv/lib/python3.9/site-packages/pip/_internal/vcs/git.pyÚlooks_like_hash+   s    r   c                       sþ   e Zd ZdZdZdZdZdZdZe	dd„ ƒZ
d	d
„ Zdd„ Zedd„ ƒZdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zedd „ ƒZed!d"„ ƒZed.d$d%„ƒZed&d'„ ƒZe‡ fd(d)„ƒZed*d+„ ƒZe‡ fd,d-„ƒZ‡  ZS )/ÚGitÚgitz.gitÚclone)r   zgit+httpz	git+httpszgit+sshzgit+gitzgit+file)ZGIT_DIRZGIT_WORK_TREEÚHEADc                 C   s   | gS r   r   ©Úrevr   r   r   Úget_base_rev_args;   s    zGit.get_base_rev_argsc                 C   sJ   |   t|ƒ¡\}}|jsdS |  ||j¡s.dS t|  ||j¡d ƒ}| S )NFr   )Úget_url_rev_optionsr   r"   Úis_commit_id_equalr   Úget_revision_sha)ÚselfÚurlÚdestÚ_Úrev_optionsZis_tag_or_branchr   r   r   Úis_immutable_rev_checkout?   s    ÿzGit.is_immutable_rev_checkoutc                 C   s^   d}| j dgddd�}| |¡r:|t|ƒd …  ¡ d }nd}d | d¡d d	… ¡}t|ƒS )
Nzgit version ÚversionFT)Úshow_stdoutÚstdout_onlyr   Ú Ú.é   )Úrun_commandÚ
startswithÚlenÚsplitÚjoinÚparse_version)r'   ZVERSION_PFXr-   r   r   r   Úget_git_versionP   s    ÿ
zGit.get_git_versionc                 C   sB   g d¢}| j |ddd|d�}| ¡ }| d¡r>|tdƒd… S dS )zl
        Return the current branch, or None if HEAD isn't at a branch
        (e.g. detached HEAD).
        )zsymbolic-refú-qr    ©é   FT©Úextra_ok_returncodesr.   r/   Úcwdzrefs/heads/N)r3   Ústripr4   r5   )ÚclsÚlocationÚargsÚoutputÚrefr   r   r   Úget_current_branch_   s    
û
zGit.get_current_branchc                 C   sl   |  d¡s|d }tdd��<}| j|j|d� | jdddd|gd	|jd
� W d  ƒ n1 s^0    Y  dS )z@Export the Git repository at the url to the destination locationú/Úexport)Úkind)r(   zcheckout-indexz-az-fz--prefixF)r.   r?   N)Úendswithr
   ÚunpackÚpathr3   )r'   rB   r(   Útemp_dirr   r   r   rH   x   s    
þz
Git.exportc           
   	   C   sÀ   | j d|g|dddd�}i }| ¡  d¡D ]T}| d¡}|s>q*z|jdd	d
�\}}W n  tyt   td |¡ƒ‚Y n0 |||< q*d |¡}d |¡}	| |¡}|dur®|dfS | |	¡}|dfS )zö
        Return (sha_or_none, is_branch), where sha_or_none is a commit hash
        if the revision names a remote branch or tag, otherwise None.

        Args:
          dest: the repository directory.
          rev: the revision name.
        zshow-refFTÚignore)r?   r.   r/   Úon_returncodeÚ
úú é   )Úmaxsplitzunexpected show-ref line: {!r}zrefs/remotes/origin/{}zrefs/tags/{}N)r3   r@   r6   ÚrstripÚ
ValueErrorÚformatÚget)
rA   r)   r"   rD   ÚrefsÚliner   rE   Z
branch_refZtag_refr   r   r   r&   …   s0    û





zGit.get_revision_shac                 C   s.   |  d¡rdS t|ƒsdS |  ||¡r*dS dS )a$  
        Return true if rev is a ref or is a commit that we don't have locally.

        Branches and tags are not considered in this method because they are
        assumed to be always available locally (which is a normal outcome of
        ``git clone`` and ``git fetch --tags``).
        zrefs/TF)r4   r   Ú
has_commit)rA   r)   r"   r   r   r   Ú_should_fetch³   s    	
zGit._should_fetchc                 C   s¢   |j }|dusJ ‚|  ||¡\}}|durF| |¡}|r<|nd|_|S t|ƒsZt d|¡ |  ||¡sj|S | jt	dd|| 
¡ ƒ|d� | j|dd�}| |¡}|S )zµ
        Resolve a revision to a new RevOptions object with the SHA1 of the
        branch, tag, or ref if found.

        Args:
          rev_options: a RevOptions object.
        Nz:Did not find branch or tag '%s', assuming revision or ref.Úfetchr:   ©r?   Z
FETCH_HEADr!   )Úarg_revr&   Úmake_newÚbranch_namer   ÚloggerÚwarningr\   r3   r	   Úto_argsÚget_revision)rA   r)   r(   r+   r"   r   Z	is_branchr   r   r   Úresolve_revisionÊ   s*    

þþ
zGit.resolve_revisionc                 C   s   |sdS |   |¡|kS )z§
        Return whether the current commit hash equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        F)re   )rA   r)   Únamer   r   r   r%   ÷   s    	zGit.is_commit_id_equalc                 C   sÈ   |  ¡ }t d||t|ƒ¡ |  tdd||ƒ¡ |jrº|  |||¡}t|dd ƒ}|d u r†|  	||j¡sºtdd| 
¡ ƒ}| j||d� n4|  |¡|krºd |¡}dd|d	|g}| j||d� |  |¡ d S )
NzCloning %s%s to %sr   r:   ra   Úcheckoutr^   z	origin/{}z-bz--track)Ú
to_displayrb   Úinfor   r3   r	   r"   rf   Úgetattrr%   rd   rF   rW   Úupdate_submodules)r'   r)   r(   r+   Úrev_displayra   Úcmd_argsZtrack_branchr   r   r   Ú	fetch_new  s$    
ÿ

ÿzGit.fetch_newc                 C   sB   | j tdd|ƒ|d� tdd| ¡ ƒ}| j ||d� |  |¡ d S )NÚconfigzremote.origin.urlr^   rh   r:   )r3   r	   rd   rl   ©r'   r)   r(   r+   rn   r   r   r   Úswitch$  s    
þz
Git.switchc                 C   sr   |   ¡ tdƒkr$| jg d¢|d� n| jddg|d� |  |||¡}tddd| ¡ ƒ}| j||d� |  |¡ d S )Nz1.9.0)r]   r:   z--tagsr^   r]   r:   Úresetz--hard)r9   r8   r3   rf   r	   rd   rl   rq   r   r   r   Úupdate/  s    z
Git.updatec                 C   sv   | j g d¢ddd|d�}| ¡ }z|d }W n tyB   t‚Y n0 |D ]}| d¡rH|} q`qH| d¡d	 }| ¡ S )
z¢
        Return URL of the first remote encountered.

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        )rp   z--get-regexpzremote\..*\.urlr;   FTr=   r   zremote.origin.url rR   r<   )r3   Ú
splitlinesÚ
IndexErrorr   r4   r6   r@   )rA   rB   ÚstdoutZremotesZfound_remoteZremoter(   r   r   r   Úget_remote_url>  s$    
û

zGit.get_remote_urlc                 C   s>   z | j dddd| g|dd� W n ty4   Y dS 0 dS dS )	zU
        Check if rev is a commit that is available in the local repository.
        ú	rev-parser:   z--verifyzsha^F)r?   Úlog_failed_cmdTN)r3   r   )rA   rB   r"   r   r   r   r[   \  s    ý
zGit.has_commitNc                 C   s*   |d u rd}| j d|gdd|d�}| ¡ S )Nr    ry   FT©r.   r/   r?   )r3   r@   )rA   rB   r"   Zcurrent_revr   r   r   re   l  s    üzGit.get_revisionc                 C   sT   | j ddgdd|d� ¡ }tj |¡s4tj ||¡}tj tj |d¡¡}t||ƒS )z~
        Return the path to setup.py, relative to the repo root.
        Return None if setup.py is in the repo root.
        ry   z	--git-dirFTr{   z..)r3   r@   ÚosrL   Úisabsr7   Úabspathr   )rA   rB   Zgit_dirÚ	repo_rootr   r   r   Úget_subdirectoryx  s    ü
zGit.get_subdirectoryc                    sè   t |ƒ\}}}}}| d¡r„|dt| d¡ƒ … }|t |¡ dd¡ d¡ }| d¡d }	|d|	… t||	d… ||||fƒ }d|vrÈd|vs˜J ‚| d	d
¡}t	t
| ƒ |¡\}}
}| dd¡}nt	t
| ƒ |¡\}}
}||
|fS )a9  
        Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
        That's required because although they use SSH they sometimes don't
        work with a ssh:// scheme (e.g. GitHub). But we need a scheme for
        parsing. Hence we remove it again afterwards and return it as a stub.
        ÚfileNrG   ú\ú+r<   z://zfile:zgit+z
git+ssh://zssh://r0   )ÚurlsplitrJ   r5   ÚlstripÚurllib_requestÚurl2pathnameÚreplaceÚfindÚ
urlunsplitÚsuperr   Úget_url_rev_and_auth)rA   r(   ÚschemeÚnetlocrL   ÚqueryÚfragmentÚinitial_slashesÚnewpathZ
after_plusr"   Ú	user_pass©Ú	__class__r   r   rŒ   Š  s,    

ÿÿÿÿÿzGit.get_url_rev_and_authc                 C   s0   t j t j |d¡¡sd S | jg d¢|d� d S )Nz.gitmodules)Z	submodulert   z--initz--recursiver:   r^   )r|   rL   Úexistsr7   r3   )rA   rB   r   r   r   rl   ¬  s    þzGit.update_submodulesc                    s|   t t| ƒ |¡}|r|S z| jddg|ddddd�}W n2 tyV   t d|¡ Y d S  tyh   Y d S 0 tj	 
| d¡¡S )	Nry   z--show-toplevelFTÚraise)r?   r.   r/   rO   rz   zKcould not determine if %s is under git control because git is not availablez
)r‹   r   Úget_repository_rootr3   r   rb   Údebugr   r|   rL   ÚnormpathrU   )rA   rB   ÚlocÚrr”   r   r   r˜   µ  s(    ú
ÿzGit.get_repository_root)N)Ú__name__Ú
__module__Ú__qualname__rg   ÚdirnameÚ	repo_nameÚschemesÚunset_environÚdefault_arg_revÚstaticmethodr#   r,   r9   ÚclassmethodrF   rH   r&   r\   rf   r%   ro   rr   rt   rx   r[   re   r€   rŒ   rl   r˜   Ú__classcell__r   r   r”   r   r   /   sL   


-

,



!
r   ).Ú
__future__r   ÚloggingÚos.pathr|   ÚreZpip._vendor.packaging.versionr   r8   Úpip._vendor.six.moves.urllibÚurllib_parser   r†   Úpip._internal.exceptionsr   r   Úpip._internal.utils.miscr   r   Úpip._internal.utils.subprocessr	   Úpip._internal.utils.temp_dirr
   Úpip._internal.utils.typingr   Ú pip._internal.vcs.versioncontrolr   r   r   r   Útypingr   r   r   r   r   r„   rŠ   Ú	getLoggerr�   rb   Úcompiler   r   r   Úregisterr   r   r   r   Ú<module>   s4   

    