Your IP : 18.216.92.5


Current Path : /usr/lib/python3.6/site-packages/pip/vcs/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/pip/vcs/__pycache__/git.cpython-36.pyc

3

�Pf,-�@s�ddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZddl
m
ZddlmZddlmZmZddlmZmZejZejZeje�ZGd	d
�d
e�Zeje�dS)�)�absolute_importN)�samefile)�
BadCommand)�parse)�request)�display_path�rmtree)�vcs�VersionControlcs�eZdZdZdZdZd7Zd8�fd
d�	Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd9dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd:d+d,�Zd-d.�Zd/d0�Z�fd1d2�Zd3d4�Ze�fd5d6��Z�ZS);�Git�gitz.git�clone�git+http�	git+https�git+ssh�git+git�git+fileNcs�|r�t|�\}}}}}|jd�r�|dt|jd���}	|	tj|�jdd�jd�}
t|||
||f�}|jd�d}|d|�t||d�||
||f�}t	t
|�j|f|�|�dS)N�file�/�\�+�)�urlsplit�endswith�len�lstrip�urllib_requestZurl2pathname�replace�
urlunsplit�find�superr�__init__)�self�url�args�kwargs�schemeZnetloc�pathZqueryZfragment�initial_slashes�newpathZ
after_plus)�	__class__��/usr/lib/python3.6/git.pyr! s

zGit.__init__cCsTd}|jdgdd�}|j|�r0|t|�d�}nd}dj|jd�dd��}t|�S)Nzgit version �versionF)�show_stdout��.�)�run_command�
startswithr�join�split�
parse_version)r"ZVERSION_PFXr-r+r+r,�get_git_version5s
zGit.get_git_versioncCsVtjdd�}|j|�z0|jd�s*|d}|jdddd|gd|d	�Wd
t|�Xd
S)z@Export the Git repository at the url to the destination locationz-exportzpip-rzcheckout-indexz-az-fz--prefixF)r.�cwdN)�tempfileZmkdtemp�unpackrr2r)r"�locationZtemp_dirr+r+r,�exportBs

z
Git.exportcCsL|j||�}d|}||kr&||gS||kr8||gStjd|�|SdS)z�Check the revision options before checkout to compensate that tags
        and branches may need origin/ as a prefix.
        Returns the SHA1 of the branch or tag if found.
        z	origin/%sz5Could not find a tag or branch '%s', assuming commit.N)�get_short_refs�logger�warning)r"�rev�dest�rev_optionsZ	revisionsZ
origin_revr+r+r,�check_rev_optionsOs

zGit.check_rev_optionscCs|j|�j|d�S)a

        Compare the current sha to the ref. ref may be a branch or tag name,
        but current rev will always point to a sha. This means that a branch
        or tag will never compare as True. So this ultimately only matches
        against exact shas.
        r)�get_revisionr3)r"rArBr+r+r,�
check_versioncszGit.check_versioncCs8|jdd|g|d�|jddg||d�|j|�dS)N�configzremote.origin.url)r8�checkoutz-q)r2�update_submodules)r"rAr#rBr+r+r,�switchlsz
Git.switchcCst|j�td�kr&|jdddg|d�n|jddg|d�|rN|j|d||�}|jdddg||d�|j|�dS)	Nz1.9.0Zfetchz-qz--tags)r8r�resetz--hard)r7r6r2rCrH)r"rArBr+r+r,�updatersz
Git.updatecCs�|j�\}}|r |g}d|}n
dg}d}|j||||�r�tjd||t|��|jdd||g�|r�|j|||�}|j||�s�|jddg||d�|j|�dS)	Nz (to %s)z
origin/masterr/zCloning %s%s to %sr
z-qrG)r8)	�get_url_revZcheck_destinationr>�inforr2rCrErH)r"rAr#r@rBZrev_displayr+r+r,�obtain�s"

z
Git.obtaincCsZ|jdddgd|d�}|j�}|d}x|D]}|jd�r,|}Pq,W|jd�d	}|j�S)
z+Return URL of the first remote encountered.rFz--get-regexpzremote\..*\.urlF)r.r8rzremote.origin.url � r)r2�
splitlinesr3r5�strip)r"r;ZremotesZfound_remoteZremoter#r+r+r,�get_url�s


