
he[c           @   sZ  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 m
 Z
 m Z d  d l m Z e
 j Z d   Z d   Z d e f d     YZ d e d d  Z d	 e f d
     YZ d Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d S(   iN(   t   phasest   utilt   error(   t   _c         C   s"   d   } t  j |   } | |  S(   Nc         S   s?   t  j |   } g  | D] } | j   d ^ q } d j |  S(   Ni    t    (   t   base64t   encodestringt
   splitlinest   join(   t   st   linest   l(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   encodearg   s    #(   t   picklet   dumps(   t   argsR   R	   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   encodeargs   s    	c         C   s   t  j |   }  t j |   S(   N(   R   t   decodestringR   t   loads(   R	   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   decodeargs   s    t   MissingToolc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR      s   c         C   sj   | p	 |  } t  j |   sf | r- t j } n t } | t d  | | rY t d  | p\ d   n  d  S(   Ns   cannot find required "%s" tools     (try installing the %s package)R   (   R   t   findexeR   t   AbortR   R   (   t   exet   namet   abortt   debnamet   exc(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   checktool   s    t   NoRepoc           B   s   e  Z RS(    (   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR   )   s   t   SKIPt   commitc           B   s&   e  Z d d i  d e e j d   Z RS(   c         C   sj   | p	 d |  _  | p d |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _	 d  S(   Nt   unknowns   0 0(
   t   authort   datet   desct   parentst   brancht   revt   extrat   sortkeyt   saverevt   phase(   t   selfR#   R$   R%   R&   R'   R(   R)   R*   R+   R,   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   __init__/   s    							N(   R   R   t   Nonet   TrueR    t   draftR.   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR!   .   s   t   converter_sourcec           B   s   e  Z d  Z d d 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 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z RS(   s   Conversion source interfacec         C   s(   | |  _  | |  _ | |  _ d |  _ d S(   sm   Initialize conversion source (or raise NoRepo("message")
        exception if path is not a valid repository)s   utf-8N(   t   uit   patht   revst   encoding(   R-   R3   R4   R5   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR.   ?   s    			t	   splicemapc         C   s8   t  j d |  s4 t j t d  | | f   n  d S(   s    fails if revstr is not a 40 byte hex. mercurial and git both uses
            such format for their revision numbering
        s   [0-9a-fA-F]{40,40}$s.   %s entry %s is not a valid revision identifierN(   t   ret   matchR   R   R   (   R-   t   revstrt   mapname(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   checkhexformatH   s    c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   beforeP   s    c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   afterS   s    c         C   s   t  S(   s   Returns true if the given targetfile belongs to the source repo. This
        is useful when only a subdirectory of the target belongs to the source
        repo.(   R0   (   R-   t   targetfilename(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   targetfilebelongstosourceV   s    c         C   s   d S(   s*   set the map of already-converted revisionsN(    (   R-   t   revmap(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   setrevmap]   s    c         C   s
   t   d S(   s(   Return a list of this repository's headsN(   t   NotImplementedError(   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   getheadsa   s    c         C   s
   t   d S(   s   Return a pair (data, mode) where data is the file content
        as a string and mode one of '', 'x' or 'l'. rev is the
        identifier returned by a previous call to getchanges().
        Data is None if file is missing/deleted in rev.
        N(   RC   (   R-   R   R(   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   getfilee   s    c         C   s
   t   d S(   sD  Returns a tuple of (files, copies, cleanp2).

        files is a sorted list of (filename, id) tuples for all files
        changed between version and its first parent returned by
        getcommit(). If full, all files in that revision is returned.
        id is the source revision id of the file.

        copies is a dictionary of dest: source

        cleanp2 is the set of files filenames that are clean against p2.
        (Files that are clean against p1 are already not in files (unless
        full). This makes it possible to handle p2 clean files similarly.)
        N(   RC   (   R-   t   versiont   full(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   getchangesm   s    c         C   s
   t   d S(   s$   Return the commit object for versionN(   RC   (   R-   RF   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   getcommit}   s    c         C   s   d S(   sW   Return the number of commits in this source.

        If unknown, return None.
        N(   R/   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   numcommits   s    c         C   s
   t   d S(   sd   Return the tags as a dictionary of name: revision

        Tag names must be UTF-8 strings.
        N(   RC   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   gettags   s    c         C   s   | s |  j  p d } n  t | t  r4 | j d  Sy | j |  j d  SWnU t k
 r y | j d  j d  SWq t k
 r | j | d  j d  SXn Xd  S(   Ns   utf-8s   latin-1t   replace(   R6   t
   isinstancet   unicodet   encodet   decodet   UnicodeError(   R-   R	   R6   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   recode   s    c         C   s
   t   d S(   sJ  Return the files changed by rev compared to parent[i].

        i is an index selecting one of the parents of rev.  The return
        value should be the list of files that are different in rev and
        this parent.

        If rev has no parents, i is None.

        This function is only needed to support --filemap
        N(   RC   (   R-   R(   t   i(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   getchangedfiles   s    c         C   s   d S(   s5   Notify the source that a revision has been converted.N(    (   R-   R(   t   sinkrev(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   converted   s    c         C   s   t  S(   s   Return true if this source has a meaningful, native revision
        order. For instance, Mercurial revisions are store sequentially
        while there is no such global ordering with Darcs.
        (   t   False(   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   hasnativeorder   s    c         C   s   t  S(   s@   Return true if this source has ability to close branch.
        (   RW   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   hasnativeclose   s    c         C   s   d S(   s   If rev is a meaningful revision reference in source, return
        the referenced identifier in the same format used by getcommit().
        return None otherwise.
        N(   R/   (   R-   R(   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   lookuprev   s    c         C   s   i  S(   sp   Return the bookmarks as a dictionary of name: revision

        Bookmark names are to be UTF-8 strings.
        (    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   getbookmarks   s    c         C   s   t  S(   s   revstr is a string that describes a revision in the given
           source control system.  Return true if revstr has correct
           format.
        (   R0   (   R-   R:   R;   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   checkrevformat   s    N(   R   R   t   __doc__R/   R.   R<   R=   R>   R@   RB   RD   RE   RH   RI   RJ   RK   RR   RT   RV   RX   RY   RZ   R[   R\   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR2   <   s*   																	t   converter_sinkc           B   sz   e  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 d   Z RS(   s"   Conversion sink (target) interfacec         C   s   | |  _  | |  _ g  |  _ d S(   s   Initialize conversion sink (or raise NoRepo("message")
        exception if path is not a valid repository)

        created is a list of paths to remove if a fatal error occurs
        laterN(   R3   R4   t   created(   R-   R3   R4   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR.      s    		c         C   s
   t   d S(   s   Path to a file that will contain lines
        source_rev_id sink_rev_id
        mapping equivalent revision identifiers for each system.N(   RC   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   revmapfile   s    c         C   s   d S(   s   Path to a file that will contain lines
        srcauthor=dstauthor
        mapping equivalent authors identifiers for each system.N(   R/   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt
   authorfile   s    c	   	      C   s
   t   d S(   s  Create a revision with all changed files listed in 'files'
        and having listed parents. 'commit' is a commit object
        containing at a minimum the author, date, and message for this
        changeset.  'files' is a list of (path, version) tuples,
        'copies' is a dictionary mapping destinations to sources,
        'source' is the source repository, and 'revmap' is a mapfile
        of source revisions to converted revisions. Only getfile() and
        lookuprev() should be called on 'source'. 'full' means that 'files'
        is complete and all other files should be removed.
        'cleanp2' is a set of the filenames that are unchanged from p2
        (only in the common merge case where there two parents).

        Note that the sink repository is not told to update itself to
        a particular revision (or even what that revision would be)
        before it receives the file data.
        N(   RC   (	   R-   t   filest   copiesR&   R!   t   sourceRA   RG   t   cleanp2(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   putcommit   s    c         C   s
   t   d S(   s   Put tags into sink.

        tags: {tagname: sink_rev_id, ...} where tagname is an UTF-8 string.
        Return a pair (tag_revision, tag_parent_revision), or (None, None)
        if nothing was changed.
        N(   RC   (   R-   t   tags(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   puttags   s    c         C   s   d S(   s   Set the current branch name. Called before the first putcommit
        on the branch.
        branch: branch name for subsequent commits
        pbranches: (converted parent revision, parent branch) tuplesN(    (   R-   R'   t	   pbranches(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   setbranch  s    c         C   s   d S(   s;  Tell the destination that we're using a filemap

        Some converter_sources (svn in particular) can claim that a file
        was changed in a revision, even if there was no change.  This method
        tells the destination that we're using a filemap and that it should
        filter empty revisions.
        N(    (   R-   t   active(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   setfilemapmode  s    c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR=     s    c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR>     s    c         C   s   d S(   s   Put bookmarks into sink.

        bookmarks: {bookmarkname: sink_rev_id, ...}
        where bookmarkname is an UTF-8 string.
        N(    (   R-   t	   bookmarks(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   putbookmarks  s    c         C   s
   t   d S(   sP   Return False if a rev mentioned in a filemap is known to not be
        present.N(   RC   (   R-   R(   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   hascommitfrommap$  s    c         C   s
   t   d S(   s   This method is for the special needs for splicemap handling and not
        for general use. Returns True if the sink contains rev, aborts on some
        special cases.N(   RC   (   R-   R(   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   hascommitforsplicemap)  s    (   R   R   R]   R.   R`   Ra   Rf   Rh   Rj   Rl   R=   R>   Rn   Ro   Rp   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR^      s   	
							
				t   commandlinec           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
 d  Z d   Z d   Z e d    Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R3   t   command(   R-   R3   Rr   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR.   0  s    	c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   prerun4  s    c         C   s   d  S(   N(    (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   postrun7  s    c         O   s"  |  j  | g t |  } x | j   D] \ } } t |  d k rX | j d |  n | j d | j d d   y> t |  d k r | j d |  n | d c d | 7<Wq& t k
 r q& Xq& Wg  | D] } t j |  ^ q } |  j	 j
 s| d t j g 7} n  d	 j |  } | S(
   Ni   t   -s   --R   R   it   =s   2>t    (   Rr   t   listt	   iteritemst   lent   appendRL   t	   TypeErrorR   t
   shellquoteR3   t	   debugflagt   ost   devnullR   (   R-   t   cmdR   t   kwargst   cmdlinet   kt   vt   arg(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   _cmdline:  s     "c         O   s   d   } |  j  | | | |  S(   Nc      
   S   s1   t  j |  d t d d d t j d t  j } | S(   Nt   shellt   bufsizeit	   close_fdst   stdout(   t
   subprocesst   PopenR0   R   t   closefdst   PIPE(   R   t   p(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   popenO  s    	(   t   _dorun(   R-   R   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   _runN  s    	c         O   s   |  j  t j | | |  S(   N(   R   R   t   popen2(   R-   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   _run2V  s    c         O   s   |  j  t j | | |  S(   N(   R   R   t   popen3(   R-   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   _run3Y  s    c         O   sV   |  j  | | |  } |  j j d | f  |  j   z | |  SWd  |  j   Xd  S(   Ns   running: %s
(   R   R3   t   debugRs   Rt   (   R-   t   openfuncR   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR   \  s    
c         O   sB   |  j  | | |  } | j   d } |  j j |  | | j f S(   Ni    (   R   t   communicateR3   R   t
   returncode(   R-   R   R   R   R   t   output(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   rune  s    c         O   sT   |  j  | | |  } | j j   } | j   |  j j d j |   | | j f S(   NR   (   R   R   t	   readlinest   waitR3   R   R   R   (   R-   R   R   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   runlinesk  s
    
R   c         C   sr   | rn | r< |  j  j t d  |  j  |  j  j |  n  t j |  d } t j d |  j | f   n  d  S(   Ns
   %s error:
i    s   %s %s(   R3   t   warnR   Rr   R   t   explainexitR   R   (   R-   t   statusR   t   msg(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   checkexitr  s    c         O   s/   |  j  | | |  \ } } |  j | |  | S(   N(   R   R   (   R-   R   R   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   run0z  s    c         O   s8   |  j  | | |  \ } } |  j | d j |   | S(   NR   (   R   R   R   (   R-   R   R   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt	   runlines0  s    c         C   s?   d } y t  j d  } Wn t t f k
 r2 n X| d d S(   Ni   t
   SC_ARG_MAXi   i   (   R   t   sysconft   AttributeErrort
   ValueError(   R-   t   argmax(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR     s    	c         o   s   t  |  j | | |   } |  j | } d } g  } xn | D]f }	 t  |	  d }
 | |
 | k  ss t  |  d k r | j |	  | |
 7} q; | V|	 g } |
 } q; W| r | Vn  d  S(   Ni    i   (   Rz   R   R   R{   (   R-   t   arglistR   R   R   t   cmdlent   limitt   bytest   flt   fnt   b(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   _limit_arglist  s    "	
c         O   sD   x= |  j  | | | |  D]# } |  j | t |  | |  q Wd  S(   N(   R   R   Rx   (   R-   R   R   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   xargs  s    (   R   R   R.   Rs   Rt   R   R   R   R   R   R   R   R   R   R   t   propertycacheR   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyRq   /  s    														t   mapfilec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   sE   t  t |   j   | |  _ | |  _ d  |  _ g  |  _ |  j   d  S(   N(	   t   superR   R.   R3   R4   R/   t   fpt   ordert   _read(   R-   R3   R4   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR.     s    				c         C   s-  |  j  s d  Sy t |  j  d  } Wn, t k
 rQ } | j t j k rM   n  d  SXx t |  D] \ } } | j   d j   } | s q_ n  y | j d d  \ } } Wn7 t	 k
 r t
 j t d  |  j  | d f   n X| |  k r|  j j |  n  t t |   j | |  q_ W| j   d  S(   Nt   ri    Rw   i   s/   syntax error in %s(%d): key/value pair expected(   R4   t   opent   IOErrort   errnot   ENOENTt	   enumerateR   t   rstript   rsplitR   R   R   R   R   R{   R   R   t   __setitem__t   close(   R-   R   t   errRS   t   linet   keyt   value(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR     s,    		c         C   s   |  j  d  k rf y t |  j d  |  _  Wqf t k
 rb } t j t d  |  j | j f   qf Xn  |  j  j	 d | | f  |  j  j
   t t |   j | |  d  S(   Nt   as   could not open map file %r: %ss   %s %s
(   R   R/   R   R4   R   R   R   R   t   strerrort   writet   flushR   R   R   (   R-   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR     s    c         C   s&   |  j  r" |  j  j   d  |  _  n  d  S(   N(   R   R   R/   (   R-   (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR     s    	(   R   R   R.   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyR     s   			c         C   s@   t  j  j |   t  j  j |   } | j d | j } |  | f S(   s;   Like util.makedate() but for time t instead of current timeiQ (   t   datetimet   utcfromtimestampt   fromtimestampt   dayst   seconds(   t   tt   deltat   tz(    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   makedatetimestamp  s    (    R   R   R   R   R   R8   t   cPickleR   t	   mercurialR    R   R   t   mercurial.i18nR   R   R   R   t	   ExceptionR   R/   R0   R   R   t   SKIPREVt   objectR!   R2   R^   Rq   t   dictR   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/hgext/convert/common.pyt   <module>   s    H				
`|2