
    cBE                        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 d dl	m
Z
 d dlmZmZmZmZmZ d dlmZ ej        Zd Z G d d          Zdd	Zd
 Zd Z G d de          ZddZ G d de          ZdZ G d d          Z G d d          Z G d d          Z  G d d          Z! G d de"          Z#d Z$dS )     N)_)open)encodingerrorphasespycompatutil)procutilc                 4    | d S |                      d          S )Nlatin1)encode)ds    6/usr/lib/python3/dist-packages/hgext/convert/common.py_encodeornoner      s    y88H    c                   L    e Zd Zd Zd Zd Zed             Zed             ZdS )_shlexpy3proxyc                     || _         d S N_l)selfls     r   __init__z_shlexpy3proxy.__init__%   s    r   c                 $    d | j         D             S )Nc              3   4   K   | ]}t          |          V  d S r   )r   ).0vs     r   	<genexpr>z*_shlexpy3proxy.__iter__.<locals>.<genexpr>)   s*      22Qa  222222r   r   r   s    r   __iter__z_shlexpy3proxy.__iter__(   s    22$'2222r   c                 N    t          | j                                                  S r   )r   r   	get_tokenr    s    r   r#   z_shlexpy3proxy.get_token+   s    TW..00111r   c                     | j         j        pdS )Ns	   <unknown>)r   infiler    s    r   r%   z_shlexpy3proxy.infile.   s    w~--r   c                     | j         j        S r   )r   linenor    s    r   r'   z_shlexpy3proxy.lineno2   s    w~r   N)	__name__
__module____qualname__r   r!   r#   propertyr%   r'    r   r   r   r   $   sw          3 3 32 2 2 . . X.   X  r   r   c                 p   | t          |dd          } n+|t          j        d          |                     d          } t	          j        | |d          }|*d|_        |xj        |                    d          z  c_        |#|xj        |                    d          z  c_        t          |          S )N   rr   )r   s/   shlexer only accepts data or filepath, not bothT)r%   posix)	r   r   ProgrammingErrordecodeshlexwhitespace_split
whitespace	wordcharsr   )datafilepathr5   r4   r   s        r   shlexerr8   7   s    |HdX666(B   {{8$$D666A!	
))(333	y''111!r   c                 F    d }t          j        |           } ||          S )Nc                     t          j        |           }d t          j        |          D             }d                    |          S )Nc                 B    g | ]}|                                 d          S )r   )
splitlines)r   r   s     r   
<listcomp>z1encodeargs.<locals>.encodearg.<locals>.<listcomp>L   s%    HHHq"HHHr   r   )base64encodebytesr   iterbytestrjoin)sliness     r   	encodeargzencodeargs.<locals>.encodeargJ   s@    "1%%HHH,@,G,GHHHxxr   )pickledumps)argsrD   rB   s      r   
encodeargsrH   I   s0      
 	TA9Q<<r   c                 R    t          j        |           } t          j        |           S r   )r>   decodebytesrE   loads)rB   s    r   
decodeargsrL   S   s     1A<??r   c                       e Zd ZdS )MissingToolNr(   r)   r*   r,   r   r   rN   rN   X           Dr   rN   Tc                     |p| }t          j        |           sH|rt          j        }nt          } |t          d          |z  |rt          d          |z  pdz             d S )Ns   cannot find required "%s" tools     (try installing the %s package)r   )r
   findexer   AbortrN   r   )exenameabortdebnameexcs        r   	checktoolrY   \   s    ;3DC   Y 	+CCCc!566=Oq!DEEOVSVX Y Y 	YY Yr   c                       e Zd ZdS )NoRepoNrO   r,   r   r   r[   r[   g   rP   r   r[   s   SKIPc                   0    e Zd Zdddddej        ddfdZdS )commitNTc                     |pd| _         |pd| _        || _        || _        |pg | _        || _        || _        |pi | _        || _        |	| _	        |
| _
        || _        d S )Ns   unknowns   0 0)authordatedescparents
