o
    ©„jÇ  ã                   @  sœ   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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 )
é    )ÚannotationsN)Ú
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	d
„ƒZd+dd„Z		d,d+dd„Z
	d,d+dd„Zed-dd„ƒZed-dd„ƒZed-dd „ƒZed.d$d%„ƒZed/d&d'„ƒZed/‡ fd(d)„ƒZ‡  ZS )0Ú	MercurialÚhgz.hgÚclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpÚrevÚstrÚreturnú	list[str]c                 C  s   d| › �gS )Nz--rev=© )r   r   r   úY/var/www/html/django_cbt/venv/lib/python3.10/site-packages/pip/_internal/vcs/mercurial.pyÚget_base_rev_args!   s   zMercurial.get_base_rev_argsÚdestÚurlr   Úrev_optionsr	   Ú	verbosityÚintÚNonec                 C  s�   |  ¡ }t d||t|ƒ¡ |dkrd}n|dkrd}n	|dkr#d}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_newr   c              
   C  sè   g }t j || jd¡}t ¡ }|dkr| d¡ z)| |¡ | dd|j	¡ t
|dƒ�}| |¡ W d   ƒ n1 s;w   Y  W n ttjfy^ }	 zt d||	¡ W Y d }	~	d S d }	~	ww tdg|¢| ¡ ‘R Ž }
| j|
|d	� d S )
NÚhgrcr   ú-qÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sr    r!   )ÚosÚpathÚjoinÚdirnameÚconfigparserÚRawConfigParserÚappendÚreadÚsetÚsecretÚopenÚwriteÚOSErrorÚNoSectionErrorr$   Úwarningr   r'   r&   )r(   r   r   r   r   Úextra_flagsÚrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   r   r   Úswitch=   s$   

ÿ€€ÿzMercurial.switchc                 C  sT   g }|dkr|  d¡ | jdg|¢|d� tdg|¢| ¡ ‘R Ž }| j||d� d S )Nr   r-   Úpullr!   r    )r7   r&   r   r'   )r(   r   r   r   r   r@   rE   r   r   r   r    V   s   
zMercurial.updateÚlocationc                 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   )ÚclsrH   r   r   r   r   Úget_remote_urlf   s   üû
zMercurial.get_remote_urlc                 C  ó   | j ddgdd|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}FTrJ   ©r&   rM   )rO   rH   Úcurrent_revisionr   r   r   Úget_revisionr   s   üûzMercurial.get_revisionc                 C  rQ   )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rR   z--template={node}FTrJ   rS   )rO   rH   Úcurrent_rev_hashr   r   r   Úget_requirement_revision   s   üûz"Mercurial.get_requirement_revisionÚnameú
str | NoneÚboolc                 C  s   dS )z&Always assume the versions don't matchFr   )rO   r   rX   r   r   r   Úis_commit_id_equal�   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.
        ÚrootFTrJ   )r&   rM   r1   r2   ÚisabsÚabspathr3   r   )rO   rH   Ú	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 n ty(   t d|¡ Y d S  ty1   Y d S w tj 	| 
d¡¡S )Nr\   FTÚraise)r"   rK   rL   Ú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   r1   r2   ÚnormpathÚrstrip)rO   rH   ÚlocÚr©Ú	__class__r   r   re       s,   
úýÿzMercurial.get_repository_root)r   r   r   r   )
r   r   r   r   r   r	   r   r   r   r   )r   )rH   r   r   r   )r   r   rX   rY   r   rZ   )rH   r   r   rY   )Ú__name__Ú
__module__Ú__qualname__rX   r4   Ú	repo_nameÚschemesÚstaticmethodr   r+   rF   r    ÚclassmethodrP   rU   rW   r[   r`   re   Ú__classcell__r   r   rk   r   r      s0    
ûûr   )Ú
__future__r   r5   Úloggingr1   Úpip._internal.exceptionsr   r   Úpip._internal.utils.miscr   r   Úpip._internal.utils.subprocessr   Úpip._internal.utils.urlsr   Ú pip._internal.vcs.versioncontrolr	   r
   r   r   Ú	getLoggerrm   r$   r   Úregisterr   r   r   r   Ú<module>   s    
 &