
    )hH                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZmZmZ d dlmZmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZmZ ej@                  jB                  Z!ej@                  jD                  Z" e jF                  e$      Z% ejL                  d      Z' ejL                  d	      Z( ejL                  d
ejR                        Z*de+de,fdZ- G d de      Z. ej^                  e.       y)    N)replace)AnyListOptionalTuple)
BadCommandInstallationError)
HiddenTextdisplay_pathhide_url)make_command)AuthInfoRemoteNotFoundErrorRemoteNotValidError
RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsz(^git version (\d+)\.(\d+)(?:\.(\d+))?.*$z^[a-fA-F0-9]{40}$a/  ^
    # Optional user, e.g. 'git@'
    (\w+@)?
    # Server, e.g. 'github.com'.
    ([^/:]+):
    # The server-side path. e.g. 'user/project.git'. Must start with an
    # alphanumeric character so as not to be confusable with a Windows paths
    # like 'C:/foo/bar' or 'C:\foo\bar'.
    (\w[^:]*)
    $shareturnc                 >    t        t        j                  |             S N)bool
HASH_REGEXmatch)r   s    H/var/www/html/venv/lib/python3.12/site-packages/pip/_internal/vcs/git.pylooks_like_hashr   8   s    
  %&&    c            
           e Zd ZdZdZdZdZdZdZe	de
dee
   fd	       Zed
edede
f fd       Zde
de
defdZdeedf   fdZede
dee
   fd       Zede
de
deee
   ef   fd       Zede
de
defd       Zede
dededefd       Zede
dee
   d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
defd!       Z"ed)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
ee
   e%f   f fd$       Z&ede
ddfd%       Z'ede
dee
   f fd&       Z(e	d'e
defd(       Z) xZ*S )*Gitgitz.gitclone)zgit+httpz	git+httpszgit+sshzgit+gitzgit+file)GIT_DIRGIT_WORK_TREEHEADrevr   c                     | gS r    r&   s    r   get_base_rev_argszGit.get_base_rev_argsL   s	    ur   argskwargsc                     t         j                  j                  d      r!|j                  di       }d|d<   d|d<   ||d<   t        |   |i |S )NPIP_NO_INPUTextra_environ0GIT_TERMINAL_PROMPTzssh -oBatchMode=yesGIT_SSH_COMMAND)osenvirongetsuperrun_command)clsr+   r,   r/   	__class__s       r   r7   zGit.run_commandP   sX    ::>>.)"JJ;M36M/0/DM+,&3F?#w"D3F33r   urldestc                     | j                  t        |            \  }}|j                  sy| j                  ||j                        syt	        | j                  ||j                        d         }| S )NFr   )get_url_rev_optionsr   r&   is_commit_id_equalr   get_revision_sha)selfr:   r;   _rev_optionsis_tag_or_branchs         r   is_immutable_rev_checkoutzGit.is_immutable_rev_checkoutY   si    11(3-@;&&t[__=    5 5dKOO LQ OP###r   .c                     | j                  dgddd      }t        j                  |      }|st        j	                  d|       yt        |j                  d            t        |j                  d	            fS )
Nversionzgit versionFT)command_descshow_stdoutstdout_onlyzCan't parse git version: %sr(         )r7   GIT_VERSION_REGEXr   loggerwarningintgroup)r@   rF   r   s      r   get_git_versionzGit.get_git_versiong   sq    ""K&	 # 
 "''0NN8'BEKKN#SQ%899r   locationc                     g d}| j                  |ddd|      }|j                         }|j                  d      r|t        d      d S y)zl
        Return the current branch, or None if HEAD isn't at a branch
        (e.g. detached HEAD).
        )zsymbolic-ref-qr%   rJ   FTextra_ok_returncodesrH   rI   cwdzrefs/heads/N)r7   strip
startswithlen)r8   rR   r+   outputrefs        r   get_current_branchzGit.get_current_brancht   sZ     .!% ! 
 lln>>-(s=)+,,r   c                    | j                  d|g|ddd      }i }|j                         j                  d      D ]2  }|j                  d      }|s	 |j                  dd	
      \  }}|||<   4 d| }d| }	|j                  |      }
|
|
dfS |j                  |	      }
|
dfS # t        $ r t	        d|      w xY w)z
        Return (sha_or_none, is_branch), where sha_or_none is a commit hash
        if the revision names a remote branch or tag, otherwise None.

        Args:
          dest: the repository directory.
          rev: the revision name.
        zshow-refFTignore)rX   rH   rI   on_returncode
 rK   )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z
