
    *,hF                        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	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:                  j<                  Zej:                  j>                  Z e j@                  e!      Z" ejF                  d      Z$ ejF                  d      Z% ejF                  d	ejL                        Z'd
e(de)fdZ* G d de      Z+ ejX                  e+       y)    N)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    W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pip/_internal/vcs/git.pylooks_like_hashr   7   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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_argsK   s	    ur   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_checkoutO   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        d |j                         D              S )	Nversionzgit versionFT)command_descshow_stdoutstdout_onlyzCan't parse git version: %sr&   c              3   2   K   | ]  }t        |        y wr   )int).0cs     r   	<genexpr>z&Git.get_git_version.<locals>.<genexpr>h   s     4SV4s   )run_commandGIT_VERSION_REGEXr   loggerwarningtuplegroups)r/   r5   r   s      r   get_git_versionzGit.get_git_version]   sc    ""K&	 # 
 "''0NN8'B4U\\^444r   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#      FTextra_ok_returncodesr7   r8   cwdzrefs/heads/N)r>   strip
startswithlen)clsrE   argsoutputrefs        r   get_current_branchzGit.get_current_branchj   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)rL   r7   r8   on_returncode
    )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z
refs/tags/)r>   rM   splitrstrip
ValueErrorget)rP   r*   r$   rR   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)rN   r   
has_commit)rP   r*   r$   s      r   _should_fetchzGit._should_fetch   s2     >>'"s#>>$$r   r1   c           	         |j                   }|J | j                  ||      \  }}|%|j                  |      }|r	||_        |S 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.
        Nz:Did not find branch or tag '%s', assuming revision or ref.fetchrG   rL   
FETCH_HEADr'   )arg_revr.   make_newbranch_namer   r@   rA   ri   r>   r   to_argsget_revision)rP   r*   r)   r1   r$   r   	is_branchs          r   resolve_revisionzGit.resolve_revision   s     !! --dC8Y?%..s3K-6cK# =AK# 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)rr   )rP   r*   ru   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--quietrI   r&   )z	--verbosez
--progress)r[      r    z--filter=blob:nonerp   zRev options %s, branch_name %scheckoutrG   rl   zorigin/z-bz--trackzResolved %s to commit %s)
to_displayr@   infor	   rD   r>   r   r$   rt   getattrdebugr-   rq   rT   rr   ro   update_submodules)r/   r*   r)   r1   rw   rev_displayflagsrp   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.urlrl   rz   rG   )r>   r   rq   r   r/   r*   r)   r1   r   s        r   switchz
Git.switchD  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)rI   	   )rk   rG   z--tagsrl   rk   rG   resetz--hard)rD   r>   rt   r   rq   r   r   s        r   updatez
Git.updateN  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\..*\.urlrH   FTrJ   r   zremote.origin.url rZ   rI   )r>   
splitlines
IndexErrorr   rN   r]   _git_remote_to_pip_urlrM   )rP   rE   stdoutremotesfound_remoteremoter)   s          r   get_remote_urlzGit.get_remote_url\  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   ospathexistspathlibPurePathas_uri	SCP_REGEXexpandr   )r)   	scp_matchs     r   r   zGit._git_remote_to_pip_urlz  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-parserG   z--verifyzsha^F)rL   log_failed_cmdT)r>   r   )rP   rE   r$   s      r   rh   zGit.has_commit  sG    
		OOdJ=$    ! 		s    	**c                 X    |d}| j                  d|gdd|      }|j                         S )Nr#   r   FTr7   r8   rL   )r>   rM   )rP   rE   r$   current_revs       r   rr   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..)r>   rM   r   r   isabsjoinabspathr   )rP   rE   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/\+rI   z://zfile:zgit+z
git+ssh://zssh:// )urlsplitendswithrO   lstripurllibrequesturl2pathnamereplacefind
urlunsplitsuperget_url_rev_and_auth)rP   r)   schemenetlocr   queryfragmentinitial_slashesnewpath
after_plusr$   	user_pass	__class__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--recursiverG   rl   )r   r   r   r   r>   )rP   rE   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)rL   r7   r8   rW   r   zKcould not determine if %s is under git control because git is not availablez
)r   get_repository_rootr>   r   r@   r~   r   r   r   normpathr^   )rP   rE   locrr   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__ru   dirname	repo_nameschemesunset_environdefault_arg_revstaticmethodstrr   r(   r   r3   r   r:   rD   classmethodr   rT   r.   ri   r   r   rt   r-   r   r   r   r   r   rh   rr   r   r   r   r   r   r   __classcell__)r   s   @r   r   r   ;   s0   DGIG 1MOs tCy  $S $ $ $5sCx 5 # (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   )-loggingos.pathr   r   r   urllib.parser   urllib.requesttypingr   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   r@   compiler?   r   VERBOSEr   r   r   r   r   registerr&   r   r   <module>r      s       	   ( ( B G G 7   <<  \\$$
 
		8	$ BJJ  RZZ+,
 BJJ		 JJ	' ' 'P. Pf S r   