U ��.e� � @ s� d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl m Z d dlmZ d dl mZ d dlmZ d d lmZ d d lmZmZmZ er�d dl mZ d dlmZ e�e�ZG d d� de�Ze�e� dS )� )�absolute_importN)�configparser)� BadCommand�InstallationError)�display_path)�make_command)� TempDirectory)�MYPY_CHECK_RUNNING)�path_to_url)�VersionControl�!find_path_to_setup_from_repo_root�vcs)� HiddenText)� RevOptionsc s� e Zd ZdZdZdZdZedd� �Zdd� Z d d � Z dd� Zd d� Ze dd� �Ze dd� �Ze dd� �Ze dd� �Ze dd� �Ze � fdd��Z� ZS )� Mercurial�hgz.hg�clone)r zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpc C s | gS )N� )Zrevr r �?/usr/lib/python3.8/site-packages/pip/_internal/vcs/mercurial.py�get_base_rev_args' s zMercurial.get_base_rev_argsc C s@ t dd��,}| j|j|d� | jd|gd|jd� W 5 Q R X dS )z?Export the Hg repository at the url to the destination location�export)Zkind)�url�archiveF��show_stdout�cwdN)r �unpack�path�run_command)�self�locationr Ztemp_dirr r r r + s �zMercurial.exportc C sP |� � }t�d||t|�� | �tddd||�� | jtdd|�� �|d� d S )NzCloning hg %s%s to %sr z --noupdate�-q�update�r )Z to_display�logger�infor r r �to_args)r �destr �rev_optionsZrev_displayr r r � fetch_new5 s ��zMercurial.fetch_newc C s� t j�|| jd�}t�� }z>|�|� |�dd|j� t |d��}|� |� W 5 Q R X W n6 ttjfk r� } zt �d||� W 5 d }~X Y n X tdd|�� �}| j||d� d S ) NZhgrc�paths�default�wz/Could not switch Mercurial repository to %s: %sr" r! r# )�osr �join�dirnamer ZRawConfigParser�read�setZsecret�open�write�OSErrorZNoSectionErrorr$ Zwarningr r&