o ]LbW @sddlmZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZddlmZmZmZmZmZmZmZm ZmZmZmZejZejZej Z ej!Z!ej"Z"ej#Z#ej$Z$ej%Z%ej&Z&ej'Z'ej(Z(ej)Z)ej*Z*ej+Z+ej,Z,d a-d%d d Z.d d Z/ddZ0de#dfde$dfde,dfde(dfde%dfde)dfde&dfde"dfde*dfg Z1de'fde+fgZ2ddZ3ddZ4Gdd d e5Z6Gd!d"d"e5Z7d&d#d$Z8dS)')absolute_importN)_)open)encodingerrorhgpycompatscmutilutil)dateutil) bzrcommoncvsdarcsfilemapgitgnuarchrmonotonep4 subversionsasciic Cs |duri}t|dp}|D]d}|}|r|drqz |dd\}}Wnty>td}||||fYqw|}|}||d|fvrbtd}| |||f|||<qtd}| |||||fqWd|S1s~wY|S)Nrb#=r s,ignoring bad line in author map file %s: %s smapping author %s to %s s5overriding mapping for author %s, was %s, will be %s ) rstrip startswithsplit ValueErrorrwarnrstripgetdebugstatus) ui authorfileauthorsafileline srcauthor dstauthormsgmr,7/usr/lib/python3/dist-packages/hgext/convert/convcmd.py readauthormap;s8   r.cCs6t|tjr|ttdS|dttdS)Nreplacezutf-8) isinstancerunicodeencodesysstr orig_encodingdecode)sr,r,r-recodeYs   r7cCs$||pd|}|s|d|}|S)a >>> bmap = {b'default': b'branch1'} >>> for i in [b'', None]: ... mapbranch(i, bmap) 'branch1' 'branch1' >>> bmap = {b'None': b'branch2'} >>> for i in [b'', None]: ... mapbranch(i, bmap) 'branch2' 'branch2' >>> bmap = {b'None': b'branch3', b'default': b'branch4'} >>> for i in [b'None', b'', None, b'default', b'branch5']: ... mapbranch(i, bmap) 'branch3' 'branch4' 'branch4' 'branch4' 'branch5' sdefaultsNoner )branch branchmapr,r,r- mapbranchbs r;scvs branchsortsgitssvnshg sourcesortsdarcssmtnsgnuarchsbzrsp4c Csg}|r|ddtDvrttd|tD]2\}}}z|r$||kr0||||||fWSWqttfyJ}z ||WYd}~qd}~ww|js`|D]}|dt |j dqPttd|)NcSg|]}|dqSrr,.0r6r,r,r- z!convertsource..s"%s: invalid source repository type%s rs%%s: missing or unsupported repository) source_convertersrAbortrNoRepo MissingToolappendquietwriterbytestrargs) r#pathtyperevs exceptionsnamesourcesortmodeinstr,r,r- convertsources  rVc Cs|r|ddtDvrttd|tD]B\}}z|r!||kr*||||WSWqtyF}z|td|WYd}~qd}~wtyX}ztd|d}~wwttd|)NcSr>r?r,r@r,r,r-rBrCzconvertsink..s'%s: invalid destination repository types convert: %s rDs%s: unknown repository type)sink_convertersrrFrrGnoterH)r#rNrOrRsinkrUr,r,r- convertsinks  rZc@s4eZdZddZddZddZddZd d Zd S) progresssourcecCs*||_||_|jtdtd|d|_dS)Ns getting filessfilesunittotal)r#rS makeprogressrprogress)selfr#rS filecountr,r,r-__init__s  zprogresssource.__init__cCs|jj|d|j||S)N)item)r` incrementrSgetfile)rafilerevr,r,r-rfszprogresssource.getfilecC |j|SN)rStargetfilebelongstosource)ratargetfilenamer,r,r-rk z(progresssource.targetfilebelongstosourcecCrirj)rS lookuprev)rarhr,r,r-rnrmzprogresssource.lookuprevcCs|jdSrj)r`completerar,r,r-closeszprogresssource.closeN)__name__ __module__ __qualname__rcrfrkrnrqr,r,r,r-r[s  r[c@sdeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dS) convertercCs||_||_||_||_i|_i|_d|_t|||_|j}|r-t j |r-| || dr@| | d|j|_|| d|_t|| d|_dS)N authormaps splicemaps branchmap)rSdestr#opts commitcacher%r$mapfilemaposrNexistsr.r parsesplicemap splicemapr:)rar#rSrw revmapfilerxr$r,r,r-rcs      zconverter.__init__c Cs|siSi}zpt|d}tt|D]`\}}|d}|s"qtj|dd}t|}dt |kr9dksGnt t d||df|D]}|j |qI|d|dd|dd }} } | | krm| ||<q| | ||<qW|Styt t d |w) acheck and validate the splicemap format and return a child/parents dictionary. Format checking has two parts. 1. generic format which is same across all source types 2. specific format checking which may be different for different source type. This logic is implemented in checkrevformat function in source files like hg.py, subversion.py etc. rr,)data whitespaces8syntax error in %s(%d): child parent1[,parent2] expectedr Ns-splicemap file not found or error reading %s:)r enumerater iterfile splitlinesrrshlexerlistlenrrFrrScheckrevformatIOError) rarNr+fpir'lexpartchildp1p2r,r,r-r~s@   $   zconverter.parsesplicemapc Cst|}t}i}|j}|jjtdtd|d}|re|d}||vr'q||jvr<|j|}|t ks;|j |r|}n ttd||\} } g} i} | r|| } | | | | | | gD]A}|| vrzfdd|D| |<z | || Wntyttdt|t| fw| |s| d|d| |<qg| sSt | t krttd| S)znReturn an ordering such that every uncommitted changeset is preceded by all its uncommitted ancestors.cstt|}t}i}g}|rK|}||vrq||||gd}||D]}|jvr8||d}||g|q*|sI|||s||fS)aReturn a (children, roots) tuple where 'children' maps parent revision identifiers to children ones, and 'roots' is the list of revisions without parents. 'parents' must be a mapping of revision identifier to its parents ones. FT) collectionsdequerrpopleftr setdefaultr{rI)rrseenchildrenrootsr hasparentrrpr,r- mapchildrenRs(      z'converter.toposort..mapchildrencsdgfdd}|S)aIf the previously converted revision has a child in the eligible revisions list, pick it. Return the list head otherwise. Branch sort attempts to minimize branch switching, which is harmful for Mercurial backend compression. Ncs6|d}|D]}d|vr|}nq|d<|S)Nrr,)nodesnextr)rprevr,r-picknext|sz>converter.toposort..makebranchsorter..picknextr,r)r)rr-makebranchsorterss z,converter.toposort..makebranchsortercfddfdd}|S)zSource specific sort.cs j|jSrj)rysortkeyrrpr,r-s z>converter.toposort..makesourcesorter..ct|ddSN)keyrrrkeyfnr,r-rz>converter.toposort..makesourcesorter..picknextr,rrprr-makesourcesorters  z,converter.toposort..makesourcesortercr)zClose order sort.csdj|jvj|jfS)Nsclose)ryextrarrrpr,r-rs z=converter.toposort..makeclosesorter..crrrrrr,r-rrz=converter.toposort..makeclosesorter..picknextr,rrprr-makeclosesorters  z+converter.toposort..makeclosesortercs"ifddfdd}|S)zSort revisions by date.cs&|vrtj|j|<|Srj)r parsedaterydater)datesrar,r-getdatesz;converter.toposort..makedatesorter..getdatecstfdd|DdS)Ncsg|]}||fqSr,r,)rArrr,r-rBszPconverter.toposort..makedatesorter..picknext..r )minrrr,r-rsz.makedatesorter..picknextr,rrp)rrr-makedatesorters z*converter.toposort..makedatesorterr<datesortr= closesortsunknown sort mode: %scsg|] }|jvr|qSr,r{rArrpr,r-rBz&converter.toposort..s cycle detected between %s and %srNsnot all revisions were sorted) rrFrremoverIr rr7insertr)rarrTrrrrrrractivesr6pendingsrrr,)rrar-toposortNsR  !       zconverter.toposortc Csb|j}|r/|jtd|t|d}|jD]}|td||j|fq| dSdS)Nswriting author map file %s swb+s%s=%s ) r$r#r"rrr%rKr tonativeeolrq)rar$ofileauthorr,r,r-writeauthormaps   zconverter.writeauthormapcCst|j||j|_dSrj)r.r#r%)rar$r,r,r-r.szconverter.readauthormapcCs>|j|}|j|j|j|_t|j|j|_||j|<|Srj) rS getcommitr%r rr;r9r:ry)rarhrr,r,r-rs  zconverter.cachecommitc sj|}jd}j||}t|tr*|tkrt}nj|}|j|<dS|\}}}g} |j rR|j D]} | jvrC | | j| j| j fq7j |j | z!j|} jtdtd| |ffdd| D} Wntydd| D} | fdd|jDYnwt| d krt}t| d krtjjt|} ntjjt|t| d } j ||| || j||} | j|| | j|<dS) Nsfullsspliced in %s as parents of %s s and csg|] }j||qSr,)r{r rrpr,r-rBrz"converter.copy..cSr>r?r,)rAbr,r,r-rBrCc3s$|] }|jvrj|VqdSrjr)rAxrpr,r- sz!converter.copy..rrr )ryrxr rS getchangesr0bytesrr{rrrIr9rw setbranchrr#r"rjoinKeyErrorextend optparentsrrr[ putcommitrq converted)rarhrfullchangesrwfilescopiescleanp2 pbranchesrrrSnewnoder,rpr-copys\              zconverter.copycsLz|j|j|j|j|jtd|j}| |}| ||j |jtd| ||}t |}d}|jtd|jjtdtdt |d}t|D]:\}}|d8}|j|j} d| vrs| d } |jd |t| f|jtd t|||||q[||jd d s|j} i} | D]} | | } |j| ttkr|j| | | <q|r| r|j| \}|rrfddt|jD}|r||j|d d <|j}i}|D]} || } |j| ttkr |j| || <q|r|r|j ||!W|"dS|"w)Nsscanning source... s sorting... sconverting... s convertingrr\r  rs%d %s s source: %s sconvertsskiptagscsg|] }|dkr|qS)r r,)rAe tagsparentr,r-rBKs  z%converter.convert..)#rSbeforerw setrevmapr{r#r"rgetheadsrrrrrr_rrydescrr7rXrrro configboolgettagsr rputtagsr iteritems getbookmarks putbookmarksrcleanup)rarTrrtnumrr`rrtagsctagskvnrev tagsparents bookmarks cbookmarksr,rr-convertsj                zconverter.convertcCs4z |jW|jn|jw|jdSrj)rwafterrSr{rqrpr,r,r-ras zconverter.cleanupN)rrrsrtrcr~rrrrr.rrr rr,r,r,r-rus/ 4 Cruc  sttjadt_dsdd<|s)t|d}|td|t ||d}t |}zt ||dd\}}Wnt y\|jD]}t|d qRwd } fd d | D} t| d kruttd| r|| d} n|} | dkr|sttd| dkr|sttdd} | rt||| }|d |s|}t||||} | | dS)NsUTF-8rvsauthorss-hgsassuming destination %s s dest_types source_typesrevT)r<rr=rcsg|] }|r|qSr,r8)rAr+rxr,r-rBrzconvert..r s!more than one sort mode specifiedrr=s1--sourcesort is not supported by this data sourcers0--closesort is not supported by this data sourcesfilemap)r byteskwargsrr4r r defaultdestr"rrZr wrapconvertsinkrV ExceptioncreatedshutilrmtreerrrFhasnativeorderhasnativecloserfilemap_sourcesetfilemapmoderrur ) r#srcrwrrxdestcsrcc defaultsortrN sortmodesrTfmaprr,rr-r isT         r rj)NN)9 __future__rrr|rmercurial.i18nrmercurial.pycompatr mercurialrrrrr r mercurial.utilsr r rrrrrr hgconvertrrrrzrHrGr bzr_source convert_cvs convert_git darcs_sourcegnuarch_sourcemercurial_sinkmercurial_sourcemonotone_source p4_sourcesvn_sink svn_sourcer4r.r7r;rErWrVrZobjectr[rur r,r,r,r-sb     4  # "