refs/tags/)r7   rY   splitrstrip
ValueErrorr5   )r8   r;   r&   r\   refslineref_sharef_name
branch_reftag_refr   s              r   r?   zGit.get_revision_sha   s    " ! 
  LLN((. 	%D;;t$DH$(JJsQJ$?! %DN	% ,C51
se$hhz"?;hhwU|!  H !#=dX!FGGHs   B%%B=c                 f    |j                  d      ryt        |      sy| j                  ||      ryy)a$  
        Return true if rev is a ref or is a commit that we don't have locally.

        Branches and tags are not considered in this method because they are
        assumed to be always available locally (which is a normal outcome of
        ``git clone`` and ``git fetch --tags``).
        zrefs/TF)rZ   r   
has_commit)r8   r;   r&   s      r   _should_fetchzGit._should_fetch   s2     >>'"s#>>$$r   rB   c           	         |j                   }|J | j                  ||      \  }}|$|j                  |      }t        ||r|nd      }|S t	        |      st
        j                  d|       | j                  ||      s|S | j                  t        dd||j                               |       | j                  |d      }|j                  |      }|S )	z
        Resolve a revision to a new RevOptions object with the SHA1 of the
        branch, tag, or ref if found.

        Args:
          rev_options: a RevOptions object.
        N)branch_namez:Did not find branch or tag '%s', assuming revision or ref.fetchrT   rX   
