HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/vcs/__pycache__/git.cpython-310.pyc
o

;j�J�@sddlmZddlZddlZddlZddlZddlZddl	Zddl
mZddlm
Z
ddlmZmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZejj Z ejj!Z!e�"e#�Z$e�%d	�Z&e�%d
�Z'e�%dej(�Z)ddd�Z*Gdd�de�Z+e�,e+�dS)�)�annotationsN)�replace)�Any)�
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�str�return�boolcCstt�|��S�N)r�
HASH_REGEX�match)r�r�I/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/vcs/git.py�looks_like_hash:srcsReZdZdZdZdZdZdZdZe	dJdd��Z
edK�fdd��ZdLdd�Z
dMdd�ZedNdd��ZedOdd ��ZedPd!d"��ZedQd&d'��ZedRd)d*��ZdSd.d/�Z	0dTdSd1d2�Z	0dTdSd3d4�ZedUd5d6��Ze	dVd7d8��ZedWd9d:��ZedXdYd<d=��ZedNd>d?��ZedZ�fdAdB��ZedTd[dCdD��ZedN�fdEdF��Ze	d\dHdI��Z�Z S)]�Git�gitz.git�clone)zgit+httpz	git+httpszgit+sshzgit+gitzgit+file)ZGIT_DIRZ
GIT_WORK_TREE�HEAD�revrr�	list[str]cCs|gSrr�r rrr�get_base_rev_argsNszGit.get_base_rev_args�argsr�kwargscsBtj�d�r|�di�}d|d<d|d<||d<t�j|i|��S)NZPIP_NO_INPUT�
extra_environ�0ZGIT_TERMINAL_PROMPTzssh -oBatchMode=yesZGIT_SSH_COMMAND)�os�environ�get�super�run_command)�clsr$r%r&��	__class__rrr,RszGit.run_command�url�destrcCsJ|�t|��\}}|jsdS|�||j�sdSt|�||j�d�}|S)NFr)Zget_url_rev_optionsr	r �is_commit_id_equalr�get_revision_sha)�selfr0r1�_�rev_optionsZis_tag_or_branchrrr�is_immutable_rev_checkout[szGit.is_immutable_rev_checkout�tuple[int, ...]cCsN|jdgdddd�}t�|�}|st�d|�dSt|�d��t|�d	��fS)
N�versionzgit versionFT)Zcommand_desc�show_stdout�stdout_onlyzCan't parse git version: %sr��)r,�GIT_VERSION_REGEXr�logger�warning�int�group)r4r9rrrr�get_git_versionis�
zGit.get_git_version�location�
str | NonecCsBgd�}|j|ddd|d�}|��}|�d�r|td�d�SdS)zl
        Return the current branch, or None if HEAD isn't at a branch
        (e.g. detached HEAD).
        )zsymbolic-ref�-qr�r<FT�Zextra_ok_returncodesr:r;�cwdzrefs/heads/N)r,�strip�
startswith�len)r-rDr$�output�refrrr�get_current_branchvs
�
zGit.get_current_branch�tuple[str | None, bool]c	Cs�|jd|g|dddd�}i}|���d�D](}|�d�}|sqz|jdd	d
�\}}Wnty8td|����w|||<qd|��}d
|��}	|�|�}
|
durU|
dfS|�|	�}
|
dfS)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.
        zshow-refFT�ignore)rIr:r;�
on_returncode�
�
� r=)�maxsplitzunexpected show-ref line: zrefs/remotes/origin/z
refs/tags/N)r,rJ�split�rstrip�
ValueErrorr*)r-r1r rMZrefs�lineZref_shaZref_nameZ
branch_refZtag_refrrrrr3�s2�
�




zGit.get_revision_shacCs.|�d�rdSt|�s
dS|�||�rdSdS)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``).
        zrefs/TF)rKr�
has_commit)r-r1r rrr�
_should_fetch�s
	zGit._should_fetchrr6rcCs�|j}|dus	J�|�||�\}}|dur&|�|�}t||r |ndd�}|St|�s0t�d|�|�||�s8|S|jt	dd||�
��|d�|j|dd�}|�|�}|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.�fetchrF�rIZ
FETCH_HEADr")Zarg_revr3�make_newrrr?�infor\r,r
�to_args�get_revision)r-r1r0r6r rZ	is_branchrrr�resolve_revision�s*
��
zGit.resolve_revision�namecCs|sdS|�|�|kS)z�
        Return whether the current commit hash equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        F)rc)r-r1rerrrr2s	zGit.is_commit_id_equal�	verbosityrA�NonecCsX|��}t�d||t|��|dkrd}n	|dkrd}nd}|��dkr5|�tdd	g|�|�|�R��n|�tdg|�|�|�R��|jr�|�|||�}t	|d
d�}t�
d||�|durv|�||j�sutdd
|���}|j||d�n%|�
|�|kr�d|��}	dd|d|	g}|j||d�n
|�|�}
|�|
�}t�d||j�|j||d�dS)NzCloning %s%s to %sr)z--quietr<r)z	--verbosez
--progress)r=�rz--filter=blob:noner]zRev options %s, branch_name %s�checkoutrFr_zorigin/z-bz--trackzResolved %s to commit %s�rf)Z
to_displayr?rarrCr,r
r rd�getattr�debugr2rbrOrcr`�update_submodules)r4r1r0r6rfZrev_display�flagsr]�cmd_argsZtrack_branchrrrr�	fetch_news`�����
��
��

