
    dh                        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j(                  e      Z G d d	e      Z ej0                  e       y)
    )annotationsN)
BadCommandInstallationError)
HiddenTextdisplay_path)make_command)path_to_url)
RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsc                       e Zd ZdZdZdZdZedd       Z	 	 	 	 	 	 	 	 	 	 ddZ		 d	 	 	 	 	 	 	 	 	 ddZ
	 d	 	 	 	 	 	 	 	 	 ddZedd	       Zedd
       Zedd       Zedd       Zedd       Zed fd       Z xZS )	Mercurialhgz.hgclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpc                    d|  gS )Nz--rev= )revs    ]/var/www/html/vivango/api/ia/venv/lib/python3.12/site-packages/pip/_internal/vcs/mercurial.pyget_base_rev_argszMercurial.get_base_rev_args!   s        c                4   |j                         }t        j                  d||t        |             |dk  rd}n|dk(  rd}n
|dk(  rd}nd}| j	                  t        d	d
g|||        | j	                  t        dg||j                          |       y )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)selfdesturlrev_options	verbosityrev_displayflagss          r   	fetch_newzMercurial.fetch_new%   s     ",,.#		
 >%1E!^E!^"E,Eg|OeOSO$OPAEA;+>+>+@A 	 	
r   c                L   g }t         j                  j                  || j                  d      }t	        j
                         }|dk  r|j                  d       	 |j                  |       |j                  dd|j                         t        |d      5 }|j                  |       d d d        t        dg||j                          }	| j                  |	|       y # 1 sw Y   9xY w# t        t        j                   f$ r!}
t"        j%                  d	||
       Y d }
~
y d }
~
ww xY w)
Nhgrcr   -qpathsdefaultwr   r   z/Could not switch Mercurial repository to %s: %s)ospathjoindirnameconfigparserRawConfigParserappendreadsetsecretopenwriter   r#   r"   OSErrorNoSectionErrorr    warning)r$   r%   r&   r'   r(   extra_flagsrepo_configconfigconfig_filecmd_argsexcs              r   switchzMercurial.switch=   s     ggll4v>--/>t$		1KK$JJw	3::6k3' *;[)*
 $HR{RK<O<O<QRHX40* *445 	XNNLcSVWW	Xs0   :C) C%C) C&"C) )D#DD#c                    g }|dk  r|j                  d       | j                  dg||       t        dg||j                          }| j                  ||       y )Nr   r.   pullr   r   )r8   r"   r   r#   )r$   r%   r&   r'   r(   rA   rE   s          r   r   zMercurial.updateV   si     >t$&/;/T:N;N8K8K8MNt,r   c                    | j                  ddgdd|      j                         }| j                  |      rt        |      }|j                         S )N
showconfigzpaths.defaultFTshow_stdoutstdout_onlyr   )r"   strip_is_local_repositoryr	   )clslocationr&   s      r   get_remote_urlzMercurial.get_remote_urlf   sX    oo?+	  

 %' 	 ##C(c"Cyy{r   c                P    | j                  ddgdd|      j                         }|S )zW
        Return the repository-local changeset revision number, as an integer.
        parentsz--template={rev}FTrL   r"   rO   )rQ   rR   current_revisions      r   get_revisionzMercurial.get_revisionr   s=    
 ??*+	 + 

 %' 	  r   c                P    | j                  ddgdd|      j                         }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rU   z--template={node}FTrL   rV   )rQ   rR   current_rev_hashs      r   get_requirement_revisionz"Mercurial.get_requirement_revision   s=     ??+,	 + 

 %' 	  r   c                     y)z&Always assume the versions don't matchFr   )rQ   r%   names      r   is_commit_id_equalzMercurial.is_commit_id_equal   s     r   c                   | j                  dgdd|      j                         }t        j                  j	                  |      s=t        j                  j                  t        j                  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.
        rootFTrL   )r"   rO   r2   r3   isabsabspathr4   r   )rQ   rR   	repo_roots      r   get_subdirectoryzMercurial.get_subdirectory   sl     OOH%Tx $ 

%' 	 ww}}Y'Xy(IJI7)LLr   c                   t         |   |      }|r|S 	 | j                  dg|dddd      }t        j                  j                  |j                  d            S # t        $ r t        j                  d|       Y y t        $ r Y y w xY w)Nr`   FTraise)r   rM   rN   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   r2   r3   normpathrstrip)rQ   rR   locr	__class__s       r   rj   zMercurial.get_repository_root   s    g)(3J	! %$   A" ww 011  	LL.
   		s   A B=BB)r   strreturnz	list[str])
r%   rq   r&   r   r'   r
   r(   intrr   None)r   )rR   rq   rr   rq   )r%   rq   r]   
str | Nonerr   bool)rR   rq   rr   ru   )__name__
__module____qualname__r]   r5   	repo_nameschemesstaticmethodr   r+   rG   r   classmethodrS   rX   r[   r^   rd   rj   __classcell__)rp   s   @r   r   r      sH   DGIG    

(
7A
NQ
	
: 11 1  	1
 1 
1< -- -  	-
 - 
-  	 	 
  
        M M 2 2r   r   )
__future__r   r6   loggingr2   pip._internal.exceptionsr   r   pip._internal.utils.miscr   r   pip._internal.utils.subprocessr   pip._internal.utils.urlsr	    pip._internal.vcs.versioncontrolr
   r   r   r   	getLoggerrw   r    r   registerr   r   r   <module>r      sZ    "   	 B = 7 0  
		8	$b2 b2J Y r   