a
    hbòfv  ã                   @   s¤   d dl Z d dlZd dlZd dlmZmZ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mZmZmZ e e¡ZG dd	„ d	eƒZe e¡ dS )
é    N)ÚListÚOptionalÚTuple)Ú
BadCommandÚInstallationError)Ú
HiddenTextÚdisplay_path)Úmake_command)Úpath_to_url)Ú
RevOptionsÚVersionControlÚ(find_path_to_project_root_from_repo_rootÚvcsc                       s   e Zd ZdZdZdZdZeee	e dœdd„ƒZ
eeeedd	œd
d„Zeeeddœdd„Zeeeddœdd„Zeeedœdd„ƒZeeedœdd„ƒZeeedœdd„ƒZeeee edœdd„ƒZeeee dœdd„ƒZeeee dœ‡ fdd„ƒZ‡  ZS )Ú	MercurialÚhgz.hgÚclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-http)ÚrevÚreturnc                 C   s   | gS )N© )r   r   r   úX/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_internal/vcs/mercurial.pyÚget_base_rev_args    s    zMercurial.get_base_rev_argsN)ÚdestÚurlÚrev_optionsÚ	verbosityr   c                 C   s�   |  ¡ }t d||t|ƒ¡ |dkr*d}n |dkr8d}n|dkrFd}nd}|  td	d
g|¢|‘|‘R Ž ¡ | jtdg|¢| ¡ ‘R Ž |d� d S )NzCloning hg %s%s to %sr   )z--quieté   r   é   )ú	--verbose)r   z--debugr   z
--noupdateÚupdate©Úcwd)Ú
to_displayÚloggerÚinfor   Úrun_commandr	   Úto_args)Úselfr   r   r   r   Úrev_displayÚflagsr   r   r   Ú	fetch_new$   s&    ü þzMercurial.fetch_new)r   r   r   r   c           	   
   C   sÈ   t j || jd¡}t ¡ }zR| |¡ | dd|j¡ t	|dƒ�}| 
|¡ W d   ƒ n1 s`0    Y  W n8 ttjfy¤ } zt d||¡ W Y d }~n(d }~0 0 tdd| ¡ ƒ}| j||d� d S )	NÚhgrcÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sr   ú-qr   )ÚosÚpathÚjoinÚdirnameÚconfigparserÚRawConfigParserÚreadÚsetÚsecretÚopenÚwriteÚOSErrorÚNoSectionErrorr"   Úwarningr	   r%   r$   )	r&   r   r   r   Úrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   r   r   Úswitch<   s    
,$zMercurial.switchc                 C   s4   | j ddg|d� tdd| ¡ ƒ}| j ||d� d S )NÚpullr.   r   r   )r$   r	   r%   )r&   r   r   r   rA   r   r   r   r   J   s    zMercurial.update)Úlocationr   c                 C   s4   | j ddgdd|d� ¡ }|  |¡r,t|ƒ}| ¡ S )NÚ
showconfigzpaths.defaultFT©Úshow_stdoutÚstdout_onlyr    )r$   ÚstripÚ_is_local_repositoryr
   )ÚclsrD   r   r   r   r   Úget_remote_urlO   s    ü

zMercurial.get_remote_urlc                 C   s   | j ddgdd|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}FTrF   ©r$   rI   )rK   rD   Úcurrent_revisionr   r   r   Úget_revision[   s    ü
zMercurial.get_revisionc                 C   s   | j ddgdd|d� ¡ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rM   z--template={node}FTrF   rN   )rK   rD   Úcurrent_rev_hashr   r   r   Úget_requirement_revisionh   s    ü
z"Mercurial.get_requirement_revision)r   Únamer   c                 C   s   dS )z&Always assume the versions don't matchFr   )rK   r   rS   r   r   r   Úis_commit_id_equalv   s    zMercurial.is_commit_id_equalc                 C   sD   | j dgdd|d� ¡ }tj |¡s:tj tj ||¡¡}t||ƒS )z‘
        Return the path to Python project root, relative to the repo root.
        Return None if the project root is in the repo root.
        ÚrootFTrF   )r$   rI   r/   r0   ÚisabsÚabspathr1   r   )rK   rD   Ú	repo_rootr   r   r   Úget_subdirectory{   s    
ÿ
zMercurial.get_subdirectoryc                    sv   t ƒ  |¡}|r|S z| jdg|ddddd�}W n2 tyP   t d|¡ Y d S  tyb   Y d S 0 tj 	| 
d¡¡S )NrU   FTÚraise)r    rG   rH   Úon_returncodeÚlog_failed_cmdzIcould not determine if %s is under hg control because hg is not availablez
)ÚsuperÚget_repository_rootr$   r   r"   Údebugr   r/   r0   ÚnormpathÚrstrip)rK   rD   ÚlocÚr©Ú	__class__r   r   r^   ‰   s*    ú
ýzMercurial.get_repository_root)Ú__name__Ú
__module__Ú__qualname__rS   r2   Ú	repo_nameÚschemesÚstaticmethodÚstrr   r   r   r   Úintr)   rB   r   ÚclassmethodrL   rP   rR   r   ÚboolrT   rY   r^   Ú__classcell__r   r   rd   r   r      s.   þr   )r3   Úloggingr/   Útypingr   r   r   Úpip._internal.exceptionsr   r   Úpip._internal.utils.miscr   r   Úpip._internal.utils.subprocessr	   Úpip._internal.utils.urlsr
   Ú pip._internal.vcs.versioncontrolr   r   r   r   Ú	getLoggerrf   r"   r   Úregisterr   r   r   r   Ú<module>   s   
 