zGit.get_urlcCs|jddgd|d�}|j�S)Nz	rev-parseZHEADF)r.r8)r2rQ)r"r;�current_revr+r+r,rD�szGit.get_revisionr/ccs�|jd|gd|d�}xl|jd�D]^}|jd�}|s4q y|jdd�\}}Wn"tk
rjtd|����YnX|j�|j�fVq Wd	S)
z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r.r8�
�
rOrzunexpected show-ref line: N)r2r5�rstrip�
ValueErrorrQ)r"r;�pattern�output�line�commit�refr+r+r,�
get_full_refs�s


zGit.get_full_refscCs
|jd�S)Nz
refs/remotes/)r3)r"r\r+r+r,�
is_ref_remote�szGit.is_ref_remotecCs
|jd�S)Nzrefs/heads/)r3)r"r\r+r+r,�
is_ref_branch�szGit.is_ref_branchcCs
|jd�S)Nz
refs/tags/)r3)r"r\r+r+r,�
is_ref_tag�szGit.is_ref_tagcCs"t|j|�|j|�|j|�f�S)z0A ref is a commit sha if it is not anything else)�anyr^r_r`)r"r\r+r+r,�
is_ref_commit�szGit.is_ref_commitcCs
|j|�S)N)r=)r"r;r+r+r,�get_refs�szGit.get_refscCs�i}x~|j||�D]n\}}d}|j|�r:|td�d�}n6|j|�rV|td�d�}n|j|�rp|td�d�}|dk	r|||<qW|S)z=Return map of named refs (branches or tags) to commit hashes.Nz
refs/remotes/zrefs/heads/z
refs/tags/)r]r^rr_r`)r"r;rX�rvr[r\Zref_namer+r+r,r=�s


zGit.get_short_refscCs�|jddgd|d�j�}tjj|�s2tjj||�}tjj|d�}|}xBtjjtjj|d��s�|}tjj|�}||krFtj	d|�dSqFWt
||�r�dStjj||�S)	z:Return the relative path of setup.py to the git repo root.z	rev-parsez	--git-dirF)r.r8z..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N)r2rQ�osr'�isabsr4�exists�dirnamer>r?r�relpath)r"r;Zgit_dirZroot_dirZ
orig_locationZ
last_locationr+r+r,�_get_subdirectory�s"

zGit._get_subdirectorycCsr|j|�}|j�jd�s d|}|j�jdd�d}|s<dS|j|�}d|||f}|j|�}|rn|d|7}|S)Nzgit:zgit+�-rrz%s@%s#egg=%sz&subdirectory=)rR�lowerr3Zegg_namer5rDrj)r"Zdistr;ZrepoZegg_project_namerSZreqZsubdirectoryr+r+r,�get_src_requirement�s


zGit.get_src_requirementcsbd|jkrHd|jkst�|jjdd�|_tt|�j�\}}|jdd�}ntt|�j�\}}||fS)a;
        Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
        That's required because although they use SSH they sometimes doesn'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.
        z://zfile:zgit+z
git+ssh://zssh://r/)r#�AssertionErrorrr rrL)r"r#r@)r*r+r,rLs
zGit.get_url_revcCs6tjjtjj|d��sdS|jdddddg|d�dS)Nz.gitmodulesZ	submodulerKz--initz--recursivez-q)r8)rer'rgr4r2)r"r;r+r+r,rHs
zGit.update_submodulescsVtt|�j|�rdSy|�jdg|ddd�}|Stk
rPtjd|�dSXdS)NTz	rev-parseF�ignore)r8r.Z
on_returncodezKcould not determine if %s is under git control because git is not available)r r�controls_locationr2rr>�debug)�clsr;�r)r*r+r,rp$s
zGit.controls_location)rrrrrr)N)r/)r/)�__name__�
__module__�__qualname__�namerhZ	repo_nameZschemesr!r7r<rCrErIrKrNrRrDr]r^r_r`rbrcr=rjrmrLrH�classmethodrp�
__classcell__r+r+)r*r,rs4

	
	
r)Z
__future__rZloggingr9Zos.pathreZ
pip.compatrZpip.exceptionsrZpip._vendor.six.moves.urllibrZurllib_parserrZpip._vendor.packaging.versionr6Z	pip.utilsrrZpip.vcsr	r
rrZ	getLoggerrtr>r�registerr+r+r+r,�<module>s"


?>