optparentsbranchrevextrasortkeysaverevphasectx)r   r_   r`   ra   rb   rd   re   rf   rg   rh   ri   rc   rj   s                r   r   zcommit.__init__o   sn     *
NF		$*[b

r   )r(   r)   r*   r   draftr   r,   r   r   r]   r]   n   sD         l     r   r]   c                       e Zd ZdZ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dS )converter_sourcezConversion source interfaceNc                 L    || _         || _        || _        || _        d| _        dS )zmInitialize conversion source (or raise NoRepo("message")
        exception if path is not a valid repository)   utf-8N)uipathrevsrepotyper   )r   rp   rs   rq   rr   s        r   r   zconverter_source.__init__   s+     		  r   	   splicemapc                 |    t          j        d|          s&t          j        t	          d          ||fz            dS )z{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)rematchr   rS   r   r   revstrmapnames      r   checkhexformatzconverter_source.checkhexformat   sP     x/88 	+CDDF#$  	 	r   c                     d S r   r,   r    s    r   beforezconverter_source.before       r   c                     d S r   r,   r    s    r   afterzconverter_source.after   r~   r   c                     dS )zReturns 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.Tr,   )r   targetfilenames     r   targetfilebelongstosourcez*converter_source.targetfilebelongstosource   	    
 tr   c                     dS )z*set the map of already-converted revisionsNr,   )r   revmaps     r   	setrevmapzconverter_source.setrevmap         r   c                     t           )z(Return a list of this repository's headsNotImplementedErrorr    s    r   getheadszconverter_source.getheads       !!r   c                     t           )zReturn 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.
        r   )r   rU   re   s      r   getfilezconverter_source.getfile   s
     "!r   c                     t           )aD  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.)
        r   )r   versionfulls      r   
getchangeszconverter_source.getchanges   s
     "!r   c                     t           )z$Return the commit object for versionr   )r   r   s     r   	getcommitzconverter_source.getcommit   r   r   c                     dS )zWReturn the number of commits in this source.

        If unknown, return None.
        Nr,   r    s    r   
numcommitszconverter_source.numcommits   r   r   c                     t           )zdReturn the tags as a dictionary of name: revision

        Tag names must be UTF-8 strings.
        r   r    s    r   gettagszconverter_source.gettags   s
    
 "!r   c                    |s	| j         pd}t          |t                    r|                    d          S 	 |                    t          j        |                                        d          S # t          $ ry 	 |                    d                              d          cY S # t          $ r@ |                    t          j        |          d                              d          cY cY S w xY ww xY w)Nro   zutf-8zlatin-1replace)r   
isinstancestrr   r1   r   sysstrUnicodeError)r   rB   r   s      r   recodezconverter_source.recode   s    	1}0Ha 	%88G$$$	88HOH5566==gFFF 	 	 	xx	**11':::::   xx 9 99EELL      	s0   9A1 1
C4<'B&#C4&AC0+C4/C00C4c                     t           )aJ  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
        r   )r   re   is      r   getchangedfilesz converter_source.getchangedfiles   s
     "!r   c                     dS )z5Notify the source that a revision has been converted.Nr,   )r   re   sinkrevs      r   	convertedzconverter_source.converted   r   r   c                     dS )zReturn 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.
        Fr,   r    s    r   hasnativeorderzconverter_source.hasnativeorder  s	    
 ur   c                     dS )z7Return true if this source has ability to close branch.Fr,   r    s    r   hasnativeclosezconverter_source.hasnativeclose  s    ur   c                     dS )zIf rev is a meaningful revision reference in source, return
        the referenced identifier in the same format used by getcommit().
        return None otherwise.
        Nr,   r   re   s     r   	lookuprevzconverter_source.lookuprev  r   r   c                     i S )zpReturn the bookmarks as a dictionary of name: revision

        Bookmark names are to be UTF-8 strings.
        r,   r    s    r   getbookmarkszconverter_source.getbookmarks  s	    
 	r   c                     dS )zrevstr is a string that describes a revision in the given
        source control system.  Return true if revstr has correct
        format.
        Tr,   rx   s      r   checkrevformatzconverter_source.checkrevformat  r   r   )NN)rt   r   )r(   r)   r*   __doc__r   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r   r   rm   rm      s]       %%! ! ! !         9 9 9" " "" " "" " " " " "  " " "    " " "D D D             r   rm   c                   Z    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d ZdS )converter_sinkz"Conversion sink (target) interfacec                 >    || _         || _        g | _        || _        dS )zInitialize 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)rp   rq   createdrs   )r   rp   rs   rq   s       r   r   zconverter_sink.__init__%  s$     	 r   c                     t           )zPath to a file that will contain lines
        source_rev_id sink_rev_id
        mapping equivalent revision identifiers for each system.r   r    s    r   
revmapfilezconverter_sink.revmapfile0  
     "!r   c                     dS )zPath to a file that will contain lines
        srcauthor=dstauthor
        mapping equivalent authors identifiers for each system.Nr,   r    s    r   
authorfilezconverter_sink.authorfile6  s	     tr   c	                     t           )a  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.
        r   )	r   filescopiesrb   r]   sourcer   r   cleanp2s	            r   	putcommitzconverter_sink.putcommit<  s
    & "!r   c                     t           )zPut 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.
        r   )r   tagss     r   puttagszconverter_sink.puttagsQ  s
     "!r   c                     dS )zSet the current branch name. Called before the first putcommit
        on the branch.
        branch: branch name for subsequent commits
        pbranches: (converted parent revision, parent branch) tuplesNr,   )r   rd   	pbranchess      r   	setbranchzconverter_sink.setbranchZ  r   r   c                     dS )a;  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.
        Nr,   )r   actives     r   setfilemapmodezconverter_sink.setfilemapmode`  r   r   c                     d S r   r,   r    s    r   r}   zconverter_sink.beforei  r~   r   c                     d S r   r,   r    s    r   r   zconverter_sink.afterl  r~   r   c                     dS )zPut bookmarks into sink.

        bookmarks: {bookmarkname: sink_rev_id, ...}
        where bookmarkname is an UTF-8 string.
        Nr,   )r   	bookmarkss     r   putbookmarkszconverter_sink.putbookmarkso  r   r   c                     t           )zPReturn False if a rev mentioned in a filemap is known to not be
        present.r   r   s     r   hascommitfrommapzconverter_sink.hascommitfrommapv  s
     "!r   c                     t           )zThis 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.r   r   s     r   hascommitforsplicemapz$converter_sink.hascommitforsplicemap{  r   r   N)r(   r)   r*   r   r   r   r   r   r   r   r   r}   r   r   r   r   r,   r   r   r   r   "  s        ,,	! 	! 	!" " "  " " "*" " "H H H        " " "
