σ
©9Vc           @@  sΘ   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z
 d  d l m Z m Z d  d l m Z m Z e j Z e j Z e j e  Z d e f d     YZ e j e  d S(	   i    (   t   absolute_importN(   t   parse(   t   request(   t   display_patht   rmtree(   t   vcst   VersionControlt   Gitc           B@  s   e  Z d  Z d Z d Z d Z d d  Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   t   gits   .gitt   clones   git+https	   git+httpss   git+sshs   git+gits   git+filec         O@  sν   | rΝ t  |  \ } } } } } | j d  rΝ | t | j d    }	 |	 t j |  j d d  j d  }
 t | | |
 | | f  } | j d  d } | |  t | | | |
 | | f  } qΝ n  t	 t
 |   j | | |  d  S(   Nt   filet   /s   \t   +i   (   t   urlsplitt   endswitht   lent   lstript   urllib_requestt   url2pathnamet   replacet
   urlunsplitt   findt   superR   t   __init__(   t   selft   urlt   argst   kwargst   schemet   netloct   patht   queryt   fragmentt   initial_slashest   newpatht
   after_plus(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyR      s    
#c         C@  sy   t  j d d  } |  j |  zH | j d  s> | d } n  |  j d d d d | g d t d	 | Wd
 t |  Xd
 S(   s@   Export the Git repository at the url to the destination locations   -exports   pip-R   s   checkout-indexs   -as   -fs   --prefixt   show_stdoutt   cwdN(   t   tempfilet   mkdtempt   unpackR   t   run_commandt   FalseR   (   R   t   locationt   temp_dir(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   export2   s    c         C@  s_   |  j  |  } d | } | | k r0 | | g S| | k rG | | g St j d |  | Sd S(   sΆ   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.
        s	   origin/%ss5   Could not find a tag or branch '%s', assuming commit.N(   t   get_refst   loggert   warning(   R   t   revt   destt   rev_optionst	   revisionst
   origin_rev(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   check_rev_options?   s    

c         C@  sJ   |  j  d d | g d | |  j  d d g | d | |  j |  d  S(   Nt   configs   remote.origin.urlR%   t   checkouts   -q(   R)   t   update_submodules(   R   R2   R   R3   (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   switchS   s    c         C@  sl   |  j  d d g d | | r; |  j | d | |  } n  |  j  d d d g | d | |  j |  d  S(   Nt   fetchs   -qR%   i    t   resets   --hard(   R)   R6   R9   (   R   R2   R3   (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   updateY   s     c         C@  sψ   |  j    \ } } | r. | g } d | } n d g } d } |  j | | | |  rτ t j d | | t |   |  j d d | | g  | rδ |  j | | |  } |  j |  j | d  sδ |  j d d g | d	 | qδ n  |  j	 |  n  d  S(
   Ns    (to %s)s   origin/mastert    s   Cloning %s%s to %sR	   s   -qi    R8   R%   (
   t   get_url_revt   check_destinationR/   t   infoR   R)   R6   t   get_revisiont
   startswithR9   (   R   R2   R   R1   R3   t   rev_display(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   obtaine   s"    		c         C@  s+   |  j  d d g d t d | } | j   S(   NR7   s   remote.origin.urlR$   R%   (   R)   R*   t   strip(   R   R+   R   (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   get_url~   s    c         C@  s+   |  j  d d g d t d | } | j   S(   Ns	   rev-parset   HEADR$   R%   (   R)   R*   RF   (   R   R+   t   current_rev(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyRB      s    c         C@  sτ   |  j  d g d t d | } i  } xΙ | j   j   D]΅ } | j d d  \ } } | j   } d	 } | j d  r | t d  } nD | j d  r« | t d  } n" | j d  rΝ | t d  } n  | d	 k	 r7 | j   | | <q7 q7 W| S(
   s=   Return map of named refs (branches or tags) to commit hashes.s   show-refR$   R%   t    i   s   refs/remotes/s   refs/heads/s
   refs/tags/N(   R)   R*   RF   t
   splitlinest   splitt   NoneRC   R   (   R   R+   t   outputt   rvt   linet   committ   reft   ref_name(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyR.      s     c         C@  s  |  j  |  } | j   j d  s1 d | } n  | j   j d d  d } | sW d  S|  j |  } |  j |  } i  } x9 t | j	    D]% \ }	 }
 |
 | k r |	 | |
 <q q W| | k rι | | } d | |  j
 |  f } n
 d | } d | | | f S(	   Ns   git:s   git+t   -i   i    s   %s-%ss   %s-devs   %s@%s#egg=%s(   RG   t   lowerRC   t   egg_nameRL   RM   RB   R.   t   sortedt   itemst   translate_egg_surname(   R   t   distR+   t	   find_tagst   repot   egg_project_nameRI   t   refst   names_by_commitRR   RQ   t   namet   full_egg_name(    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   get_src_requirement   s"    

c         C@  s   d |  j  k rl d |  j  k s$ t  |  j  j d d  |  _  t t |   j   \ } } | j d d  } n t t |   j   \ } } | | f S(   s;  
        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.
        s   ://s   file:s   git+s
   git+ssh://s   ssh://R>   (   R   t   AssertionErrorR   R   R   R?   (   R   R   R1   (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyR?   Έ   s    c         C@  sK   t  j j t  j j | d   s% d  S|  j d d d d d g d | d  S(   Ns   .gitmodulest	   submoduleR=   s   --inits   --recursives   -qR%   (   t   osR   t   existst   joinR)   (   R   R+   (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyR9   Ι   s
    !(   s   gits   git+https	   git+httpss   git+sshs   git+gits   git+fileN(   t   __name__t
   __module__R`   t   dirnamet	   repo_namet   schemesRM   R   R-   R6   R:   R=   RE   RG   RB   R.   Rb   R?   R9   (    (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyR      s    										(   t
   __future__R    t   loggingR&   t   os.pathRe   t   pip._vendor.six.moves.urllibR   t   urllib_parseR   R   t	   pip.utilsR   R   t   pip.vcsR   R   R   R   t	   getLoggerRh   R/   R   t   register(    (    (    s(   /tmp/pip-build-5Z5nTX/pip/pip/vcs/git.pyt   <module>   s   		Ό