HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //snap/certbot/4965/lib/python3.12/site-packages/pip/_internal/vcs/__pycache__/git.cpython-312.pyc
�

:�h�J����ddlmZddlZddlZddlZddlZddlZddl	Zddl
mZddlm
Z
ddlmZmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZej>j@Z ej>jBZ!ejDe#�Z$ejJd	�Z&ejJd
�Z'ejJdejP�Z)dd�Z*Gd
�de�Z+ejXe+�y)�)�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[^:]*)
    $c�>�ttj|��S�N)�bool�
HASH_REGEX�match)�shas ��/build/snapcraft-certbot-c9561b03ef7f16aa90eb6754ca5f17a1/parts/certbot/install/lib/python3.12/site-packages/pip/_internal/vcs/git.py�looks_like_hashr:s���
� � ��%�&�&�c����eZdZdZdZdZdZdZdZe	dd��Z
ed�fd��Zdd	�Z
dd
�Zed d��Zed!d��Zed"d
��Ze								d#d��Zed$d��Z										d%d�Z	d&									d%d�Z	d&									d%d�Zed'd��Ze	d(d��Zed)d��Zed*d+d��Zed d��Zed,�fd��Zed&d-d��Zed �fd��Ze	d.d��Z�xZ S)/�Git�gitz.git�clone)zgit+httpz	git+httpszgit+sshzgit+gitzgit+file)�GIT_DIR�
GIT_WORK_TREE�HEADc��|gSr���revs r�get_base_rev_argszGit.get_base_rev_argsNs	���u�rc���tjjd�r!|jdi�}d|d<d|d<||d<t�|�|i|��S)N�PIP_NO_INPUT�
extra_environ�0�GIT_TERMINAL_PROMPTzssh -oBatchMode=yes�GIT_SSH_COMMAND)�os�environ�get�super�run_command)�cls�args�kwargsr*�	__class__s    �rr2zGit.run_commandRsX���
�:�:�>�>�.�)�"�J�J���;�M�36�M�/�0�/D�M�+�,�&3�F�?�#��w�"�D�3�F�3�3rc���|jt|��\}}|jsy|j||j�syt	|j||j�d�}|S)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_checkoutzGit.is_immutable_rev_checkout[si���1�1�(�3�-�@���;������&�&�t�[�_�_�=�� �� 5� 5�d�K�O�O� L�Q� O�P��#�#�#rc���|jdgddd��}tj|�}|stj	d|�yt|j
d��t|j
d	��fS)
N�versionzgit versionFT)�command_desc�show_stdout�stdout_onlyzCan't parse git version: %sr$��)r2�GIT_VERSION_REGEXr�logger�warning�int�group)r;rCrs   r�get_git_versionzGit.get_git_versionisq���"�"�
�K�&���	#�
��"�'�'��0����N�N�8�'�B���E�K�K��N�#�S����Q��%8�9�9rc��gd�}|j|ddd|��}|j�}|jd�r|td�dSy)zl
        Return the current branch, or None if HEAD isn't at a branch
        (e.g. detached HEAD).
        )zsymbolic-ref�-qr"�rGFT��extra_ok_returncodesrErF�cwdzrefs/heads/N)r2�strip�
startswith�len)r3�locationr4�output�refs     r�get_current_branchzGit.get_current_branchvsZ��.������!%����!�
���l�l�n���>�>�-�(��s�=�)�+�,�,�rc��|jd|g|ddd��}i}|j�jd�D]2}|jd�}|s�	|jdd	�
�\}}|||<�4d|��}d
|��}	|j|�}
|
�|
dfS|j|	�}
|
dfS#t$rt	d|����wxYw)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)rTrErF�
on_returncode�
�
� rH)�maxsplitzunexpected show-ref line: zrefs/remotes/origin/z
refs/tags/)r2rU�split�rstrip�
ValueErrorr0)r3r=r&rY�refs�line�ref_sha�ref_name�
branch_ref�tag_refrs           rr:zGit.get_revision_sha�s�����
������"�!�
�����L�L�N�(�(��.�	%�D��;�;�t�$�D���
H�$(�J�J�s�Q�J�$?�!���%�D��N�	%�,�C�5�1�
��s�e�$���h�h�z�"���?���;���h�h�w����U�|���!�
H�!�#=�d�X�!F�G�G�
H�s�B%�%B=c�f�|jd�ryt|�sy|j||�ryy)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)rVr�
has_commit)r3r=r&s   r�
_should_fetchzGit._should_fetch�s2���>�>�'�"���s�#���>�>�$��$��rc	��|j}|�J�|j||�\}}|�$|j|�}t||r|nd��}|St	|�st
j
d|�|j||�s|S|jtdd||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.�fetchrP�rT�
FETCH_HEADr%)�arg_revr:�make_newrrrJ�infornr2r�to_args�get_revision)r3r=r<r?r&r�	is_branchs       r�resolve_revisionzGit.resolve_revision�s����!�!�������-�-�d�C�8���Y��?�%�.�.�s�3�K�!�+�9�C�RV�X�K����s�#��K�K�L��
�
� � ��s�+���	�����$��[�-@�-@�-B�C��	�	
�
���t���6��!�*�*�3�/���rc�0�|sy|j|�|k(S)z�
        Return whether the current commit hash equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        F)rx)r3r=�names   rr9zGit.is_commit_id_equals ��������%��-�-rc�d�|j�}tjd||t|��|dkrd}n