z
Git.fetch_newrcCsd|jtdd|�|d�g}|dkr|�d�tdg|�|���R�}|j||d�|j||d�dS)N�configzremote.origin.urlr_rrFrirj)r,r
�appendrbrm�r4r1r0r6rf�extra_flagsrorrr�switchPs
�
z
Git.switchcCs�g}|dkr|�d�|��dkr|jddg|�|d�n
|jdg|�|d�|�|||�}tddg|�|���R�}|j||d�|j||d	�dS)
NrrF)r<�	r^z--tagsr_�resetz--hardrj)rrrCr,rdr
rbrmrsrrr�updatefs"
���z
Git.updatecCsx|jgd�ddd|d�}|��}z|d}Wn	tyt�w|D]}|�d�r-|}nq"|�d�d	}|�|���S)
z�
        Return URL of the first remote encountered.

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        )rqz--get-regexpzremote\..*\.urlrGFTrHrzremote.origin.url rUr<)r,�
splitlines�
IndexErrorrrKrW�_git_remote_to_pip_urlrJ)r-rD�stdoutZremotesZfound_remoteZremoter0rrr�get_remote_url�s(
��
�zGit.get_remote_urlcCsJt�d|�r|Stj�|�rt�|���St�|�}|r!|�	d�St
|��)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://[email protected]/foo/bar.git
            2. A local project.git folder: /path/to/bare/repository.git
            3. SCP shorthand for form 1: [email protected]: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)�rerr(�path�exists�pathlib�PurePath�as_uri�	SCP_REGEX�expandr
)r0Z	scp_matchrrrr{�s

zGit._git_remote_to_pip_urlcCs8z|jdddd|g|dd�WdStyYdSw)zU
        Check if rev is a commit that is available in the local repository.
        �	rev-parserFz--verifyzsha^F)rI�log_failed_cmdT)r,r)r-rDr rrrr[�s���zGit.has_commitNcCs*|durd}|jd|gdd|d�}|��S)Nrr�FT�r:r;rI)r,rJ)r-rDr Zcurrent_revrrrrc�s�zGit.get_revisioncCsT|jddgdd|d���}tj�|�stj�||�}tj�tj�|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,rJr(r�isabs�join�abspathr)r-rDZgit_dirZ	repo_rootrrr�get_subdirectory�s��
zGit.get_subdirectory� tuple[str, str | None, AuthInfo]cs�t|�\}}}}}|�d�rC|dt|�d���}|tj�|��dd��d�}|�d�d}	|d|	�t	||	d�||||f�}d|vrcd|vsMJ�|�d	d
�}t
��|�\}}
}|�dd�}n	t
��|�\}}
}||
|fS)
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�/�\�+r<z://zfile:zgit+z
git+ssh://zssh://�)�urlsplit�endswithrL�lstrip�urllib�requestZurl2pathnamer�find�
urlunsplitr+�get_url_rev_and_auth)r-r0�scheme�netlocr�query�fragment�initial_slashes�newpathZ
after_plusr Z	user_passr.rrr��s&

���
zGit.get_url_rev_and_authcCsFgd�}|dkr
|�d�tj�tj�|d��sdS|j||d�dS)N)Z	submodulerxz--initz--recursiverrFz.gitmodulesr_)rrr(rr�r�r,)r-rDrf�argvrrrrms

�zGit.update_submodulescsxt��|�}|r
|Sz|jddg|ddddd�}Wnty)t�d|�YdSty2YdSwtj�	|�
d��S)	Nr�z--show-toplevelFT�raise)rIr:r;rRr�zKcould not determine if %s is under git control because git is not availablez
)r+�get_repository_rootr,rr?rlrr(r�normpathrX)r-rD�loc�rr.rrr�s,
���zGit.get_repository_root�repo_urlcCsdS)zEIn either https or ssh form, requirements must be prefixed with git+.Tr)r�rrr�should_add_vcs_url_prefix5szGit.should_add_vcs_url_prefix)r rrr!)r$rr%rrr)r0rr1rrr)rr8)rDrrrE)r1rr rrrP)r1rr rrr)r1rr0rr6rrr)r1rrerErr)
r1rr0rr6rrfrArrg)r)rDrrr)r0rrr)rDrr rrrr)rDrr rErr)r0rrr�)rDrrfrArrg)r�rrr)!�__name__�
__module__�__qualname__re�dirnameZ	repo_nameZschemesZ
unset_environZdefault_arg_rev�staticmethodr#�classmethodr,r7rCrOr3r\rdr2rprurxr}r{r[rcr�r�rmr�r��
__classcell__rrr.rr>s\	


--
D��
r)rrrr)-�
__future__r�loggingZos.pathr(r�r~�urllib.parser��urllib.requestZdataclassesr�typingrZpip._internal.exceptionsrrZpip._internal.utils.miscrrr	Zpip._internal.utils.subprocessr
Z pip._internal.vcs.versioncontrolrrr
rrrr�parser�r��	getLoggerr�r?�compiler>r�VERBOSEr�rr�registerrrrr�<module>s>$

�

