U
    „~$h�  ã                   @   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   d| › �gS )Nz--rev=© )r   r   r   ú?/tmp/pip-unpacked-wheel-g27rp152/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|||fžŽ ¡ | jtd|| ¡ fžŽ |d� d S )NzCloning hg %s%s to %sr   )z--quieté   r   é   )ú	--verbose)r   z--debugr   ú
--noupdateÚupdate©Úcwd)r   r   )r   )Ú
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 ¡ }z>| |¡ | dd|j¡ t	|dƒ�}| 
|¡ W 5 Q R X W n6 ttjfk
rŽ } zt d||¡ W 5 d }~X Y n X 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   rB   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
   )ÚclsrE   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}FTrG   ©r%   rJ   )rL   rE   Ú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
        rN   z--template={node}FTrG   rO   )rL   rE   Ú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   )rL   r   rT   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.
        ÚrootFTrG   )r%   rJ   r0   r1   ÚisabsÚabspathr2   r   )rL   rE   Ú	repo_rootr   r   r   Úget_subdirectory{   s       ÿ
zMercurial.get_subdirectoryc                    sz   t ƒ  |¡}|r|S z| jdg|ddddd�}W n6 tk
rR   t d|¡ Y d S  tk
rf   Y d S X tj 	| 
d¡¡S )NrV   FTÚraise)r!   rH   rI   Ú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   r0   r1   ÚnormpathÚrstrip)rL   rE   ÚlocÚr©Ú	__class__r   r   r_   ‰   s*    ú
ýzMercurial.get_repository_root)Ú__name__Ú
__module__Ú__qualname__rT   r3   Ú	repo_nameÚschemesÚstaticmethodÚstrr   r   r   r   Úintr*   rC   r   ÚclassmethodrM   rQ   rS   r   ÚboolrU   rZ   r_   Ú__classcell__r   r   re   r   r      s4      þr   )r4   Úloggingr0   Ú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   Ú	getLoggerrg   r#   r   Úregisterr   r   r   r   Ú<module>   s   
 