
    'jIK                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SK	J
r
  S SKJr  S SKJrJr  S SKJrJrJrJr  S SKJr  S SKJrJrJrJrJrJrJr  \R>                  R@                  r \R>                  RB                  r!\RD                  " \#5      r$\RJ                  " S	5      r&\RJ                  " S
5      r'\RJ                  " S\RP                  5      r)SS jr* " S S\5      r+\RX                  " \+5        g)    )annotationsN)replace)Any)
BadCommandInstallationError)
HiddenTextdisplay_pathhide_url	strtobool)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[^:]*)
    $c                >    [        [        R                  U 5      5      $ N)bool
HASH_REGEXmatch)shas    M/var/www/html/KUNJ/venv/lib/python3.13/site-packages/pip/_internal/vcs/git.pylooks_like_hashr   9   s    
  %&&    c                    ^  \ rS rSrSrSrSrSrSrSr	\
SS j5       r\SU 4S	 jj5       rS S
 jrS!S jr\S"S j5       r\S#S j5       r\S$S j5       r\        S%S j5       r\S&S j5       r          S'S jr S(         S'S jjr S(         S'S jjr\S)S j5       r\
S*S j5       r\S+S j5       r\S,S-S jj5       r\S"S j5       r\S.U 4S jj5       r\S(S/S jj5       r\S"U 4S jj5       r\
S0S j5       r Sr!U =r"$ )1Git=   gitz.gitclone)zgit+httpz	git+httpszgit+sshzgit+gitzgit+file)GIT_DIRGIT_WORK_TREEHEADc                    U /$ r    revs    r   get_base_rev_argsGit.get_base_rev_argsM   s	    ur   c                   > [         R                  R                  S5      (       a   UR                  S0 5      nSUS'   SUS'   X2S'   [        TU ]  " U0 UD6$ )NPIP_NO_INPUTextra_environ0GIT_TERMINAL_PROMPTzssh -oBatchMode=yesGIT_SSH_COMMAND)osenvirongetsuperrun_command)clsargskwargsr-   	__class__s       r   r5   Git.run_commandQ   sY    ::>>.))"JJ;M36M/0/DM+,&3?#w"D3F33r   c                    U R                  [        U5      5      u  p4UR                  (       d  gU R                  X$R                  5      (       d  g[	        U R                  X$R                  5      S   5      nU(       + $ )NFr   )get_url_rev_optionsr
   r(   is_commit_id_equalr   get_revision_sha)selfurldest_rev_optionsis_tag_or_branchs         r   is_immutable_rev_checkoutGit.is_immutable_rev_checkoutZ   sf    11(3-@&&t__==    5 5dOO LQ OP###r   c                    U R                  S/SSSS9n[        R                  U5      nU(       d  [        R	                  SU5        g[        UR                  S5      5      [        UR                  S	5      5      4$ )
Nversionzgit versionFT)command_descshow_stdoutstdout_onlyzCan't parse git version: %sr&         )r5   GIT_VERSION_REGEXr   loggerwarningintgroup)r?   rH   r   s      r   get_git_versionGit.get_git_versionh   sq    ""K&	 # 
 "''0NN8'BEKKN#SQ%899r   c                    / SQnU R                  USSSUS9nUR                  5       nUR                  S5      (       a  U[        S5      S $ g)zT
Return the current branch, or None if HEAD isn't at a branch
(e.g. detached HEAD).
)zsymbolic-ref-qr$   rL   FTextra_ok_returncodesrJ   rK   cwdzrefs/heads/N)r5   strip
startswithlen)r6   locationr7   outputrefs        r   get_current_branchGit.get_current_branchu   s]     .!% ! 
 lln>>-((s=)+,,r   c                   U R                  SU/USSSS9n0 nUR                  5       R                  S5       H4  nUR                  S5      nU(       d  M   UR                  SS	S
9u  pgXdU'   M6     SU 3nSU 3n	UR                  U5      n
U
b  U
S4$ UR                  U	5      n
U
S4$ ! [         a    [	        SU< 35      ef = f)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)rZ   rJ   rK   on_returncode
 rM   )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z
refs/tags/)r5   r[   splitrstrip
ValueErrorr3   )r6   rA   r(   r_   refslineref_sharef_name
branch_reftag_refr   s              r   r>   Git.get_revision_sha   s     " ! 
  LLN((.D;;t$DH$(JJsQJ$?! %N / ,C51
se$hhz"?;hhwU|!  H !#=dX!FGGHs   B&&C c                    UR                  S5      (       a  g[        U5      (       d  gU R                  X5      (       a  gg)z
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)r\   r   
has_commit)r6   rA   r(   s      r   _should_fetchGit._should_fetch   s9     >>'""s##>>$$$r   c           	        UR                   nUc   eU R                  X5      u  pVUb%  UR                  U5      n[        X6(       a  UOSS9nU$ [	        U5      (       d  [
        R                  SU5        U R                  X5      (       d  U$ U R                  [        SSX#R                  5       5      US9  U R                  USS9nUR                  U5      nU$ )	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.fetchrV   rZ   
FETCH_HEADr'   )arg_revr>   make_newr   r   rO   inforv   r5   r   to_argsget_revision)r6   rA   r@   rC   r(   r   	is_branchs          r   resolve_revisionGit.resolve_revision   s     !! --d8?%..s3K!+9CRVXK s##KKL
   ++ 	$-@-@-BC 	 	

 t6!**3/r   c                :    U(       d  gU R                  U5      U:H  $ )z
Return whether the current commit hash equals the given name.

Args:
  dest: the repository directory.
  name: a string name.
F)r   )r6   rA   names      r   r=   Git.is_commit_id_equal  s      %--r   c                   UR                  5       n[        R                  SX%[        U5      5        US::  a  SnOUS:X  a  SnOSnU R	                  5       S:  aO  [        [        R                  R                  SS	5      5      (       d!  U R                  [        S
S/UQUPUP76 5        OU R                  [        S
/UQUPUP76 5        UR                  (       a  U R                  XU5      n[        USS 5      n[        R                  SX75        UcK  U R                  XR                  5      (       d*  [        SSUR!                  5       5      nU R                  XS9  OSU R#                  U5      U:w  a  SU 3n	SSUSU	/nU R                  XS9  O"U R%                  U5      n
UR'                  U
5      n[        R                  SX#R                  5        U R)                  XS9  g )NzCloning %s%s to %sr   )z--quietrL   r&   )z	--verbosez
--progress)rM      *PIP_NO_PARTIAL_CLONE_FOR_BROKEN_GIT_SERVERnor!   z--filter=blob:nonery   zRev options %s, branch_name %scheckoutrV   r{   zorigin/z-bz--trackzResolved %s to commit %s	verbosity)
to_displayrO   r   r	   rS   r   r1   r2   r3   r5   r   r(   r   getattrdebugr=   r   ra   r   r~   update_submodules)r?   rA   r@   rC   r   rev_displayflagsry   cmd_argstrack_branchr   s              r   	fetch_newGit.fetch_new  s    ",,.(#L<NO>%1E!^E/E!W,YJJNNGN6
 6
 (  	
  \'EEE3EEF??//;GK!+}dCKLL9;T" ..t__EE+"#++- H
 $$X$8((.+= ")6     4##D)C%..s3K.__E 	t9r   c                    U R                  [        SSU5      US9  / nUS::  a  UR                  S5        [        S/UQUR                  5       P76 nU R                  XaS9  U R	                  XS9  g )Nconfigzremote.origin.urlr{   r   rV   r   r   )r5   r   appendr   r   r?   rA   r@   rC   r   extra_flagsr   s          r   switch
Git.switchQ  s     	#6< 	 	

 >t$
P[P+:M:M:OP,t9r   c                H   / nUS::  a  UR                  S5        U R                  5       S:  a  U R                  SS/UQUS9  OU R                  S/UQUS9  U R                  XU5      n[	        SS/UQUR                  5       P76 nU R                  XaS9  U R                  XS	9  g )
Nr   rV   )rL   	   rz   z--tagsr{   resetz--hardr   )r   rS   r5   r   r   r   r   r   s          r   update
Git.updateg  s     >t$ !V+gx>+>DIg44$?++D{C
 
 !	
 	,t9r   c                ,   U R                  / SQSSSUS9nUR                  5       n US   nU H  nUR	                  S5      (       d  M  Un  O   UR                  S5      S	   nU R                  UR                  5       5      $ ! [         a    [        ef = f)
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\..*\.urlrW   FTrX   r   zremote.origin.url rh   rL   )r5   
splitlines
IndexErrorr   r\   rj   _git_remote_to_pip_urlr[   )r6   r^   stdoutremotesfound_remoteremoter@   s          r   get_remote_urlGit.get_remote_url  s     :!% ! 
 ##%	&"1:L F  !566%    %a())#))+66  	&%%	&s   B Bc                >   [         R                  " SU 5      (       a  U $ [        R                  R	                  U 5      (       a$  [
        R                  " U 5      R                  5       $ [        R                  U 5      nU(       a  UR                  S5      $ [        U 5      e)a  
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   r1   pathexistspathlibPathas_uri	SCP_REGEXexpandr   )r@   	scp_matchs     r   r   Git._git_remote_to_pip_url  su    " 88Is##J77>># <<$++--OOC(	##$455!#&&r   c                V     U R                  SSSUS-   /USS9  g! [         a     gf = f)zE
Check if rev is a commit that is available in the local repository.
	rev-parserV   z--verifyz	^{commit}F)rZ   log_failed_cmdT)r5   r   )r6   r^   r(   s      r   ru   Git.has_commit  sH    
		OOdJk0AB$    ! 		s    
((c                T    Uc  SnU R                  SU/SSUS9nUR                  5       $ )Nr$   r   FTrJ   rK   rZ   )r5   r[   )r6   r^   r(   current_revs       r   r   Git.get_revision  sA    ;Coo#	 & 
   ""r   c                \   U R                  SS/SSUS9R                  5       n[        R                  R	                  U5      (       d  [        R                  R                  X5      n[        R                  R                  [        R                  R                  US5      5      n[        X5      $ )zy
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..)r5   r[   r1   r   isabsjoinabspathr   )r6   r^   git_dir	repo_roots       r   get_subdirectoryGit.get_subdirectory  s     //+&	 " 

 %' 	 ww}}W%%ggll85GGGOOBGGLL$$?@	7LLr   c                  > SSK n[        U5      u  p4pVnUR                  S5      (       a  US[        UR	                  S5      5      *  nXR
                  R                  U5      R                  SS5      R	                  S5      -   n	UR                  S5      S-   n
USU
 [        X:S XIXg45      -   nSU;  a?  S	U;  d   eUR                  S
S5      n[        TU ]-  U5      u  pnUR                  SS5      nO[        TU ]-  U5      u  pnXU4$ )a  
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.
r   Nfile/\+rL   z://zfile:zgit+z
git+ssh://zssh:// )urllib.requesturlsplitendswithr]   lstriprequesturl2pathnamer   find
urlunsplitr4   get_url_rev_and_auth)r6   r@   urllibschemenetlocr   queryfragmentinitial_slashesnewpath
after_plusr(   	user_passr9   s                r   r   Git.get_url_rev_and_auth  s     	 19-X??6"""#;c$++c*:&;%;<O%(C(CD(I(Q(Qc)fSkG  S)A-J*%
$fuG) C #%%%++fl3C"''">s"CCi++h+C"''">s"CCi""r   c                    / SQnUS::  a  UR                  S5        [        R                  R                  [        R                  R	                  US5      5      (       d  g U R                  UUS9  g )N)	submoduler   z--initz--recursiver   rV   z.gitmodulesr{   )r   r1   r   r   r   r5   )r6   r^   r   argvs       r   r   Git.update_submodules  sV    ?>KKww~~bggll8]CDD 	 	
r   c           	        > [         TU ]  U5      nU(       a  U$  U R                  SS/USSSSS9n[        R                  R                  UR                  S5      5      $ ! [         a    [        R                  SU5         g [         a     g f = f)	Nr   z--show-toplevelFTraise)rZ   rJ   rK   re   r   zKcould not determine if %s is under git control because git is not availablez
)r4   get_repository_rootr5   r   rO   r   r   r1   r   normpathrk   )r6   r^   locrr9   s       r   r   Git.get_repository_root  s    g)(3J	/0! %$   A" ww 011  	LL/
   		s   A  B	BBc                    g)zEIn either https or ssh form, requirements must be prefixed with git+.Tr&   )repo_urls    r   should_add_vcs_url_prefixGit.should_add_vcs_url_prefix8  s     r   r&   )r(   strreturnz	list[str])r7   r   r8   r   r   r   )r@   r   rA   r   r   r   )r   ztuple[int, ...])r^   r   r   
str | None)rA   r   r(   r   r   ztuple[str | None, bool])rA   r   r(   r   r   r   )rA   r   r@   r   rC   r   r   r   )rA   r   r   r   r   r   )
rA   r   r@   r   rC   r   r   rQ   r   None)r   )r^   r   r   r   )r@   r   r   r   )r^   r   r(   r   r   r   r   )r^   r   r(   r   r   r   )r@   r   r   z tuple[str, str | None, AuthInfo])r^   r   r   rQ   r   r   )r   r   r   r   )#__name__
__module____qualname____firstlineno__r   dirname	repo_nameschemesunset_environdefault_arg_revstaticmethodr)   classmethodr5   rE   rS   ra   r>   rv   r   r=   r   r   r   r   r   ru   r   r   r   r   r   r   __static_attributes____classcell__)r9   s   @r   r   r   =   s4   DGIG 1MO  4 4$:  0 + +Z  , ++'+6@+	+ +Z . .?:?:(?:7A?:NQ?:	?:L :: :  	:
 : 
:6 :: :  	:
 : 
:< 7 7: ' '<   	# 	# M M" # #@ 
 
 2 20  r   r   )r   r   r   r   )-
__future__r   loggingos.pathr1   r   r   urllib.parser   dataclassesr   typingr   pip._internal.exceptionsr   r   pip._internal.utils.miscr   r	   r
   r   pip._internal.utils.subprocessr    pip._internal.vcs.versioncontrolr   r   r   r   r   r   r   parser   r   	getLoggerr   rO   compilerN   r   VERBOSEr   r   r   registerr&   r   r   <module>r     s    "    	    B R R 7   <<  \\$$
 
		8	$ JJ  ZZ+,
 JJ		 JJ	'~. ~B S r   