|dk(rd}nd}|j	�dk\r!|jt
dd	g|�|�|����n|jt
dg|�|�|����|jr�|j|||�}t|d
d�}tjd||�|�K|j||j�s�t
dd
|j��}|j||��nV|j|�|k7rBd|��}	dd|d|	g}|j||��n"|j|�}
|j|
�}tjd||j�|j!||��y)NzCloning %s%s to %sr)z--quietrGr$)z	--verbosez
--progress)rH�rz--filter=blob:nonerpzRev options %s, branch_name %s�checkoutrPrrzorigin/z-bz--trackzResolved %s to commit %s��	verbosity)�
to_displayrJrvr	rNr2rr&rz�getattr�debugr9rwr[rxru�update_submodules)r;r=r<r?r��rev_display�flagsrp�cmd_args�track_branchrs           r�	fetch_newz
Git.fetch_news���"�,�,�.�����(�#�{�L��<N�O���>�%1�E�
�!�^��E�/�E����!�W�,�
�����(�����	�
��
�
���\�'�E�E�E�3�E��E�F��?�?��/�/��c�;�G�K�!�+�}�d�C�K��L�L�9�;��T��"��.�.�t�[�_�_�E�+�"��#�+�+�-� �H�
�$�$�X�4�$�8��(�(��.�+�=�")��
�6������ ���� � ��t� �4��#�#�D�)�C�%�.�.�s�3�K����.��[�_�_�E�	
���t�y��9rc���|jtdd|�|��g}|dkr|jd�tdg|�|j����}|j||��|j	||��y)N�configzremote.origin.urlrrrrPrr�)r2r�appendrwr��r;r=r<r?r��extra_flagsr�s       r�switchz
Git.switchPs���	
�����#6��<��	�	
�
����>����t�$��
�P�[�P�+�:M�:M�:O�P������t��,����t�y��9rc�b�g}|dkr|jd�|j�dk\r|jddg|�|��n|jdg|�|��|j|||�}t	ddg|�|j����}|j||��|j
||�	�y)
NrrP)rG�	rqz--tagsrr�resetz--hardr�)r�rNr2rzrrwr�r�s       r�updatez
Git.updatefs�������>����t�$����!�V�+����g�x�>�+�>�D��I����g�4��4�$��?��+�+�D�#�{�C�����
��
�
���!�	
��	
����t��,����t�y��9rc�"�|jgd�ddd|��}|j�}	|d}|D]}|j	d�s�|}n|jd�d	}|j
|j��S#t$rt�wxYw)
z�
        Return URL of the first remote encountered.

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        )r�z--get-regexpzremote\..*\.urlrQFTrRrzremote.origin.url rarG)r2�
splitlines�
IndexErrorr
rVrc�_git_remote_to_pip_urlrU)r3rX�stdout�remotes�found_remote�remoter<s       r�get_remote_urlzGit.get_remote_url�s������:�!%����!�
���#�#�%��	&�"�1�:�L��	�F�� � �!5�6�%���	�� � ��%�a�(���)�)�#�)�)�+�6�6���	&�%�%�	&�s�A>�>Bc��tjd|�r|Stjj	|�r#tj|�j�Stj|�}|r|jd�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://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)�rerr.�path�exists�pathlib�PurePath�as_uri�	SCP_REGEX�expandr)r<�	scp_matchs  rr�zGit._git_remote_to_pip_url�sq��"�8�8�I�s�#��J�
�7�7�>�>�#���#�#�C�(�/�/�1�1��O�O�C�(�	���#�#�$4�5�5�!�#�&�&rc�Z�	|jdddd|zg|d��y#t$rYywxYw)zU
        Check if rev is a commit that is available in the local repository.
        �	rev-parserPz--verifyzsha^F)rT�log_failed_cmdT)r2r)r3rXr&s   rrmzGit.has_commit�sG��
		��O�O��d�J����=��$�
�
���!�	��	�s��	*�*c�X�|�d}|jd|gdd|��}|j�S)Nr"r�FT�rErFrT)r2rU)r3rXr&�current_revs    rrxzGit.get_revision�sA���;��C��o�o�
�#�����	&�
��� � �"�"rc�\�|jddgdd|��j�}tjj	|�s tjj||�}tjj
tjj|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..)r2rUr.r��isabs�join�abspathr)r3rX�git_dir�	repo_roots    r�get_subdirectoryzGit.get_subdirectory�s����/�/�
�+�&����	"�
�
�%�'�	��w�w�}�}�W�%��g�g�l�l�8�W�5�G��G�G�O�O�B�G�G�L�L��$�$?�@�	�7��)�L�Lrc���t|�\}}}}}|jd�r�|dt|jd��}|tj
j
|�jdd�jd�z}|jd�dz}	|d|	t||	d||||f�z}d|vr>d|vsJ�|jd	d
�}t�|�-|�\}}
}|jdd�}nt�|�-|�\}}
}||
|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�/�\�+rGz://zfile:zgit+z
git+ssh://zssh://�)�urlsplit�endswithrW�lstrip�urllib�request�url2pathnamer�find�
urlunsplitr1�get_url_rev_and_auth)
r3r<�scheme�netlocr��query�fragment�initial_slashes�newpath�
after_plusr&�	user_passr6s
            �rr�zGit.get_url_rev_and_auth�s*���19��
�-����e�X��?�?�6�"�"�#;�c�$�+�+�c�*:�&;�%;�<�O�%����(C�(C�D�(I�(Q�(Q��c�)��f�S�k��G� ���S�)�A�-�J���*�%�
��
��$�f�g�u�h�G�)��C�����#�%�%�%��+�+�f�l�3�C�"'�'�">�s�"C��C��i��+�+�h��+�C�"'�'�">�s�"C��C��i��C��"�"rc���gd�}|dkr|jd�tjjtjj	|d��sy|j||��y)N)�	submoduler�z--initz--recursiverrPz.gitmodulesrr)r�r.r�r�r�r2)r3rXr��argvs    rr�zGit.update_submodulessS��?����>��K�K����w�w�~�~�b�g�g�l�l�8�]�C�D�������	�	
rc���t�|�|�}|r|S	|jddg|dddd��}tjj|jd��S#t$rtjd|�Yyt$rYywxYw)	Nr�z--show-toplevelFT�raise)rTrErFr^r�zKcould not determine if %s is under git control because git is not availablez
)r1�get_repository_rootr2rrJr�rr.r��normpathrd)r3rX�loc�rr6s    �rr�zGit.get_repository_roots�����g�)�(�3����J�	�����/�0��!� �%�$�
 ��A�"�w�w������� 0�1�1���	��L�L�/��
�
� �	��	�s�A�B	�>B	�B	c��y)zEIn either https or ssh form, requirements must be prefixed with git+.Tr$)�repo_urls r�should_add_vcs_url_prefixzGit.should_add_vcs_url_prefix5s��r)r&�str�returnz	list[str])r4rr5rr�r�)r<r�r=r�r�r)r�ztuple[int, ...])rXr�r��
str | None)r=r�r&r�r�ztuple[str | None, bool])r=r�r&r�r�r)r=r�r<rr?rr�r)r=r�r|r�r�r)
r=r�r<rr?rr�rLr��None)r)rXr�r�r�)r<r�r�r�)rXr�r&r�r�rr)rXr�r&r�r�r�)r<r�r�z tuple[str, str | None, AuthInfo])rXr�r�rLr�r�)r�r�r�r)!�__name__�
__module__�__qualname__r|�dirname�	repo_name�schemes�
unset_environ�default_arg_rev�staticmethodr'�classmethodr2rArNr[r:rnrzr9r�r�r�r�r�rmrxr�r�r�r�r��
__classcell__)r6s@rrr>s3����D��G��I��G�1�M��O������4��4�$�:�����0�+��+�Z����,�+��+�'�+�6@�+�	�+��+�Z�.��.�=:��=:�(�=:�7A�=:�NQ�=:�	
�=:�H�:��:��:� �	:�
�:�
�
:�6�:��:��:� �	:�
�:�
�
:�<�7��7�:�'��'�<�
��
��	#��	#��M��M�"�#��#�<�
��
��2��2�0���rr)rr�r�r)-�
__future__r�logging�os.pathr.r�r��urllib.parser��urllib.request�dataclassesr�typingr�pip._internal.exceptionsrr�pip._internal.utils.miscrr	r
�pip._internal.utils.subprocessr� pip._internal.vcs.versioncontrolrr
rrrrr�parser�r��	getLoggerr�rJ�compilerIr�VERBOSEr�rr�registerr$rr�<module>r�s���"����	�����B�G�G�7�����<�<� � ��
�\�\�
$�
$�
�
��	�	�8�	$���B�J�J�����R�Z�Z�+�
,�
�
�B�J�J�		��J�J�
�	�'�z�.�z�z
����S�r