a ljQ @ s d dl Z d dlZd dlZd dlmZmZ d dlmZmZ d dl m Z mZ d dlm Z d dlmZ d dlmZmZmZmZ eeZG dd d eZee dS ) N)ListOptional) BadCommandInstallationError) HiddenTextdisplay_path)make_command)path_to_url) RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsc s e Zd ZdZdZdZdZeee e dddZ eeedd d dZ eeedd dd Zeeedd ddZeeedddZeeedddZeeedddZeeee edddZeeee dddZeeee d fddZ ZS ) MercurialZhgz.hgclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-http)revreturnc C s | gS )N )r r r ?/usr/lib/python3.9/site-packages/pip/_internal/vcs/mercurial.pyget_base_rev_args s zMercurial.get_base_rev_argsN)desturlrev_optionsr c C sP | }td||t| | tddd|| | jtdd| |d d S )NzCloning hg %s%s to %sr z --noupdate-qupdatecwd)Z to_displayloggerinfor run_commandr to_args)selfr r r Zrev_displayr r r fetch_new$ s zMercurial.fetch_newc C s t j|| jd}t }zR|| |dd|j t |d}| | W d n1 s`0 Y W n8 ttjfy } zt d|| W Y d }~n(d }~0 0 tdd| }| j||d d S ) NZhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr r r )ospathjoindirnameconfigparserZRawConfigParserreadsetZsecretopenwriteOSErrorZNoSectionErrorr Zwarningr r r ) r r r r Zrepo_configZconfigZconfig_fileexccmd_argsr r r switch2 s ,$zMercurial.switchc C s4 | j ddg|d tdd| }| j ||d d S )NZpullr r r )r r r )r r r r r0 r r r r @ s zMercurial.update)locationr c C s4 | j ddgdd|d }| |r,t|}| S )NZ showconfigz paths.defaultFTshow_stdoutstdout_onlyr )r stripZ_is_local_repositoryr )clsr2 r r r r get_remote_urlE s zMercurial.get_remote_urlc C s | j ddgdd|d }|S )zW Return the repository-local changeset revision number, as an integer. parentsz--template={rev}FTr3 r r6 )r7 r2 Zcurrent_revisionr r r get_revisionQ s zMercurial.get_revisionc C s | j ddgdd|d }|S )zh Return the changeset identification hash, as a 40-character hexadecimal string r9 z--template={node}FTr3 r: )r7 r2 Zcurrent_rev_hashr r r get_requirement_revision^ s z"Mercurial.get_requirement_revision)r namer c C s dS )z&Always assume the versions don't matchFr )r7 r r= r r r is_commit_id_equall s zMercurial.is_commit_id_equalc C sD | j dgdd|d }tj|s:tjtj||}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. rootFTr3 )r r6 r% r&