
    k"g                         d dl Z d dlZd dlZd dlmZ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j,                  e      Z G d d	e      Z ej4                  e       y)
    N)ListOptionalTuple)
BadCommandInstallationError)
HiddenTextdisplay_path)make_command)path_to_url)
RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsc            
       F    e Zd ZdZdZdZdZedede	e   fd       Z
ded	ed
ededdf
dZded	ed
eddfdZded	ed
eddfdZededefd       Zededefd       Zededefd       Zededee   defd       Zededee   fd       Zededee   f fd       Z xZS )	Mercurialhgz.hgclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httprevreturnc                     d|  gS )Nz--rev= )r   s    T/var/www/html/djangosite/lib/python3.12/site-packages/pip/_internal/vcs/mercurial.pyget_base_rev_argszMercurial.get_base_rev_args    s        desturlrev_options	verbosityNc                 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)selfr   r   r   r   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                    t         j                  j                  || j                  d      }t	        j
                         }	 |j                  |       |j                  dd|j                         t        |d      5 }|j                  |       d d d        t        dd|j                               }| j                  ||       y # 1 sw Y   8xY w# t        t        j                  f$ r!}t         j#                  d||       Y d }~y d }~ww xY w)	Nhgrcpathsdefaultwr#   -qr$   z/Could not switch Mercurial repository to %s: %s)ospathjoindirnameconfigparserRawConfigParserreadsetsecretopenwriter
   r*   r)   OSErrorNoSectionErrorr'   warning)	r+   r   r   r   repo_configconfigconfig_filecmd_argsexcs	            r   switchzMercurial.switch<   s    ggll4v>--/		1KK$JJw	3::6k3' *;[)*
 $HdK4G4G4IJHX40* *445 	XNNLcSVWW	Xs0   :C ;CC C	C D
)DD
c                     | j                  ddg|       t        dd|j                               }| j                  ||       y )Npullr4   r$   r#   )r)   r
   r*   )r+   r   r   r   rF   s        r   r#   zMercurial.updateJ   sC    &$T2$0C0C0EFt,r   locationc                     | 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   )clsrK   r   s      r   get_remote_urlzMercurial.get_remote_urlO   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}FTrN   r)   rQ   )rS   rK   current_revisions      r   get_revisionzMercurial.get_revision[   s=    
 ??*+	 + 

 %' 	  r   c                 P    | j                  ddgdd|      j                         }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rV   z--template={node}FTrN   rW   )rS   rK   current_rev_hashs      r   get_requirement_revisionz"Mercurial.get_requirement_revisionh   s=     ??+,	 + 

 %' 	  r   namec                      y)z&Always assume the versions don't matchFr   )rS   r   r]   s      r   is_commit_id_equalzMercurial.is_commit_id_equalv   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.
        rootFTrN   )r)   rQ   r5   r6   isabsabspathr7   r   )rS   rK   	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)Nra   FTraise)r%   rO   rP   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   r5   r6   normpathrstrip)rS   rK   locr	__class__s       r   rk   zMercurial.get_repository_root   s    g)(3J	! %$   A" ww 011  	LL.
   		s   A B=BB)__name__
__module____qualname__r]   r8   	repo_nameschemesstaticmethodstrr   r   r   r   intr.   rH   r#   classmethodrT   rY   r\   r   boolr_   re   rk   __classcell__)rq   s   @r   r   r      s   DGIG  s  tCy    

(
7A
NQ
	
013 1Z 1j 1T 1-3 -Z -j -T -
 	c 	c 	 	 
 C 
 C 
  
          c # 4   M M M M 23 28C= 2 2r   r   )r9   loggingr5   typingr   r   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   	getLoggerrr   r'   r   registerr   r   r   <module>r      s]      	 ( ( B = 7 0  
		8	$L2 L2^ Y r   