o ^UbH@slddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZmZmZmZmZddlmZejZejZddZGd d d eZd%d d ZejrcejZejZnej Zej!Zd dZ"ddZ#Gddde$Z%d&ddZ&Gddde$Z'dZ(GdddeZ)GdddeZ*GdddeZ+Gdd d eZ,Gd!d"d"e-Z.d#d$Z/dS)')absolute_importN)_)open)encodingerrorphasespycompatutil)procutilcCs|durdS|dS)Nlatin1)encode)dr6/usr/lib/python3/dist-packages/hgext/convert/common.py _encodeornone s rc@s<eZdZddZddZddZeddZed d Zd S) _shlexpy3proxycCs ||_dSN_l)selflrrr__init__'s z_shlexpy3proxy.__init__cCsdd|jDS)Ncss|]}t|VqdSr)r).0vrrr +sz*_shlexpy3proxy.__iter__..rrrrr__iter__*sz_shlexpy3proxy.__iter__cCst|jSr)rr get_tokenrrrrr-sz_shlexpy3proxy.get_tokencCs |jjpdS)Ns )rinfilerrrrr0s z_shlexpy3proxy.infilecCs|jjSr)rlinenorrrrr4sz_shlexpy3proxy.linenoN) __name__ __module__ __qualname__rrrpropertyrrrrrrr&s rcCs|durtjrt|ddd}nt|d}n|durtdtjr&|d}tj||dd}|durJd|_tjrC|j|d7_n|j|7_|durctjr\|j |d7_ n|j |7_ tjrjt |S|S)Nrr )rs/shlexer only accepts data or filepath, not bothT)rposix) rispy3rrProgrammingErrordecodeshlexwhitespace_split whitespace wordcharsr)datafilepathr,r+rrrrshlexer9s.  r/cCsdd}t|}||S)NcSs&t|}ddt|D}d|S)NcSsg|]}|dqS)r) splitlines)rrrrr bsz1encodeargs..encodearg..)base64_encodebytesr iterbytestrjoin)slinesrrr encodearg`s zencodeargs..encodearg)pickledumps)argsr8r6rrr encodeargs_s r<cCst|}t|Sr)base64_decodebytesr9loads)r6rrr decodeargsis r?c@ eZdZdS) MissingToolNr r!r"rrrrrAnrATcCsJ|p|}t|s#|rtj}nt}|td||rtd|p ddS)Nscannot find required "%s" tools (try installing the %s package)r2)r findexerAbortrAr)exenameabortdebnameexcrrr checktoolrs  rKc@r@)NoRepoNrBrrrrrL}rCrLsSKIPc@s(eZdZdddddejddfddZdS)commitNTc Cs\|pd|_|pd|_||_||_| pg|_||_||_|pi|_||_| |_ | |_ | |_ dS)Nsunknowns0 0) authordatedescparents optparentsbranchrevextrasortkeysaverevphasectx) rrNrOrPrQrSrTrUrVrWrXrRrYrrrrs     zcommit.__init__)r r!r"rdraftrrrrrrMsrMc@seZdZdZd,ddZd-ddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZd.ddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd-d*d+ZdS)/converter_sourcezConversion source interfaceNcCs"||_||_||_||_d|_dS)zmInitialize conversion source (or raise NoRepo("message") exception if path is not a valid repository)utf-8N)uipathrevsrepotyper)rr]r`r^r_rrrrs  zconverter_source.__init__ splicemapcCs&td|sttd||fdS)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)rematchrrErrrevstrmapnamerrrcheckhexformats zconverter_source.checkhexformatcCdSrrrrrrbeforezconverter_source.beforecCrhrrrrrrafterrjzconverter_source.aftercCdS)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)rtargetfilenamerrrtargetfilebelongstosourcez*converter_source.targetfilebelongstosourcecCrl)z*set the map of already-converted revisionsNr)rrevmaprrr setrevmapzconverter_source.setrevmapcCt)z(Return a list of this repository's headsNotImplementedErrorrrrrgetheadszconverter_source.getheadscCrs)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. rt)rrGrTrrrgetfileszconverter_source.getfilecCrs)aDReturns 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.) rt)rversionfullrrr getchangesszconverter_source.getchangescCrs)z$Return the commit object for versionrt)rryrrr getcommitrwzconverter_source.getcommitcCrl)zWReturn the number of commits in this source. If unknown, return None. Nrrrrr numcommitsrozconverter_source.numcommitscCrs)zdReturn the tags as a dictionary of name: revision Tag names must be UTF-8 strings. rtrrrrgettagsrozconverter_source.gettagsc Cs|s|jpd}t|tjr|dSz |t|dWStyHz |ddWYStyG|t|ddYYSww)Nr\zutf-8zlatin-1replace)r isinstancerunicoder r(sysstr UnicodeError)rr6rrrrrecodes      zconverter_source.recodecCrs)aJReturn 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 rt)rrTirrrgetchangedfiless z converter_source.getchangedfilescCrl)z5Notify the source that a revision has been converted.Nr)rrTsinkrevrrr convertedrrzconverter_source.convertedcCrl)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. Frrrrrhasnativeorderrozconverter_source.hasnativeordercCrl)z7Return true if this source has ability to close branch.Frrrrrhasnativecloserwzconverter_source.hasnativeclosecCrl)zIf rev is a meaningful revision reference in source, return the referenced identifier in the same format used by getcommit(). return None otherwise. NrrrTrrr lookuprev"rozconverter_source.lookuprevcCsiS)zpReturn the bookmarks as a dictionary of name: revision Bookmark names are to be UTF-8 strings. rrrrr getbookmarks)rozconverter_source.getbookmarkscCrl)zrevstr is a string that describes a revision in the given source control system. Return true if revstr has correct format. Trrdrrrcheckrevformat0rozconverter_source.checkrevformat)NN)rar)r r!r"__doc__rrgrirkrnrqrvrxr{r|r}r~rrrrrrrrrrrrr[s,     r[c@speZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS)converter_sinkz"Conversion sink (target) interfacecCs||_||_g|_||_dS)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)r]r^createdr`)rr]r`r^rrrr;s zconverter_sink.__init__cCrs)zPath to a file that will contain lines source_rev_id sink_rev_id mapping equivalent revision identifiers for each system.rtrrrr revmapfileFzconverter_sink.revmapfilecCrl)zPath to a file that will contain lines srcauthor=dstauthor mapping equivalent authors identifiers for each system.Nrrrrr authorfileLrzconverter_sink.authorfilec Crs)aCreate 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. rt) rfilescopiesrQrMsourcerprzcleanp2rrr putcommitRszconverter_sink.putcommitcCrs)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. rt)rtagsrrrputtagsgszconverter_sink.puttagscCrl)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)rrS pbranchesrrr setbranchprrzconverter_sink.setbranchcCrl)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)ractiverrrsetfilemapmodevrrzconverter_sink.setfilemapmodecCrhrrrrrrrirjzconverter_sink.beforecCrhrrrrrrrkrjzconverter_sink.aftercCrl)zPut bookmarks into sink. bookmarks: {bookmarkname: sink_rev_id, ...} where bookmarkname is an UTF-8 string. Nr)r bookmarksrrr putbookmarksrrzconverter_sink.putbookmarkscCrs)zPReturn False if a rev mentioned in a filemap is known to not be present.rtrrrrhascommitfrommapszconverter_sink.hascommitfrommapcCrs)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.rtrrrrhascommitforsplicemaprz$converter_sink.hascommitforsplicemapN)r r!r"rrrrrrrrrirkrrrrrrrr8s    rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ d#ddZ ddZddZeddZddZd d!Zd"S)$ commandlinecCs||_||_dSr)r]command)rr]rrrrrs zcommandline.__init__cCrhrrrrrrprerunrjzcommandline.preruncCrhrrrrrrpostrunrjzcommandline.postrunc Ost|}|j|gt|}t|D]@\}}t|dkr%|d|n |d|ddzt|dkr?|d|n |dd|7<WqtySYqwdd |D}|j j si|d t t j g7}d |}|S) N-s--_r2=cSsg|]}t|qSr)r shellquote)rargrrrr1sz(commandline._cmdline..s2> )r byteskwargsrlist iteritemslenappendr TypeErrorr] debugflagbytestrosdevnullr5)rcmdr;kwargscmdlinekrrrr_cmdlines&     zcommandline._cmdlinecOs"dd}|j||g|Ri|S)NcSs"tjt|ddtjtjd}|S)NTr)shellbufsize close_fdsstdout) subprocessPopenr tonativestrclosefdsPIPE)rprrrpopenszcommandline._run..popen)_dorun)rrr;rrrrr_runs zcommandline._runcO|jtj|g|Ri|Sr)rr popen2rrr;rrrr_run2zcommandline._run2cOrr)rr popen3rrrr_run3rzcommandline._run3cOsP|j|g|Ri|}|jd|f|z ||W|S|w)Ns running: %s )rr]debugrr)ropenfuncrr;rrrrrrs zcommandline._doruncOs:|j|g|Ri|}|d}|j|||jfS)Nr)r communicater]r returncoderrr;rroutputrrrruns   zcommandline.runcOsF|j|g|Ri|}|j}||jd|||jfSNr2)rr readlineswaitr]rr5rrrrrrunliness   zcommandline.runlinesr2cCsL|r$|r|jtd|j|j|t|}td|j|fdS)Ns %s error: s%s %s)r]warnrrr explainexitrrE)rstatusrmsgrrr checkexits  zcommandline.checkexitcOs,|j|g|Ri|\}}||||Sr)rrrrr;rrrrrrrun0s zcommandline.run0cOs2|j|g|Ri|\}}||d||Sr)rrr5rrrr runlines0szcommandline.runlines0c Cs6d}ztd}Wn ttfyYnw|ddS)Ni SC_ARG_MAXr)rsysconfAttributeError ValueError)rargmaxrrrrs zcommandline.argmaxc ost|j|g|Ri|}|j|}d}g}|D]&} t| d} || |ks.t|dkr8|| || 7}q|V| g}| }q|rH|VdSdS)Nr)rrrr) rarglistrr;rcmdlenlimitnumbytesflfnbrrr_limit_arglists      zcommandline._limit_arglistcOsD|j||g|Ri|D]}|j|gt||Ri|q dSr)rrr)rrrr;rrrrrxargss"zcommandline.xargsN)r2)r r!r"rrrrrrrrrrrrr propertycacherrrrrrrrs$     rcs<eZdZfddZfddZfddZddZZS) mapfilecs2tt|||_||_d|_g|_|dSr)superrrr]r^fporder_read)rr]r^ __class__rrrs  zmapfile.__init__c s|jsdSzt|jd}Wnty'}z|jtjkrWYd}~dSd}~wwtt|D]B\}}|d }|s>q/z | dd\}}Wnt y]t td|j|dfw||vrh|j|tt|||q/|dS)Nsrbrrrs/syntax error in %s(%d): key/value pair expected)r^rIOErrorerrnoENOENT enumerater iterfiler0rstriprsplitrrrErrrrr __setitem__close)rrerrrlinekeyvaluerrrr$s6     z mapfile._readc s|jdur+z t|jd|_Wnty*}zttd|jt|j fd}~ww|j t d||f|j tt|||dS)Nsabscould not open map file %r: %ss%s %s )rrr^rrrErr strtolocalstrerrorwriter tonativeeolflushrrr)rr r rrrrr>s  zmapfile.__setitem__cCs|jr |jd|_dSdSr)rrrrrrrKs  z mapfile.close)r r!r"rrrr __classcell__rrrrrs     rcCs0tj|tj|}|jd|j}||fS)z?Like dateutil.makedate() but for time t instead of current timeiQ)datetimeutcfromtimestamp fromtimestampdaysseconds)tdeltatzrrrmakedatetimestampQs r)NNNN)NTN)0 __future__rbase64rrrrbr)rmercurial.i18nrmercurial.pycompatr mercurialrrrrr mercurial.utilsr r9rrobjectrr/r& encodebytesr3 decodebytesr= encodestring decodestringr<r? ExceptionrArKrLSKIPREVrMr[rrdictrrrrrrsH        ` 6