ó
heż[c           @   sŪ   d  d l  Z  d  d l m Z m Z e j j d d d g  d  d l m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z y0 d  d	 l m Z m Z m Z d  d
 l m Z Wn e k
 rŗ n Xd Z d e f d     YZ d S(   i’’’’N(   t   demandimportt   errors   bzrlib.transactionss   bzrlib.urlutilst   ElementPath(   t   _(   R   (   t   NoRepot   committ   converter_source(   t   bzrdirt   revisiont   errors(   t   RevisionSpect   filet   symlinkt
   bzr_sourcec           B   s   e  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(   s>   Reads Bazaar repositories by using the Bazaar Python librariesc         C   s  t  t |   j | | d | t j j t j j | d   sY t t d  |   n  y t	 Wn1 t
 k
 r t t d  t d  d   n Xt j j |  } |  j |  y t	 j j |  j   |  _ Wn* t j k
 r’ t t d  |   n Xi  |  _ d  S(   Nt   revss   .bzrs)   %s does not look like a Bazaar repositorys"   Bazaar modules could not be loadeds     (try installing the %s package)t   bzr(   t   superR   t   __init__t   ost   patht   existst   joinR   R   R   t	   NameErrort   abspatht   _checkrepotypet   BzrDirt   opent   open_repositoryt
   sourcerepoR	   t   NoRepositoryPresentt
   _parentids(   t   selft   uiR   R   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyR   $   s"    !c         C   sģ   y¾ d d l  m } | j j |  d } y | j d t  } | j } Wn/ t j t j	 f k
 ry d  } | j   } n X| d  k	 r½ | j j j | j j j k r½ |  j j t d   n  Wn' t k
 rē |  j j t d   n Xd  S(   Ni’’’’(   R   i    t   recommend_upgradesa   warning: lightweight checkouts may cause conversion failures, try with a regular branch instead.
s(   bzr source type could not be determined
(   t   bzrlibR   R   t   open_containingt   open_workingtreet   Falset   branchR	   t   NoWorkingTreet   NotLocalUrlt   Nonet   open_brancht   root_transportt   baseR    t   warnR   t	   Exceptiont   note(   R   R   R   t   dirt   treeR&   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyR   ;   s    c         C   s   |  j  j   d S(   s  Before the conversion begins, acquire a read lock
        for all the operations that might need it. Fortunately
        read locks don't block other reads or writes to the
        repository, so this shouldn't have any impact on the usage of
        the source repository.

        The alternative would be locking on every operation that
        needs locks (there are currently two: getting the file and
        getting the parent map) and releasing immediately after,
        but this approach can take even 40% longer.N(   R   t	   lock_read(   R   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   beforeO   s    c         C   s   |  j  j   d  S(   N(   R   t   unlock(   R   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   after\   s    c         C   s   |  j  j d t  S(   Nt   using(   R   t   find_branchest   True(   R   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   _bzrbranches_   s    c         C   sž   |  j  s7 t g  |  j   D] } | j   ^ q  } n d  } x] |  j   D]O } y) t j |  j  d  } | j |  } Wn t j	 k
 r n X| j
 } qJ W| d  k rĢ t j t d  |  j  d   n  | g } g  | D] } | d k rÜ | ^ qÜ } | S(   Ni    s   %s is not a valid revisions   null:(   R   t   sortedR9   t   last_revisionR)   R
   t   from_stringt
   in_historyR	   t   BzrErrort   rev_idR   t   AbortR   (   R   t   bt   headst   revidR&   t   rt   infot   h(    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   getheadsb   s     	.	%c   	      C   sš   |  j  j |  } | j | j |  j p* d   } d  } | d  k	 rW | j |  } n  | t k rg d S|  j | | f } | d k rĶ | j	 |  } | d  k rĆ t
 j t d  | | f   n  | | f S| j |  } | j   | f Sd  S(   Ns   utf-8R   s   %s.%s symlink has no target(   NN(   R   t   revision_treet   path2idt   decodet   encodingR)   t   kindt   supportedkindst
   _modecachet   get_symlink_targetR   R@   R   t   get_filet   read(	   R   t   namet   revt   revtreet   fileidRL   t   modet   targett   sio(    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   getfilew   s     !
c         C   s   | r t  j t d    n  i  |  _ |  j j |  |  _ |  j j |  } |  j j | d  } |  j	 |  j |  \ } } | | t
   f S(   Ns(   convert from cvs does not support --fulli    (   R   R@   R   RN   R   RH   t   _revtreeR   t   popt   _gettreechangest   set(   R   t   versiont   fullt	   parentidst   prevtreet   filest   changes(    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt
   getchanges   s    	c         C   sŻ   |  j  j |  } | j s7 g  } t j f |  j | <n |  j | j  } | |  j | <|  j | j j	 d d   } | d k r d } n  t
 d | d d | j | j f d |  j | j  d	 |  j | j  d
 | d |  S(   Ns   branch-nicku   defaultt   trunkt   defaultt   parentst   dates   %d %dt   authort   descR&   RS   (   R   t   get_revisiont
   parent_idsR   t   NULL_REVISIONR   t   _filterghostst   recodet
   propertiest   getR   t	   timestampt   timezonet	   committert   message(   R   R^   RS   Rg   R&   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt	   getcommit   s    		c         C   sp   i  } xc |  j    D]U } | j   s) i  S| j j   } x- | j   D] \ } } | | |  j |  <qE Wq W| S(   N(   R9   t   supports_tagst   tagst   get_tag_dictt	   iteritemsRo   (   R   t   bytetagsR&   t   tagdictRR   RS   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   gettags«   s    c         C   s   i  |  _  |  j j |  } | d  k	 r; |  j | | } n	 t j } |  j j |  } g  |  j | |  d D] } | d ^ qm } | S(   Ni    (   RN   R   RH   R)   R   R   Rm   R\   (   R   RS   t   it   curtreet   parentidRa   t   eRc   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   getchangedfilesµ   s    		-c      	   C   sX  | j  } g  } i  } t   } t | j |  d d   d t } x	| D]\ } }	 }
 } } } } } |	 d d k sI |	 d d k r qI n  | d d k r%| d d k rŠ | j |  j |	 d  | f  n  | d d k rI d  |	 k rI |	 d |	 d k } | j j	 |	 d  } x| j j
 |  D]ļ \ } } | j d k rJq)n  |  j |	 d d |  } | | k rwq)n  | j |  | sq)n  |  j |	 d d |  } | j | | f  | j | | f  | j rąd	 pų| j d
 k rõd pųd } | |  j | | f <| | | <q)WqI qI n  |	 \ } } | d  k	 rO|  j |  } n  | d  k	 rm|  j |  } n  | j | p||  | d  k r„| j | | f  qI n  | r×| | k r×| | | <| j | | f  n  g  | | f D] } | d ^ qä\ } } | rd	 p!| d
 k rd p!d } | |  j | | f <| j | | f  qI W| | f S(   Nt   keyc         S   s   |  d d p |  d d S(   Ni   i    (    (   t   c(    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   <lambda>Ź   s    t   reversei    u    i   t	   directoryt   /t   xR   t   st    t   l(   NR   (   t   _revision_idR]   R:   t   iter_changesR8   R)   t   appendRo   t	   inventoryRI   t   iter_entriesRL   t   addt
   executableRN   (   R   t   currentt   originRC   Rc   t   renamest   seent
   curchangesRU   t   pathst   changed_contentt	   versionedt   parentRR   RL   R   t   renamingt   subdirt   entryt   frompatht   topathRV   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyR\   Ā   sj    				" #
)c         C   sA   |  j  j |  } t g  | D] } | | k r | ^ q  } | S(   sq   Filters out ghost revisions which hg does not support, see
        <http://bazaar-vcs.org/GhostRevision>
        (   R   t   get_parent_mapt   tuple(   R   t   idst	   parentmapR   Rg   (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyRn     s    +N(   t   __name__t
   __module__t   __doc__R)   R   R   R3   R5   R9   RG   RY   Rd   Rv   R}   R   R\   Rn   (    (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyR   !   s   									
		X(   s   files   symlink(   R   t	   mercurialR    R   t   ignoret   extendt   mercurial.i18nR   t   commonR   R   R   R"   R   R   R	   t   bzrlib.revisionspecR
   t   ImportErrorRM   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/hgext/convert/bzr.pyt   <module>   s   	
