U
    
Ha                     @   s   d dl Z d dlZd dlZd dl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)
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dd Zdd Z	d	d
 Z
dd Zedd Zedd Zedd Zedd Zedd Ze fddZ  ZS )	Mercurialhgz.hgclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpc                 C   s   | gS )N )revr   r   ?/tmp/pip-unpacked-wheel-tx790h60/pip/_internal/vcs/mercurial.pyget_base_rev_args   s    zMercurial.get_base_rev_argsc                 C   sP   |  }td||t| | tddd|| | jtdd| |d d S )NzCloning hg %s%s to %sr   z
--noupdate-qupdatecwd)
to_displayloggerinfor   run_commandr   to_args)selfdesturlrev_optionsrev_displayr   r   r   	fetch_new!   s    zMercurial.fetch_newc           	   
   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   r   r   )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   switch0   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!   r:   r   r   r   r   A   s    zMercurial.updatec                 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	   )clslocationr    r   r   r   get_remote_urlG   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}FTr>   r   rA   )rC   rD   current_revisionr   r   r   get_revisionT   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
        rF   z--template={node}FTr>   rG   )rC   rD   current_rev_hashr   r   r   get_requirement_revisionb   s    
z"Mercurial.get_requirement_revisionc                 C   s   dS )z&Always assume the versions don't matchFr   )rC   r   namer   r   r   is_commit_id_equalq   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.
        rootFTr>   )r   rA   r(   r)   isabsabspathr*   r   )rC   rD   	repo_rootr   r   r   get_subdirectoryw   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 )NrN   FTraise)r   r?   r@   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(   r)   normpathrstrip)rC   rD   locr	__class__r   r   rW      s(    
zMercurial.get_repository_root)__name__
__module____qualname__rL   r+   	repo_nameschemesstaticmethodr   r#   r;   r   classmethodrE   rI   rK   rM   rR   rW   __classcell__r   r   r]   r   r      s*   





r   )r,   loggingr(   typingr   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   	getLoggerr_   r   r   registerr   r   r   r   <module>   s   
 