
    q&f                         d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ i Z e
j                  e      ZdZ ej"                  d      Z G d d	      Zd
 ZddddddZdeddfdZd Z edd      d        Zy)a'  extend schemes with shortcuts to repository swarms

This extension allows you to specify shortcuts for parent URLs with a
lot of repositories to act like a scheme, for example::

  [schemes]
  py = http://code.python.org/hg/

After that you can use it like::

  hg clone py://trunk/

Additionally there is support for some more complex schemas, for
example used by Google Code::

  [schemes]
  gcode = http://{1}.googlecode.com/hg/

The syntax is taken from Mercurial templates, and you have unlimited
number of variables, starting with ``{1}`` and continuing with
``{2}``, ``{3}`` and so on. This variables will receive parts of URL
supplied, split by ``/``. Anything not specified as ``{part}`` will be
just appended to an URL.

For convenience, the extension adds these schemes by default::

  [schemes]
  py = http://hg.python.org/
  bb = https://bitbucket.org/
  bb+ssh = ssh://hg@bitbucket.org/
  gcode = https://{1}.googlecode.com/hg/
  kiln = https://{1}.kilnhg.com/Repo/

You can override a predefined scheme by defining a new scheme with the
same name.
    N)_)error
extensionshgpycompat	registrar	templater)urlutils   ships-with-hg-cores   {(\d+)\}c                   ,    e Zd Zd Zd Zd ZddZd Zy)ShortRepositoryc                     || _         || _        || _        	 t        t	        t
        t        j                  | j                                    | _        y # t        $ r
 d| _        Y y w xY w)Nr   )
schemer	   urlmaxmapint_partrefindallparts
ValueError)selfr   r   r	   s       //usr/lib/python3/dist-packages/hgext/schemes.py__init__zShortRepository.__init__G   sR    "	Sgoodhh&?@ADJ 	DJ	s   ;A A&%A&c                      d| j                   z  S )Ns   <ShortRepository: %s>)r   )r   s    r   __repr__zShortRepository.__repr__P   s    '$++55    c                     | j                  |j                        }|j                  |      }t        j                  j                  |j                  j                        }| |j                  ||g|i |S y )N)new_raw_location)	resolverawloccopyr   peer_schemesgetr   r   	make_peer)r   uipathargskwargsnew_urlclss          r   r$   zShortRepository.make_peerS   se    ,,t{{+yy'y2oo!!$((//2? 3==T;D;F;;r   Nc                 R   | j                  |      }t        j                  |      }|j                  xs d}|t        j
                  v rt        j
                  |   }n6|t        j                  v rt        j                  |   }nt        j                  }|j                  |||||      S )Ns   file)intents
createopts)	r   r
   r   r   r   r"   repo_schemesLocalFactoryinstance)	r   r%   r   creater,   r-   ur   r*   s	            r   r0   zShortRepository.instance[   s    ll3KK$WR__$//&)Cr&//&)C//C||VW  
 	
r   c                    	 |j                  dd      d   }|j                  d| j
                        }t        |      | j
                  kD  r|d   }|d d }nd}t        |      D ci c]  \  }}d|dz   z  | }}}dj                  | j                  j                  | j                  |            |z   S # t        $ r" t        j                  t	        d      |z        w xY wc c}}w )Ns   ://   s   no '://' in scheme url '%s'   /r   s   %d)split
IndexErrorr   Abortr   r   len	enumeratejoinr	   processr   )r   r   r   tailivcontexts          r   r   zShortRepository.resolvei   s    	G))FA&q)C 		$

+u:

"9D#2JED2;E2BC$!Q5AE?A%CCxx..txxABTII  	G++a >?#EFF	G Ds   B4 &C"4+C)NN)__name__
__module____qualname__r   r   r$   r0   r    r   r   r   r   F   s    6
Jr   r   c                 X    |r!t         D ]  }|j                  |dz         s y  | |      S )N   :F)schemes
startswith)origr&   r   s      r   hasdriveletterrK   y   s3     	Fv}-	 :r   s   http://hg.python.org/s   https://bitbucket.org/s   ssh://hg@bitbucket.org/s   https://{1}.googlecode.com/hg/s   https://{1}.kilnhg.com/Repo/)s   pys   bbs   bb+sshs   gcodes   kilnr   returnc                    t         j                  rxt        |       dk(  ri| j                         rXt        j
                  j                  d| z        r5t        d      }|| | j                         fz  }t        j                  |      yyyy)z6check if a scheme conflict with a Windows drive letterr4   s   %s:\s5   custom scheme %s:// conflicts with drive letter %s:\
N)r   	iswindowsr:   isalphaosr&   existsr   upperr   r9   )r   msgs     r   _check_drive_letterrT      s{     	K1NNGGNN8f,-JK''kk#	 .   	r   c                    t         j                  t        | j                  d                   t	        j
                  t        j                        }t         j                         D ]~  \  }}t        |       t        j                  |      j                  }|t        j                  v rt        |||      t        j                  |<   at        |||      t        j                  |<    t!        j"                  t        dt$               y )Ns   schemesrK   )rH   updatedictconfigitemsr	   engineparseitemsrT   r
   r   r   r   r"   r   r.   r   wrapfunctionrK   )r%   tr   r   
url_schemes        r   extsetupr_      s    NN4z234)A}} FF#[[%,,
(&5c61&EBOOF#&5c61&EBOOF#F G%5~Fr   s   debugexpandschemeT)norepoc                 :   t        j                  |      j                  }|t        j                  v rt        j                  |   }nt        j
                  j                  |      }|!t        |t              r|j                  |      }| j                  |dz          y)z3given a repo path, provide the scheme-expanded pathN   
)r
   r   r   r   r"   r.   r#   
isinstancer   r   write)r%   r   optsr   r*   s        r   expandschemerf      sr     [[$$F oof%oo!!&)
:c?;kk#HHS5[r   )__doc__rP   remercurial.i18nr   	mercurialr   r   r   r   r   r	   mercurial.utilsr
   cmdtablecommand
testedwithcompiler   r   rK   rH   bytesrT   r_   rf   rE   r   r   <module>rq      s   #J 
 	   
)

H
%
 #

"**\
"0J 0Jf $$)/,
 
$ 
G 		d+	 ,	r   