o ]Lb 3@s~ddlmZddlZddlZddlmZddlmZmZddl m Z m Z m Z ddl mZdd Zd d ZGd d d ejZdS))absolute_importN)_)errorutil)dateutilprocutil stringutil)commonccs6z t|}|s WdS|VqtyYdSw)z,Yield the dictionary objects generated by p4TN)marshalloadEOFError)fdr2/usr/lib/python3/dist-packages/hgext/convert/p4.pyloaditers  rcCs&gd}|D] \}}|||}q|S)aQPerforce escapes special characters @, #, *, or % with %40, %23, %2A, or %25 respectively >>> decodefilename(b'portable-net45%252Bnetcore45%252Bwp8%252BMonoAndroid') 'portable-net45%2Bnetcore45%2Bwp8%2BMonoAndroid' >>> decodefilename(b'//Depot/Directory/%2525/%2523/%23%40.%2A') '//Depot/Directory/%25/%23/#@.*' ))s%2A*)s%23#)s%40@)s%25%)replace)filename replacementskvrrrdecodefilename&s rcseZdZd&fdd ZddZddZdd Zejd d Z ejd d Z ejddZ ejddZ ejddZ ejddZddZddZddZd&ddZddZd d!Zd"d#Zd$d%ZZS)' p4_sourceNcsddlm}tt|j||||dd|vr$|ds$ttd|tj ddd i|_ |j d d |j |_td |_td |_td|_|rYt|dkr[ttddSdS)Nr )convcmd)revs///s%%s does not look like a P4 repositoryp4F)abortconverts p4.encodingsE([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)(\+\w+)?$sA\$(Id|Header|Date|DateTime|Change|File|Revision|Author):[^$\n]*\$s\$(Id|Header):[^$\n]*\$s8p4 source does not support specifying multiple revisions)rsuperr__init__ startswithr NoRepor checktoolrevmapuiconfig orig_encodingencodingrecompilere_type re_keywordsre_keywords_oldlenrAbort)selfr,repotypepathrr __class__rrr';s2   zp4_source.__init__cCs ||_dS)aSets the parsed revmap dictionary. Revmap stores mappings from a source revision to a target revision. It is set in convertcmd.convert and provided by the user as a file on the commandline. Revisions in the map are considered beeing present in the repository and ignored during _parse(). This allows for incremental imports if a revmap is provided. N)r+)r7r+rrr setrevmap^s zp4_source.setrevmapcCsJdt|}tj|dd}i}t|D]}|dd}|r"d||<q|S)zRead changes affecting the pathsp4 -G changes -s submitted %srbmodechangeNT)r shellquotepopenrget)r7r9cmdstdout p4changesrcrrr _parse_viewks  zp4_source._parse_viewc&Csi}i}i}i}i}i}g} |tdd|vr9||||dr4|dr4|dddi} n]ddi} nXdt|} t tj | d d } i} | D]B} | d r| |  \}}||||d r{|d r{|dd}|dd}|d d}|| ddd}|| |<qNt |td}t | tdd}|jdd}|tdd}|D]{}|rt|t|krq|jrt|t|jdkrq||jvr|}q|r|g}ng}||}|||}|jd}t|dkr|dd}nd}d|j|f}|t|ddg}i}g}d}d||vrd||vr|d|}d}|D]} || rQt| | |t| d}nq5|rx|||d|f|||<| d|dkrt|||||<|d7}d||vrd||vs+|D]}||}dt|}!tj |!d d }"d}#t!|"D]e}d}$d}d ||vr|d ||kr|d|dkrd}%d!||%f|vr|d"||%fd#kr|d!||%f}$n |%d7}%d!||%f|vs|d7}d ||vs|$r |$|vr ||$}#nq|#r|#||<q|"td$||fq|||<|||<|||<|}q|r>t|dkr>|g} |||| |d%S)&z4Prepare list of P4 filenames and revisions to importsreading p4 views r r!s/...Nsp4 -G client -o %sr=r>sViews...r )keyT)rLreverser$s p4.startrevscollecting p4 changelists rs s **empty changelist description**s%s %sP s depotFile%dsrev%dsaction%dsmove/addsp4 -G filelog %sschange%ds file%d,%dshow%d,%ds moved froms*cannot find source for copied file: %s@%s ) changesetfilescopiesheads depotname)#statusrupdaterHr(endswithrrAr r rBsplitfindsortedkeysintr5r,r-rr+_fetch_revision_construct_commitdesc splitlinesrstriprevrellipsislowerrappendrCrwarn)&r7r,r9rF changeset files_map copies_map localname depotnameheadsviewsrD clientspecclientsviewcview vieworderstartrevlastidchangeparentsrrGdescarr shortdesctfilescopies copiedfilesioldnamerrflcmdflstdoutcopiedfilename copiedoldnamejrrr_parsevs               zp4_source._parsecCs||j|jSN)rr,r9r7rrr _parse_onceszp4_source._parse_oncecC |jdS)NrRrrrrrr{  zp4_source.copiescCr)NrQrrrrrrzrzp4_source.filescCr)NrPrrrrrrgrzp4_source.changesetcCr)NrSrrrrrrlrzp4_source.headscCr)NrTrrrrrrkrzp4_source.depotnamecCs|jSr)rlrrrrgetheads szp4_source.getheadscCsdtd|j||f}d} tj|dd}d}g}d}t|D]t} | d} | d} | dkr>|sscodesdataserrorsgenericsstatsaction)spurgesdeletes move/delete)NNstyperJr xrKssymlinklskokstextsbinarys$\1$rO)rrArkrBrrCIOErrorr2matchgroupr4r3rejoinsubrW)r7namerbrD lasterrorrEr?contentskeywordsrcodedataactionp4typeflagsrrrgetfile#sd      0   zp4_source.getfilecCs*|r ttd|j||j|tfS)Ns'convert from p4 does not support --full)rr6rrzr{set)r7rbfullrrr getchangeseszp4_source.getchangesc Csj||dd}t|ddf}|durg}tj||dt|d||d|d|d|dd d S) ze Constructs a common.commit object from an unmarshalled `p4 describe` output sdescrJstimerNsusers%Y-%m-%d %H:%M:%S %1%2r@)r"sconvert_revision)authordatervr_branchrbextra)recoderCr\r commitrdatestr)r7objrvr_rrrrr^js  zp4_source._construct_commitcCs d|}tj|dd}t|S)zXReturn an output of `p4 describe` including author, commit date as a dictionary.sp4 -G describe -s %sr=r>)rrBr r )r7rbrDrErrrr]~s zp4_source._fetch_revisioncCsH||jvr |j|S||jvr||}|j|ddSttd|)N)rvs1cannot find %s in the revmap or parsed changesets)rgr+r]r^rr6r)r7rbrrrr getcommits     zp4_source.getcommitcCsiSrrrrrrgettagsszp4_source.gettagscCstdd|j|DS)NcSsg|]}|dqS)rr).0xrrr sz-p4_source.getchangedfiles..)rZrz)r7rbr}rrrgetchangedfilesszp4_source.getchangedfilesr)__name__ __module__ __qualname__r'r<rHrr propertycacherr{rzrgrlrkrrrr^r]rrr __classcell__rrr:rr:s4#        B  r) __future__rr r0mercurial.i18nr mercurialrrmercurial.utilsrrrr%r rrconverter_sourcerrrrrs