o ]Lb@s0ddlmZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZmZmZmZm Z mZmZmZmZmZmZmZmZddlmZmZd d Zd d Zd dZiZ iZ!e"Z#e#j$Z$e#j%Z%e#j&Z&edZ'edZ(Gddde)Z*ddZ+ddZ,ddZ-ddZ.ddZ/ddZ0e#de$d d!Z1e#d"e$d#d$Z2e#d%e$d&d'Z3e#d(e$d)d*Z4d+d,Z5d-d.Z6d/d0Z7d1d2Z8d3d4Z9e#d5e&ed6e8d7d8d9Z:e#d:e&ed6e8d7d;d<Z;e#d=e&ed6e8d7d>d?Ze#dGe%e8d7dHdIZ?e#dJe%e8d7dKdLZ@e#dMe%edNdOdPZAe#dQe&dRdRdSdTdUZBe#dVe%dRdRdSdWdXZCdYdZZDd[d\ZEd]d^ZFd_d`ZGdwdadbZHdcddZIdedfZJejKdgdhZLdwdidjZMdkdlZNdmdnZOdodpZPdqdrZQdsdtZRdudvZSeSdde#e TZUdS)x)absolute_importN)_)hexshort)getattr) encodingerror formattermatchpycompat registrarscmutil simplemergetagmerge templatekw templater templateutilutil)procutil stringutilcG|jd|d|g|RSN merge-tools.)configuitoolpartargsr!5/usr/lib/python3/dist-packages/mercurial/filemerge.py_toolstr.r#cGrr) configboolrr!r!r" _toolbool2r$r&cCs|d|d|Sr) configlist)rrrr!r!r" _toollist6sr(sfile '%(fd)s' was deleted in other%(o)s but was modified in local%(l)s. You can use (c)hanged version, (d)elete, or leave (u)nresolved. What do you want to do?$$ &Changed $$ &Delete $$ &Unresolvedsfile '%(fd)s' was deleted in local%(l)s but was modified in other%(o)s. You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved. What do you want to do?$$ &Changed $$ &Deleted $$ &Unresolvedc@sleZdZdZddZddZddZdd Zd d Zd d Z dZ ddZ ddZ ddZ ddZddZdS) absentfilectxzRepresents a file that's ostensibly in a context but is actually not present in it. This is here because it's very specific to the filemerge code for now -- other code is likely going to break with the values this returns.cCs||_||_dSN)_ctx_f)selfctxfr!r!r"__init___s zabsentfilectx.__init__cCsd|j|jfS)Nsabsent file %s@%s)r,r+r-r!r!r" __bytes__cszabsentfilectx.__bytes__cC|jSr*)r,r1r!r!r"pathfzabsentfilectx.pathcCdSr*r!r1r!r!r"sizeizabsentfilectx.sizecCr6r*r!r1r!r!r"datalr8zabsentfilectx.datacCs |jjSr*)r+reponullidr1r!r!r"filenodeos zabsentfilectx.filenodeTcCs*|o||ko||k S)zVcompare with other file context returns True if different from fctx. isabsent changectxr4)r-fctxr!r!r"cmpts zabsentfilectx.cmpcCdS)Nr!r1r!r!r"flagsr8zabsentfilectx.flagscCr3r*)r+r1r!r!r"r?r5zabsentfilectx.changectxcCrBNFr!r1r!r!r"isbinaryr8zabsentfilectx.isbinarycCrB)NTr!r1r!r!r"r>r8zabsentfilectx.isabsentN)__name__ __module__ __qualname____doc__r0r2r4r7r9r< _customcmprArDr?rFr>r!r!r!r"r)Xs  r)cCs2|tvr|St||d|}|dr|St||S)N executablepython:) internalsr# startswithfindexternaltool)rrcmdr!r!r" _findtools   rRcCs|dr|St|S)NrM)rOr shellquote)rQr!r!r"_quotetoolpaths  rTc CsvdD])}t|||}|s qt|t||d}|r+t|t||dd}|r+|Sqt||d|}tt|S)N)sregkeys regkeyaltsregnames regappendrCrL)r#r lookupregrfindexe expandpath)rrknkpexer!r!r"rPs rPcsxdddfdd ddfdd }d d }|r;t|}|r/|s/d S|r7|t|fS||fStjd } | rO|rK| sKd S| | fS|oR} dD]@\} } t|j d| g} | |r|| | || |r|r| ddds t dt | t |ft| }| t|fSqXi}tdD]$\}}|dd}||vrtt|d||<t|drLj|q|}tfdd|D}d d}|r||||||r||vr|s||fS|dd|f|d|D]\}}||d|||rt|}|t|fSq|s'|s'|r:|s8t|r8 t d|d SdS)Nmergesstrict-capability-checkFcs(|tvr|o t|j|St||Sr*)rN capabilitiesgetr&)r capabilitystrict)rr!r" hascapabilitys z _picktool..hascapabilitycSs|tvo t|jtkSr*)rN mergetypenomergerr!r!r" supportscdsz_picktool..supportscdcs|}|r td||f}t|s)|rtd|d Std|d S|r<|ds<td|d S|rO|dsOtd|d S|rX|sX d Stsmt|drmtd|d Sd S) Ns%s (for pattern %s)scouldn't find merge tool %s ssymlinkstool %s can't handle symlinks binarystool %s can't handle binary guistool %s requires a GUI TF)rrRwarnnoterguir&)rpatsymlinkbinary changedeletetmsg)ra strictcheckrerr!r"checks,    z_picktool..checkuis forcemerge)s:promptNsHGMERGEsmerge-patternsrCrfT)r`swarning: check merge-patterns configurations, if %r for binary file %r is unintentional (see 'hg help merge-tools' for binary files capability) rrrsprioritysdisabledcs"g|] \}}|vr| |fqSr!r!).0rrZ)disabledr!r" s"z_picktool..)Nshgmergesno tool found to merge %s )s:mergeN)F)r%rrRrTrenvironr^ configitemsr rootrhrr bytestrsetsplitintr#r&addkeyssorteditemsinsertappendlen)r:rr4rmrlrnrqforcetoolpathhgmerge binarycaprkrmftoolsrYvtnamesuimergerZr!)rtrarprerr" _picktools|               rcCs4d|vrdSd|vr dSd|vrdSd|vrdSdS)zGuess the EOL type of a fileNs   r!r9r!r!r"_eoltypesrcCsVt|}|r%t|}t|}|r'|||}||kr)t||dSdSdSdS)z/Convert EOL markers in a file to match origfileN)rr9rreadfilereplace writefile)filebackuptostyler9stylenewdatar!r!r" _matcheol's   rpromptc CsJ|j}|j}t|}|jrtdt |j |j g} ||| d<ze|j r<| t | d} gd| } n$|j rP| t| d} gd| } n| td| d} gd| } | dkrnt||||||WS| dkr|t||||||WS| d krt||||||WSWd Stjy|d t||||||YSw) zfAsks the user which of the local `p1()` or the other `p2()` version to keep as the merged version.s/in-memory merge does not support file conflictssfd)localother unresolved)rrrsfile '%(fd)s' needs to be resolved. You can keep (l)ocal%(l)s, take (o)ther%(o)s, or leave (u)nresolved. What do you want to do?$$ &Local $$ &Other $$ &UnresolvedrrrrN)rr@r4r getuipathfnr? isinmemoryr InMemoryMergeConflictsError partextraslabelr> promptchoice_localchangedotherdeletedmsg_otherchangedlocaldeletedmsgr_iother_ilocal_ifailResponseExpectedwrite) r:mynodelocalotherbasetoolconfrfduipathfnpromptsindexchoicer!r!r"_iprompt3sH       rrcCsd|jfS)z=Uses the local `p1()` version of files as the merged version.r)r@r>r:rrrrrr!r!r"rgsrrcCsN|jrt|jd}d|fSt|j|j|jd}d|fS)z=Uses the other `p2()` version of files as the merged version.TFr)r@r>_underlyingfctxifabsentremoverr9rD)r:rrrrrdeletedr!r!r"rms  rsfailcCs,|jrt|j|j|jdS)z Rather than attempting to merge files that were modified on both branches, it marks them as unresolved. The resolve command must be used to resolve these conflicts.rF)r@r>rrr9rDrr!r!r"r|s  rcCs|r ||S|S)zSometimes when resolving, our fcd is actually an absentfilectx, but we want to write to it (to do the resolve). This helper returns the underyling workingfilectx in that case. r=)filectxr!r!r"rsrcCs@t|rtd|j}|td|t|dS)z verifies that text is non-binarys%s looks like a binary file.s warning: %s N) rrmtextrr@r4rhr Abort)inputrmsgr!r!r" _verifytexts  rc Cs2|\}}}}} |s|js|jrdS|j} gd} z t| |d| } Wn-tjySt| |dd} | | vrQddd| D} tt d|| | fYnw| rd }| d kr_d }n| d kred }t dd|||fDrsdSt j ||||d\}}|r| | vr|j ||j |s| ddSdS)Nr)skeep keep-merge3keep-mergediffspremergerC, cSsg|]}d|dqS)'r!)rsrr!r!r"ruz_premerge..s6%s.premerge not valid ('%s' is neither boolean nor %s)r\r mergediffrmerge3css|] }t|VqdSr*)rrmr)rsrr!r!r" s z_premerge..modes premerge successful r)r@r>rr&r ConfigErrorr#lowerjoinranyrrrDdebug)r:rrrrrrrmrlscriptfnr validkeeppremerge_validr merged_text conflictsr!r!r" _premergesJ   rc Csx|\}}}} } t|} | r |jtd|| |fdS|s(|r:|jtd|| |fdSdS)Ns2warning: internal %s cannot merge symlinks for %s Fs@warning: internal %s cannot merge change/delete conflict for %s T)rrrrhrr4r>) r:rfcdfcofcarrrrmrlrrr!r!r" _mergechecks& rcCst|j}zt||t||t||Wn tjyYdSwtj||||d\}}|j||jd|dfS)a) Uses the internal non-interactive simple merge algorithm for merging files. It will fail if there are any conflicts and leave markers in the partially merged file. Markers will have two sections, one for each side of merge, unless mode equals 'union' which suppresses the markers.)TTFrTF)rrr rrr@rrD)r:rrrrrrrr!r!r"_merges    runionsJwarning: conflicts while merging %s! (edit, then use 'hg resolve --mark') )precheckcCt||||dS)z Uses the internal non-interactive simple merge algorithm for merging files. It will use both left and right sides for conflict regions. No markers are inserted.rrr:rrrrrrr!r!r"_iunionsrr\cCr)z Uses the internal non-interactive simple merge algorithm for merging files. It will fail if there are any conflicts and leave markers in the partially merged file. Markers will have two sections, one for each side of merge.r\rrr!r!r"_imergerrcCr)a Uses the internal non-interactive simple merge algorithm for merging files. It will fail if there are any conflicts and leave markers in the partially merged file. Marker will have three sections, one from each side of the merge and one for the base content.rrrr!r!r"_imerge3rrsmerge3-lie-about-conflictsrCcOst|i|\}}}|d|fSrE)r)r kwargsb1junkb2r!r!r"_imerge3alwaysgood+s rrcCr)ag Uses the internal non-interactive simple merge algorithm for merging files. It will fail if there are any conflicts and leave markers in the partially merged file. The marker will have two sections, one with the content from one side of the merge, and one with a diff from the base content to the content on the other side. (experimental)rrrr!r!r" _imerge_diff>srs merge-localcCr)zg Like :merge, but resolve all conflicts non-interactively in favor of the local `p1()` changes.rrrr!r!r" _imergelocalQrs merge-othercCr)zg Like :merge, but resolve all conflicts non-interactively in favor of the other `p2()` changes.rrrr!r!r" _imergeotherYrrstagmergesjautomatic tag merging of %s failed! (use 'hg resolve --tool :merge' or another merge tool of your choice) c Cs$t||j|j|j\}}||dfS)z? Uses the internal tag merge algorithm (experimental). F)rmerger@) r:rrrrrrsuccessstatusr!r!r" _itagmergeas rsdumpT)rmrlc Cst||j}|j}ddlm} t|j| jrtdt |d|j | |d|j |j| |d|j |jdS)a Creates three versions of the files to merge, containing the contents of local, other and base. These files can then be used to perform a merge manually. If the file to be merged is named ``a.txt``, these files will accordingly be named ``a.txt.local``, ``a.txt.other`` and ``a.txt.base`` and they will be placed in the same directory as ``a.txt``. This implies premerge. Therefore, files aren't dumped, if premerge runs successfully. Use :forcedump to forcibly write files out. rcontexts0in-memory merge does not support the :dump tool.s.locals.others.base)FrF) _workingpathr@r4r isinstanceoverlayworkingfilectxr rrr decodeddatawwriter9rD) r:rrrrrrarrr!r!r"_idumprs  rs forcedumpcCst|||||||S)zS Creates three versions of the files as same as :dump, but omits premerge. )rrr!r!r" _forcedumpsrcCs td)Ns5in-memory merge does not support external merge tools)r rrr!r!r" _xmergeimms rc  Cs|dd} | s dStj} |t||| ||t|tdd|v|dd| ||tdd|v|dd | ||td d|v|d d ||d } t | } t ||} t j || t j| d } || | dS)Ncommand-templatesspre-merge-tool-outputrl HG_MY_LABEL)ctxfctxnodenameislinklabelbase HG_BASE_LABEL)rrrr r rHG_OTHER_LABEL)rrspathrr rstoolpathstoolargsdefaults resources)rr mappingdictr?rr4rrDr unquotestringr templateresources maketemplaterrkeywordsr renderdefault)rr:rfclfcbrenvrr tmplrpropstresrr!r!r"_describemergesR        %  rc& Cs4|j}|j}|j} |\} } } } }t|}|s|r/|jtd| ||fdSt||}t |j| d}d| | fd|| fg}d}d|vrp|}|}| drft j |\}}|d ||ft|}|dd \}}t|d kr|d }d d }|t|t|t| d|vd|vd| v||||||d }|j}||||||||||d}td||dd}t|| dr|jtd| ||f|dur| d|}|jd|t||||| ||| | |j||j|dd}nc|jd| |fd}zddlm}| | d| } Wnt!yEt"#td| wt$| |d}!|!dur\t"#td | |ft%&|}"dd!lm'}#|#(||d"| |!d|"id#\}$}%|%r{d}|jd$|d#|d%fWdS1swYdS)&Ns7warning: %s cannot merge change/delete conflict for %s )FrNsargsr rrCs$outputs.origrrcSs|jr d|j|jfS|jS)Ns%s: %s) label_detailr)rr!r!r" format_labelsz_xmerge..format_labelr) sHG_FILEs HG_MY_NODEs HG_OTHER_NODEs HG_BASE_NODEs HG_MY_ISLINKsHG_OTHER_ISLINKsHG_BASE_ISLINKrr r )rr rsoutputs labellocals labelothers labelbases\$cSstt|Sr*)rrSr localpath)sr!r!r"sz_xmerge..rgs"running merge tool %s for file %s  slaunching merge tool: %s s mergetool)cwdrv blockedtags%launching python merge script: %s:%s rr) extensionss hgmerge.%ss&loading python merge script failed: %ss%s does not have function: %s)hookr\Tsmerge tool returned: %d F))r@rrr>rrhrr4rr#rendswithossplitextrr9_maketempfilesrrr?noderDr interpolater&rrrsystemrxrr'loadpath Exceptionr rrr shellsplitr( pythonhook)&r:rrrrrrrrrrrrmrlrrr!r filesoutpathlocaloutputpathext temppathsbasepath otherpathr rrrrQrr'modmergefnargslistr(retraisedr!r!r"_xmerges                     &rAcCsB|j}|dur|}d|i}||}|d|_dS)zAApplies the given template to the ctx and stores it in the input.Nrr)r@r?r-p1r splitlinesr)rtemplater.rtemplateresultr!r!r"_populate_label_detailLs   rFcCsj|j}|dd}|durt||d|}t|}t||}tj||tj |d}|D]}t ||q+dS)z?Populates the label details using the conflict marker template.rs mergemarkerNsmergemarkertemplater) rrr#rrr rrrrrF)r:inputsrrrDrrrr!r!r"_populate_label_detailsWs     rHcCs,|dur dddSd|dd|ddS)zReturn a dictionary of extra labels for use in prompts to the user Intended use is in strings of the form "(l)ocal%(l)s". NrC)ros [%s]rrr!)labelsr!r!r"rgs  rcCs|rdSddlm}t||jr7td\}}t|d}| | Wdn1s1wYnt ||| }t||}t|||j||dS)aMakes and returns a filectx-like object for ``fcd``'s backup file. In addition to preserving the user's pre-existing modifications to `fcd` (if any), the backup is used to undo certain premerges, confirm whether a merge changed anything, and determine what line endings the new file should have. Backups only need to be written once since their content doesn't change afterwards. Nrrshg-merge-backupwb)r:)r>rrrrr mkstempr*fdopenrr9r backuppathr4rrcopyfilearbitraryfilectx)r:rrrrrr/rr!r!r" _makebackupxs     rQc #sdtjddfdd}g}|D]\}}}|||||qz |VWtdStw)zyCreates a temporary file for each (prefix, path, data) tuple in `files`, so an external merge tool may use them. shgmerge-)prefixcsNtj|\}}dtj||f}tj|}|r||7}t|||S)Ns%s~%s)r*r4r+basenamerrr)rRr4r9fullbaser7prenametmprootr!r"maketempfrompaths z(_maketempfiles..maketempfrompathN)r mkdtemprshutilrmtree)r4rY temp_filesrRr4r9r!rWr"r,s   r,c$ Cs0|j}|} t|} | | } |p|p|} d||v} |p-|}t||| | | |\}}d}|tvrL| drL|t dd}|r| drd}| ddkrw|d d dd \}}|sld }d |vstd |vrvd }nd }|rt td||}|d|| t| t| t|f|tvrt|}|j}|j}|j}d}n|rt}nt}t}td}d}d }||| | |f}|sddg}t |dkr|dt||d}t||d }t||d}|tkr|||||||S||kr|td| || || fn |td| |d|||f|rO|||||||sO|rM|rFt d| || dSt!|||}d }z|"dd}|rht#||d} n|} |tkrd}!| dkrx|}!|dks| dkrt$||||g|!dt%|||||}|s|dfW|s|dur|&SSSd|_'d|_'d|_'| dkrt$||||g|d||||||||\}"}}#|"rt(||||||}|r|r|rt d| || t)|||#fW|s|dur|&SSS|s|dur|&www)aperform a 3-way merge in the working directory mynode = parent node before merge orig = original local filename before merge fco = other file context fca = ancestor file context fcd = local file context for current/destination file Returns whether the merge is complete, the return value of the merge, and a boolean indicating whether the file was deleted from disk.rN internal:sinternalrMF:rrT\/sinvalid 'python:' syntax: %ss?picked tool '%s' for %s (binary %s symlink %s changedelete %s) smerging %s failed! rrrr rsmerging %s and %s to %s s merging %s smy %s other %s ancestor %s s0in-memory merge does not support merge conflictsrrrs mergemarkerssbasicrd)*rr4rrrFrDr>rrNrOrcountrsplitr rrrr ryrb onfailurerrrrA fullmergerr MergeInputrcrrrhrQrr#rHrrr_check_onfilemergefailure)$r:wctxrorigrrrrJrrrfduipathrmrlrnrrr invalidsyntaxscriptfuncrbrer isexternalrrrrrr;internalmarkerstyle markerstyle labeltool needcheckrr!r!r" filemerges            $       rucCstd}t|)Ns0merge halted after failed merge (see hg resolve))rr InterventionRequired)rr!r!r" _haltmerge_s rwcCsH|dd}|dkrtd}||ddkrt|dkr"tdSdS)Nr\s on-failurers,continue merge operation (yn)?$$ &Yes $$ &Norrshalt)rrrrw)ractionrr!r!r"rids  ricCsttd|tjS)Ns^([<>=+|-])\1{6}( .*)$)boolresearch MULTILINErr!r!r"hasconflictmarkersosr}c Cs|}t|}|s!t||dsdt||dvr!t|r!d}d}dt||dvr;d}|td||dr;d}|sd|sdt||d sMd t||dvrd|durd| |sd|td ||drdd}|durvt||d rvt t ||||S) Nscheckconflictss conflictsscheckrFrTs0was merge of '%s' successful (yn)?$$ &Yes $$ &Nos checkchangedschangedsJ output file %s appears unchanged was merge successful (yn)?$$ &Yes $$ &Nosfixeol) r4rrr&r(r}r9rrrArr) r:r;rrrrrrcheckedr!r!r"rh}sL     rhcCs||Sr*)wjoinr4)r:r.r!r!r"rsrcCst|jD]6\}}d|}|t|<|td|<|t|<tdd|jD}|r.s (actual capabilities: %s)rs %ss* (actual capabilities: binary, symlink)s! (actual capabilities: binary)s" (actual capabilities: symlink)N) r iteritems_tablerN internalsdocrr]rrrJsysstrr)rextname registrarobjrVrofullnamer]capdescr!r!r"loadinternalmerges  rr*)V __future__r contextlibr*rzr[i18nrr-rrr rrrr r r r rrrrrrrutilsrrr#r&r(rNr internalmerge internaltoolrc mergeonlyrfrrobjectr)rRrTrPrrrrrrrrrrrrrrrrrrrrrrrrrArFrHrrQcontextmanagerr,rurwrir}rhrrvalues i18nfunctionsr!r!r!r"s   <4 q  3     ,             6q   1 /