" " " " "r   r   c                       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dZd Zd Zed             Zd Zd ZdS )commandlinec                 "    || _         || _        d S r   )rp   command)r   rp   r   s      r   r   zcommandline.__init__  s    r   c                     d S r   r,   r    s    r   prerunzcommandline.prerun  r~   r   c                     d S r   r,   r    s    r   postrunzcommandline.postrun  r~   r   c                    t          j        |          }| j        |gt          |          z   }|                                D ]\  }}t          |          dk    r|                    d|z              n,|                    d|                    dd          z              	 t          |          dk    r|                    d|z              n|dxx         d|z   z  cc<   # t          $ r Y w xY wd |D             }| j	        j
        s#|d	t          j        t          j                  gz  }d
                    |          }|S )N      -s   --   _r      =c                 6    g | ]}t          j        |          S r,   )r
   
shellquote)r   args     r   r=   z(commandline._cmdline.<locals>.<listcomp>  s#    ???8&s++???r   s   2>    )r   byteskwargsr   listitemslenappendr   	TypeErrorrp   	debugflagbytestrosdevnullrA   )r   cmdrG   kwargscmdlinekr   s          r   _cmdlinezcommandline._cmdline  sK   %f--<%T

2LLNN 	 	DAq1vv{{tax((((uqyyt'<'<<===q66Q;;NN37++++BKKK4!8+KKK   ??w???w  	=x/
;;<<G))G$$s    ?C  
C-,C-c                 ,    d } | j         ||g|R i |S )Nc                     t          j        t          j        |           ddt          j        t           j                  }|S )NTr   )shellbufsize	close_fdsstdout)
subprocessPopenr
   tonativestrclosefdsPIPE)r   ps     r   popenzcommandline._run.<locals>.popen  s?     $W--"+!  A Hr   )_dorun)r   r   rG   r   r  s        r   _runzcommandline._run  s7    	 	 	 t{5#7777777r   c                 :     | j         t          j        |g|R i |S r   )r  r
   popen2r   r   rG   r   s       r   _run2zcommandline._run2  (    t{8?CA$AAA&AAAr   c                 :     | j         t          j        |g|R i |S r   )r  r
   popen3r  s       r   _run3zcommandline._run3  r  r   c                      | j         |g|R i |}| j                            d|fz             |                                  	  ||          |                                  S # |                                  w xY w)Ns   running: %s
)r   rp   debugr   r   )r   openfuncr   rG   r   r   s         r   r  zcommandline._dorun  s    $-5d555f55&'3444	8G$$LLNNNNDLLNNNNs   
A$ $A:c                      | j         |g|R i |}|                                d         }| j                            |           ||j        fS )Nr   )r  communicaterp   r  
returncoder   r   rG   r   r   outputs         r   runzcommandline.run  sV    DIc+D+++F++#fq|##r   c                      | j         |g|R i |}|j                                        }|                                 | j                            d                    |                     ||j        fS Nr   )r  r   	readlineswaitrp   r  rA   r  r  s         r   runlineszcommandline.runlines  sp    DIc+D+++F++##%%	chhv&&'''q|##r   r   c                    |r}|rI| j                             t          d          | j        z             | j                             |           t	          j        |          }t          j        d| j        |fz            d S )Ns
   %s error:
