ó
'šMc           @   s³   d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z m Z e j Z e j Z d e	 f d „  ƒ  YZ e j e ƒ d S(	   iÿÿÿÿN(   t   call_subprocess(   t   display_patht   rmtree(   t   vcst   VersionControl(   t   logger(   t   url2pathnamet   urlparset   Gitc           B   s¤   e  Z d  Z d 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 d „  Z RS(   t   gits   .gitt   clones   git+https	   git+httpss   git+sshs   git+gits   git+files   git-clone.txtss   # This was a Git repo; to make it a repo again run:
git init
git remote add origin %(url)s -f
git checkout %(rev)s
c         O   sê   | rÊ t  | ƒ \ } } } } } | j d ƒ rÊ | t | j d ƒ ƒ  }	 |	 t | ƒ 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   lstripR   t   replacet
   urlunsplitt   findt   superR   t   __init__(   t   selft   urlt   argst   kwargst   schemet   netloct   patht   queryt   fragmentt   initial_slashest   newpatht
   after_plus(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyR      s    %-c         C   sÃ   d  } } x² | j ƒ  D]¤ } | j ƒ  s | j ƒ  j d ƒ rE q n  t j d | ƒ } | ru | j d ƒ j ƒ  } n  t j d | ƒ } | r¥ | j d ƒ j ƒ  } n  | r | r | | f Sq Wd S(   Nt   #s$   git\s*remote\s*add\s*origin(.*)\s*-fi   s   ^git\s*checkout\s*-q\s*(.*)\s*(   NN(   t   Nonet
   splitlinest   stript
   startswitht   ret   searcht   group(   R   t   contentR   t   revt   linet	   url_matcht	   rev_match(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   parse_vcs_bundle_file#   s    
"c         C   s…   t  j d d ƒ } |  j | ƒ zT | j d ƒ s> | d } n  t |  j d d d d | g d |  j 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   filter_stdoutt   show_stdoutt   cwdN(	   t   tempfilet   mkdtempt   unpackR   R    t   cmdt   _filtert   FalseR   (   R   t   locationt   temp_dir(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   export2   s    c         C   s’   |  j  | ƒ } | j |  j | ƒ ƒ t d „  | j ƒ  Dƒ ƒ } d | } | | k rb | | g S| | k ry | | 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.
        c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   kt   v(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pys	   <genexpr>F   s    s	   origin/%ss5   Could not find a tag or branch '%s', assuming commit.N(   t   get_tag_revst   updatet   get_branch_revst   dictt   itemsR   t   warn(   R   R,   t   destt   rev_optionst	   revisionst   inverse_revisionst
   origin_rev(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   check_rev_options?   s    
c         C   sC   t  |  j d d | g d | ƒt  |  j d d g | d | ƒd  S(   Nt   configs   remote.origin.urlR3   t   checkouts   -q(   R    R7   (   R   RF   R   RG   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   switchS   s    c         C   se   t  |  j d d g d | ƒ| r> |  j | d | | ƒ } n  t  |  j d d d g | d | ƒd  S(   Nt   fetchs   -qR3   i    t   resets   --hard(   R    R7   RK   (   R   RF   RG   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyRA   Y   s    c         C   sõ   |  j  ƒ  \ } } | r. | g } d | } n d g } d } |  j | | | | ƒ rñ t j d | | t | ƒ f ƒ t |  j d d | | g ƒ | rñ |  j | | | ƒ } |  j | ƒ j	 | d ƒ sî t |  j d d g | d	 | ƒqî qñ n  d  S(
   Ns    (to %s)s   origin/mastert    s   Cloning %s%s to %sR
   s   -qi    RM   R3   (
   t   get_url_revt   check_destinationR   t   notifyR   R    R7   RK   t   get_revisionR'   (   R   RF   R   R,   RG   t   rev_display(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   obtaina   s    		 c         C   s.   t  |  j d d g d t d | ƒ} | j ƒ  S(   NRL   s   remote.origin.urlR2   R3   (   R    R7   R9   R&   (   R   R:   R   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   get_urlr   s    c         C   s.   t  |  j d d g d t d | ƒ} | j ƒ  S(   Ns	   rev-parset   HEADR2   R3   (   R    R7   R9   R&   (   R   R:   t   current_rev(    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyRU   x   s    !c         C   s    t  |  j d d g d t d t d | ƒ} g  } x] | j ƒ  D]O } | j ƒ  } t  |  j d | g d t d | ƒ} | j | j ƒ  | f ƒ q= Wt | ƒ } | S(   Nt   tags   -lR2   t   raise_on_returncodeR3   s	   rev-parse(   R    R7   R9   R%   R&   t   appendRC   (   R   R:   t   tagst   tag_revsR-   R[   R,   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyR@   }   s    !c         C   sÛ   t  |  j d d g d t d | ƒ} g  } xž | j ƒ  D] } | j d ƒ d j ƒ  } d j g  | j ƒ  D] } | d k ri | ^ qi ƒ } t  |  j d	 | g d t d | ƒ} | j | j ƒ  | f ƒ q7 Wt | ƒ } | S(
   Nt   branchs   -rR2   R3   s   ->i    RQ   t   *s	   rev-parse(	   R    R7   R9   R%   t   splitR&   t   joinR]   RC   (   R   R:   t   branchest   branch_revsR-   t   bR`   R,   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyRB   Š   s    !4!c   
      C   s  |  j  | ƒ } | j ƒ  j d ƒ s1 d | } n  | j ƒ  j d d ƒ d } | sW d  S|  j | ƒ } |  j | ƒ } |  j | ƒ } | | k r§ d | | | f }	 nI | | k ræ | | d k ræ d | | | j	 d d	 ƒ f }	 n
 d
 | }	 d | | |	 f S(   Ns   git:s   git+t   -i   i    s   %s-%ss   origin/masters   origin/RQ   s   %s-devs   %s@%s#egg=%s(
   RX   t   lowerR'   t   egg_nameRb   R$   RU   R@   RB   R   (
   R   t   distR:   t	   find_tagst   repot   egg_project_nameRZ   R_   Re   t   full_egg_name(    (    s/   /usr/lib/python2.7/dist-packages/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://RQ   (   R   t   AssertionErrorR   R   R   RR   (   R   R   R,   (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyRR   ¯   s    (   R	   s   git+https	   git+httpss   git+sshs   git+gits   git+fileN(   t   __name__t
   __module__t   namet   dirnamet	   repo_namet   schemest   bundle_filet   guideR$   R   R0   R<   RK   RN   RA   RW   RX   RU   R@   RB   Ro   RR   (    (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyR      s&   											(   R4   R(   t   pipR    t   pip.utilR   R   t   pip.vcsR   R   t   pip.logR   t   pip.backwardcompatR   R   R   R   R   t   register(    (    (    s/   /usr/lib/python2.7/dist-packages/pip/vcs/git.pyt   <module>   s   		¶