FETCH_HEADr)   )arg_revr?   make_newr   r   rM   rN   rq   r7   r   to_argsget_revision)r8   r;   r:   rB   r&   r   	is_branchs          r   resolve_revisionzGit.resolve_revision   s     !! --dC8Y?%..s3K!+9CRVXK s#NNL
   s+ 	$[-@-@-BC 	 	

 t6!**3/r   namec                 0    |sy| j                  |      |k(  S )z
        Return whether the current commit hash equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        F)rz   )r8   r;   r}   s      r   r>   zGit.is_commit_id_equal   s      %--r   	verbosityNc                 `   |j                         }t        j                  d||t        |             |dk  rd}n
|dk(  rd}nd}| j	                         dk\  r!| j                  t        dd	g|||        n| j                  t        dg|||        |j                  r| j                  |||      }t        |d
d       }t        j                  d||       |K| j                  ||j                        st        dd|j                               }| j                  ||       nV| j                  |      |k7  rBd| }	dd|d|	g}| j                  ||       n"| j                  |      }
|j                  |
      }t        j                  d||j                         | j!                  |       y )NzCloning %s%s to %sr   )z--quietrJ   r(   )z	--verbosez
--progress)rK      r"   z--filter=blob:noners   zRev options %s, branch_name %scheckoutrT   ru   zorigin/z-bz--trackzResolved %s to commit %s)
to_displayrM   infor   rQ   r7   r   r&   r|   getattrdebugr>   ry   r^   rz   rx   update_submodules)r@   r;   r:   rB   r   rev_displayflagsrs   cmd_argstrack_branchr   s              r   	fetch_newzGit.fetch_new  s    ",,.(#{L<NO>%1E!^E/E!W, (  	
  \'EEE3EEF??//c;GK!+}dCKLL9;T" ..t[__E+"#++- H
 $$X4$8((.+= ")6    t 4##D)C%..s3K.[__E 	t$r   c                     | j                  t        dd|      |       t        dd|j                               }| j                  ||       | j                  |       y )Nconfigzremote.origin.urlru   r   rT   )r7   r   ry   r   r@   r;   r:   rB   r   s        r   switchz
Git.switchN  s_    #6< 	 	
  
D+2E2E2GHt,t$r   c                 &   | j                         dk\  r| j                  g d|       n| j                  ddg|       | j                  |||      }t        ddd|j	                               }| j                  ||       | j                  |       y )N)rJ   	   )rt   rT   z--tagsru   rt   rT   resetz--hard)rQ   r7   r|   r   ry   r   r   s        r   updatez
Git.updateX  s    !V+6DAgt_$7++D#{C49L9L9NOt,t$r   c                 "   | j                  g dddd|      }|j                         }	 |d   }|D ]  }|j	                  d      s|} n |j                  d      d	   }| j                  |j                               S # t        $ r t        w xY w)
z
        Return URL of the first remote encountered.

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        )r   z--get-regexpzremote\..*\.urlrU   FTrV   r   zremote.origin.url rd   rJ   )r7   
splitlines
IndexErrorr   rZ   rf   _git_remote_to_pip_urlrY   )r8   rR   stdoutremotesfound_remoteremoter:   s          r   get_remote_urlzGit.get_remote_urlf  s     :!% ! 
 ##%	&"1:L  	F  !56%	   %a())#))+66  	&%%	&s   A> >Bc                    t        j                  d|       r| S t        j                  j	                  |       r#t        j                  |       j                         S t        j                  |       }|r|j                  d      S t        |       )a8  
        Convert a remote url from what git uses to what pip accepts.

        There are 3 legal forms **url** may take:

            1. A fully qualified url: ssh://git@example.com/foo/bar.git
            2. A local project.git folder: /path/to/bare/repository.git
            3. SCP shorthand for form 1: git@example.com:foo/bar.git

        Form 1 is output as-is. Form 2 must be converted to URI and form 3 must
        be converted to form 1.

        See the corresponding test test_git_remote_url_to_pip() for examples of
        sample inputs/outputs.
        z\w+://zssh://\1\2/\3)rer   r3   pathexistspathlibPurePathas_uri	SCP_REGEXexpandr   )r:   	scp_matchs     r   r   zGit._git_remote_to_pip_url  sq    " 88Is#J77>># ##C(//11OOC(	##$455!#&&r   c                 Z    	 | j                  dddd|z   g|d       y# t        $ r Y yw xY w)zU
        Check if rev is a commit that is available in the local repository.
        	rev-parserT   z--verifyzsha^F)rX   log_failed_cmdT)r7   r	   )r8   rR   r&   s      r   rp   zGit.has_commit  sG    
		OOdJ=$    ! 		s    	**c                 X    |d}| j                  d|gdd|      }|j                         S )Nr%   r   FTrH   rI   rX   )r7   rY   )r8   rR   r&   current_revs       r   rz   zGit.get_revision  sA    ;Coo#	 & 
   ""r   c                 \   | j                  ddgdd|      j                         }t        j                  j	                  |      s t        j                  j                  ||      }t        j                  j                  t        j                  j                  |d            }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.
        r   z	--git-dirFTr   z..)r7   rY   r3   r   isabsjoinabspathr   )r8   rR   git_dir	repo_roots       r   get_subdirectoryzGit.get_subdirectory  s     //+&	 " 

 %' 	 ww}}W%ggll8W5GGGOOBGGLL$$?@	7)LLr   c                    t        |      \  }}}}}|j                  d      r|dt        |j                  d              }|t        j
                  j                  |      j                  dd      j                  d      z   }|j                  d      dz   }	|d|	 t        ||	d ||||f      z   }d|vr>d|vsJ |j                  d	d
      }t        | -  |      \  }}
}|j                  dd      }nt        | -  |      \  }}
}||
|fS )a9  
        Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
        That's required because although they use SSH they sometimes don't
        work with a ssh:// scheme (e.g. GitHub). But we need a scheme for
        parsing. Hence we remove it again afterwards and return it as a stub.
        fileN/\+rJ   z://zfile:zgit+z
git+ssh://zssh:// )urlsplitendswithr[   lstripurllibrequesturl2pathnamer   find
urlunsplitr6   get_url_rev_and_auth)r8   r:   schemenetlocr   queryfragmentinitial_slashesnewpath
after_plusr&   	user_passr9   s               r   r   zGit.get_url_rev_and_auth  s*    19-eX??6""#;c$++c*:&;%;<O%(C(CD(I(Q(Qc)fSkG  S)A-J*%

$fguhG) C #%%%++fl3C"''">s"CCi++h+C"''">s"CCiC""r   c                     t         j                  j                  t         j                  j                  |d            sy | j	                  g d|       y )Nz.gitmodules)	submoduler   z--initz--recursiverT   ru   )r3   r   r   r   r7   )r8   rR   s     r   r   zGit.update_submodules  s;    ww~~bggll8]CDB 	 	
r   c                    t         |   |      }|r|S 	 | j                  d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   z--show-toplevelFTraise)rX   rH   rI   ra   r   zKcould not determine if %s is under git control because git is not availablez
)r6   get_repository_rootr7   r   rM   r   r	   r3   r   normpathrg   )r8   rR   locrr9   s       r   r   zGit.get_repository_root  s    g)(3J	/0! %$   A" ww 011  	LL/
   		s   A B	>B	B	repo_urlc                      y)zEIn either https or ssh form, requirements must be prefixed with git+.Tr(   )r   s    r   should_add_vcs_url_prefixzGit.should_add_vcs_url_prefix  s     r   r   )+__name__
__module____qualname__r}   dirname	repo_nameschemesunset_environdefault_arg_revstaticmethodstrr   r*   classmethodr   r7   r   rD   r   rO   rQ   r   r^   r?   rq   r
   r   r|   r>   r   r   r   r   r   rp   rz   r   r   r   r   r   r   __classcell__)r9   s   @r   r    r    <   sY   DGIG 1MOs tCy   4 4s 4s 4 4$S $ $ $:sCx : # (3-  0 +C +c +eHSM4<O6P + +Z  3 4  , ++'+6@+	+ +Z .c .# .4 . .=%=%(=%7A=%NQ=%	=%~%3 %Z %j %T %%3 %Z %j %T % 7c 7c 7 7: 'C 'C ' '< # C D   	#C 	#hsm 	#s 	# 	# M M M M" #s #uS(3-5Q/R # #< 
 
 
 
 23 28C= 2 20 C D  r   r    )0loggingos.pathr3   r   r   urllib.parser   urllib.requestdataclassesr   typingr   r   r   r   pip._internal.exceptionsr   r	   pip._internal.utils.miscr
   r   r   pip._internal.utils.subprocessr    pip._internal.vcs.versioncontrolr   r   r   r   r   r   r   parser   r   	getLoggerr   rM   compilerL   r   VERBOSEr   r   r   r   r    registerr(   r   r   <module>r      s       	    - - B G G 7   <<  \\$$
 
		8	$ BJJ  RZZ+,
 BJJ		 JJ	' ' 'Y. Yx S r   