s   %s %s)rp   warnr   r   r
   explainexitr   rS   )r   statusr  msgs       r   	checkexitzcommandline.checkexit  s     	> %Q~..=>>>V$$$&v..C+h$,)<<===	> 	>r   c                 Z     | j         |g|R i |\  }}|                     ||           |S r   )r  r  r   r   rG   r   r  r  s         r   run0zcommandline.run0  s@    !#777777vv&&&r   c                      | j         |g|R i |\  }}|                     |d                    |                     |S r  )r  r  rA   r!  s         r   	runlines0zcommandline.runlines0  sL    &s<T<<<V<<vsxx//000r   c                 p    d}	 t          j        d          }n# t          t          f$ r Y nw xY w|dz  dz
  S )Ni   
SC_ARG_MAX   r   )r   sysconfAttributeError
ValueError)r   argmaxs     r   r+  zcommandline.argmax  sT     	Z--FF
+ 	 	 	D	 {Qs    --c              /      K   t           | j        |g|R i |          }| j        |z
  }d}g }|D ]T}	t          |	          dz   }
||
z   |k     st          |          dk    r|                    |	           ||
z  }K|V  |	g}|
}U|r|V  d S d S )Nr      )r   r   r+  r   )r   arglistr   rG   r   cmdlenlimitnumbytesflfnbs              r   _limit_arglistzcommandline._limit_arglist  s      ]T]388888899f$ 	 	BB!A!|e##s2ww!||		"AT 	HHHHH	 	r   c                 r     | j         ||g|R i |D ]#} | j        |gt          |          |z   R i | $d S r   )r5  r"  r   )r   r.  r   rG   r   r   s         r   xargszcommandline.xargs   si    $$WcCDCCCFCC 	8 	8ADIc7T$ZZ!^7777777	8 	8r   N)r   )r(   r)   r*   r   r   r   r   r  r  r  r  r  r  r  r"  r$  propertycacher+  r5  r7  r,   r   r   r   r     s               *8 8 8B B BB B B  $ $ $$ $ $> > > >  
  
   ]"  "8 8 8 8 8r   r   c                   8     e Zd Z fdZ fdZ fdZd Z xZS )mapfilec                     t          t          |                                            || _        || _        d | _        g | _        |                                  d S r   )superr:  r   rp   rq   fporder_read)r   rp   rq   	__class__s      r   r   zmapfile.__init__  sL    gt%%'''	


r   c                 V   | j         sd S 	 t          | j         d          }n# t          $ r Y d S w xY wt          |          D ]\  }}|                                d                                         }|s4	 |                    dd          \  }}n<# t          $ r/ t          j	        t          d          | j         |dz   fz            w xY w|| vr| j                            |           t          t          |                               ||           |                                 d S )Ns   rbr   r   r   s/   syntax error in %s(%d): key/value pair expected)rq   r   FileNotFoundError	enumerater<   rstriprsplitr*  r   rS   r   r>  r   r<  r:  __setitem__close)r   r=  r   linekeyvaluer@  s         r   r?  zmapfile._read  sQ   y 	F	di''BB  	 	 	FF	 }} 	9 	9GAt??$$Q'..00D ![[q11
UU   kHIIy!a%()  
 $
!!#&&&'4  ,,S%8888





s   " 
007B9C
c                    | j         p	 t          | j        d          | _         nT# t          $ rG}t	          j        t          d          | j        t          j        |j	                  fz            d }~ww xY w| j         
                    t          j        d||fz                       | j                                          t          t          |                               ||           d S )Ns   abs   could not open map file %r: %ss   %s %s
)r=  r   rq   IOErrorr   rS   r   r   
strtolocalstrerrorwriter	   tonativeeolflushr<  r:  rF  )r   rI  rJ  errr@  s       r   rF  zmapfile.__setitem__&  s    7?ty%00   k788y("5cl"C"CDE  
 	d&zS%L'@AABBBgt((e44444s   % 
A6AA11A6c                 X    | j         r"| j                                          d | _         d S d S r   )r=  rG  r    s    r   rG  zmapfile.close3  s0    7 	GMMOOODGGG	 	r   )r(   r)   r*   r   r?  rF  rG  __classcell__)r@  s   @r   r:  r:    sy                05 5 5 5 5      r   r:  c                     t           j                             |           t           j                             |           z
  }|j        dz  |j        z   }| |fS )z?Like dateutil.makedate() but for time t instead of current timeiQ )datetimeutcfromtimestampfromtimestampdaysseconds)tdeltatzs      r   makedatetimestampr^  9  sT    ..	 ''**+E 
e	em	+Bb5Lr   )NNNN)NTN)%r>   rV  r   rE   rv   r2   r   mercurial.i18nr   mercurial.pycompatr   	mercurialr   r   r   r   r	   mercurial.utilsr
   r8  r   r   r8   rH   rL   	ExceptionrN   rY   r[   SKIPREVr]   rm   r   r   dictr:  r^  r,   r   r   <module>rf     s     				  				            # # # # # #              % $ $ $ $ $"         &   $    
	 	 	 	 	) 	 	 	Y Y Y Y	 	 	 	 	Y 	 	 	        <S S S S S S S Sl]" ]" ]" ]" ]" ]" ]" ]"@@8 @8 @8 @8 @8 @8 @8 @8F1 1 1 1 1d 1 1 1h    r   