
    	^c                        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mZ ddl	m
Z
 ddlmZmZmZmZm	Z	mZmZmZmZmZmZmZmZ ddlmZmZ d Zd	 Zd
 Zi Zi Z ej                     Z!e!j"        Z"e!j#        Z#e!j$        Z$ ed          Z% ed          Z& G d d          Z'd Z(d Z)d Z*d Z+d Z,d Z- e!de"          d             Z. e!de"          d             Z/ e!de"          d             Z0 e!de"          d             Z1d Z2d Z3d Z4d  Z5d! Z6 e!d"e$ ed#          e5$          d%             Z7 e!d&e$ ed#          e5$          d'             Z8 e!d(e$ ed#          e5$          d)             Z9 e!d*e$d+e5$          d,             Z: e!d-e$ ed#          e5$          d.             Z; e!d/e#e5$          d0             Z< e!d1e#e5$          d2             Z= e!d3e# ed4                    d5             Z> e!d6e$d7d78          d9             Z? e!d:e#d7d78          d;             Z@d< ZAd= ZBd> ZCd? ZDdLd@ZEdA ZFdB ZGe jH        dC             ZIdLdDZJdE ZKdF ZLdG ZMdH ZNdI ZOdJ ZPdK ZQ eQdde!           eR                                ZSdS )M    N   )_)hexshort)getattr)encodingerror	formattermatchpycompat	registrarscmutilsimplemergetagmerge
templatekw	templatertemplateutilutil)procutil
stringutilc                 ,     | j         d|dz   |z   g|R  S N   merge-tools   .)configuitoolpartargss       5/usr/lib/python3/dist-packages/mercurial/filemerge.py_toolstrr"   -   s'    29^TD[4%7?$????    c                 ,     | j         d|dz   |z   g|R  S r   )
configboolr   s       r!   	_toolboolr&   1   s'    2=t);CdCCCCr#   c                 :    |                      d|dz   |z             S r   )
configlist)r   r   r   s      r!   	_toollistr)   5   s    ==t);<<<r#   s   file '%(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 $$ &Unresolveds   file '%(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                   X    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 )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.c                 "    || _         || _        d S N)_ctx_f)selfctxfs      r!   __init__zabsentfilectx.__init__^   s    	r#   c                 $    d| j         | j        fz  S )Ns   absent file %s@%s)r/   r.   r0   s    r!   	__bytes__zabsentfilectx.__bytes__b   s    #tw	&:::r#   c                     | j         S r-   )r/   r5   s    r!   pathzabsentfilectx.pathe   s	    wr#   c                     d S r-    r5   s    r!   sizezabsentfilectx.sizeh       tr#   c                     d S r-   r:   r5   s    r!   datazabsentfilectx.datak   r<   r#   c                 >    | j                                         j        S r-   )r.   reponullidr5   s    r!   filenodezabsentfilectx.filenoden   s    y~~&&r#   Tc                     |                                 oS|                                |                                 k    o)|                                |                                 k     S )zVcompare with other file context

        returns True if different from fctx.
        isabsent	changectxr8   )r0   fctxs     r!   cmpzabsentfilectx.cmps   sW     MMOO +  DNN$4$44+		tyy{{*
 	
r#   c                     dS )Nr#   r:   r5   s    r!   flagszabsentfilectx.flags~   s    sr#   c                     | j         S r-   )r.   r5   s    r!   rF   zabsentfilectx.changectx   s
    yr#   c                     dS NFr:   r5   s    r!   isbinaryzabsentfilectx.isbinary   s    ur#   c                     dS )NTr:   r5   s    r!   rE   zabsentfilectx.isabsent   r<   r#   N)__name__
__module____qualname____doc__r3   r6   r8   r;   r>   rB   
_customcmprH   rJ   rF   rN   rE   r:   r#   r!   r+   r+   W   s        I I  ; ; ;      ' ' ' J	
 	
 	
          r#   r+   c                     |t           v r|S t          | |d|          }|                    d          r|S t          | |          S )N
   executable   python:)	internalsr"   
startswithfindexternaltool)r   r   cmds      r!   	_findtoolr\      sN    y
2t]D
1
1C
~~j!! 
B%%%r#   c                 X    |                      d          r| S t          j        |           S )NrW   )rY   r   
shellquote)r[   s    r!   _quotetoolpathr_      s,    
~~j!! 
s###r#   c           
      J   dD ]i}t          | ||          }|st          j        |t          | |d                    }|r-t          j        |t          | |dd          z             }|r|c S jt          | |d|          }t          j        t          j        |                    S )N)s   regkeys	   regkeyalts   regnames	   regappendr#   rV   )r"   r   	lookupregr   findexe
expandpath)r   r   knkpexes         r!   rZ   rZ      s    '  Rr"" 	N1hr4<<== 	 Xb$c%J%J!JKKA 
2t]D
1
1CDOC00111r#   c                 X                        dd          dfd	d fd}                    dd          }|r6t          |          }|r |          sd	S |r|t          |          fS ||fS t          j                            d
          }	|	r|r |	          sd	S |	|	fS |o}
                    d          D ]\  }}t          j        | j	        d|g          } ||          r |||||
|          r~|rY |dd          sK
                    t          d          t          j        |          t          j        |          fz             t          |          }|t          |          fc S i }t                                          d          D ]k\  }}|                    d          d         }||vr!t!          t#          |d                    ||<   t%          |d          r                    |           l|                                }t+          fd|                                D                       }                    dd          }|r1 ||||||          r"||vr|s||fS |                    dd |f           |                    d           |D ]7\  }} ||d |||          r#t          |          }|t          |          fc S 8|s|s|r8|s4t3          |          r%
                    t          d          |z             d	S dS )N   merges   strict-capability-checkFc                     | t           v r'|o$t           |          j                            |          S t          | |          S r-   )rX   capabilitiesgetr&   )r   
capabilitystrictr   s      r!   hascapabilityz _picktool.<locals>.hascapability   s@    9Jio:>>zJJJT:...r#   c                 J    | t           v ot           |          j        t          k    S r-   )rX   	mergetypenomerger   s    r!   
supportscdz_picktool.<locals>.supportscd   s    y IYt_%>'%IIr#   c                 |   | }|rt          d          | |fz  }t          	|           sN|r&	                    t          d          |z             n	                    t          d          |z             n|r3 | d          s&	                    t          d          |z             n|r3 | d          s&	                    t          d          |z             nZ|r |           snLt	          j                    s7t          	| d          r&	                    t          d          |z             nd	S d
S )Ns   %s (for pattern %s)s   couldn't find merge tool %s
s   symlinks   tool %s can't handle symlinks
   binarys   tool %s can't handle binary
   guis   tool %s requires a GUI
TF)r   r\   warnnoter   guir&   )
r   patsymlinkbinarychangedeletetmsgro   strictcheckrt   r   s
         r!   checkz_picktool.<locals>.check   st    	;+,,c{:DT"" 	 D:;;dBCCCC:;;dBCCCC 	]]4[II 	GGA899D@AAAA 		MM$	;GG 		GGA677$>???? 	**T"2"2 	  	Ib$$?$? 	GGA122T9::::4ur#      uis
   forcemerge)s   :promptNs   HGMERGEs   merge-patternsr#   rv   T)rn   s   warning: check merge-patterns configurations, if %r for binary file %r is unintentional
(see 'hg help merge-tools' for binary files capability)
r   r   r   s   prioritys   disabledc                 (    g | ]\  }}|v	| |fS r:   r:   ).0r   rf   disableds      r!   
<listcomp>z_picktool.<locals>.<listcomp>   s-    IIIaD4H4H1"d4H4H4Hr#   )Ns   hgmerges   no tool found to merge %s
)s   :mergeN)F)r%   r   r\   r_   r   environrl   configitemsr   rootrx   r   r   bytestrsetsplitintr"   r&   addkeyssorteditemsinsertappendlen)r@   r   r8   r}   r|   r~   r   forcetoolpathhgmerge	binarycapr{   r   mftoolsre   vtnamesuimergerf   r   ro   r   rt   s    `                   @@@@r!   	_picktoolr      s-   --*DEEK/ / / / / /
J J J       2 IIe]++E 	&R'' 	&

8 4 4 	&## &~h7788 u~% "":..G & 	&

7 3 3 	&##W%%
 &;I^^$566 4 4	T[C#//2d88 	4dC)\JJ 	4 	mmD)DIII 	;   '--x/?/E/EFG   !T**H.223333 EuuH~..  1GGDMM!E>>8B;7788E!HRK(( 	LLOOOJJLLEIIII5;;==III E iix((G - 5$>> 	-e##L#))LLT7O,,,	LL#$$$ 1 115D'6<88 	1 Q''H~h//0000	1
   &  L   	>E

 	>GGA455<===?r#   c                 6    d| v rdS d| v rdS d| v rdS d| v rdS dS )zGuess the EOL type of a file    Ns   
      
r:   r>   s    r!   _eoltyper     s?    }}t$w}}u}}u4r#   c                    t          |                                          }|rXt          j        |           }t          |          }|r5|                    ||          }||k    rt          j        | |           dS dS dS dS )z/Convert EOL markers in a file to match origfileN)r   r>   r   readfilereplace	writefile)filebackuptostyler>   stylenewdatas         r!   	_matcheolr   &  s    v{{}}%%G .}T"" 	.ll5'22G$tW-----. .	. 	.r#      promptc           	         | j         }|j                                        }t          j        |           }|j                                                                        rt          j        d          t          |j
        |j
        g          }	 ||          |	d<   	 |j                                        r)|                    t          |	z  d          }
g d|
         }nr|j                                        r)|                    t          |	z  d          }
g d|
         }n0|                    t          d          |	z  d          }
g d|
         }|dk    rt!          | |||||          S |dk    rt#          | |||||          S |d	k    rt%          | |||||          S dS # t          j        $ r, |                    d
           t%          | |||||          cY S w xY w)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 conflictss   fd   )   local   other
   unresolved)r   r   r   s   file '%(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 $$ &Unresolvedr   r   r   r   N)r   rG   r8   r   getuipathfnrF   
isinmemoryr	   InMemoryMergeConflictsError
partextraslabelrE   promptchoice_localchangedotherdeletedmsg_otherchangedlocaldeletedmsgr   _iother_ilocal_ifailResponseExpectedwrite)r@   mynodelocalotherbasetoolconfr   fduipathfnpromptsindexchoices               r!   _ipromptr   2  s#    
B			B"4((H z((** 
/>
 
 	
 %+u{344GXb\\GEN B:   	@OO$@7$JANNE888?FFZ  "" 	@OO$@7$JANNE888?FF
 OO:   
 
E 988?FX4tXFFFx4tXFFF}$$$udHEEE %$! B B B
dFE5$AAAAABs   CF" ,F" F" "8GGr   c                 8    d|j                                         fS )z=Uses the local `p1()` version of files as the merged version.r   )rG   rE   r@   r   r   r   r   r   s         r!   r   r   f  s     ej!!####r#   r   c                 >   |j                                         r)t          |j                                                    d}nXt          |j                                       |j                                         |j                                                    d}d|fS )z=Uses the other `p2()` version of files as the merged version.TFr   )rG   rE   _underlyingfctxifabsentremover   r>   rJ   )r@   r   r   r   r   r   deleteds          r!   r   r   l  s     z 
++22444
++11JOOuz//11	
 	
 	
 g:r#   s   failc                     |j                                         rVt          |j                                       |j                                         |j                                                    dS )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.r   F)rG   rE   r   r   r>   rJ   r   s         r!   r   r   {  sb     z 

++11JOOuz//11	
 	
 	
 8r#   c                     |                                  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.
    rD   )filectxs    r!   r   r     s<    
    ""7<<>>22r#   c                    t          j        |                                           rbt          d          | j                                        z  }|                    t          d          |z             t          j        |          dS )z verifies that text is non-binarys   %s looks like a binary file.s   warning: %s
N)	r   r}   textr   rG   r8   rx   r	   Abort)inputr   msgs      r!   _verifytextr     sv    && /005:??3D3DD
"##c)***k# r#   c                    |\  }}}}}	|s2|j                                         s|j                                         rdS | j        }
g d}	 t          |
|d|           }n# t          j        $ rq t          |
|dd                                          }||vrFd                    d |D                       }t	          j        t          d          |||fz            Y nw xY w|rd}|d	k    rd
}n|dk    rd}t          d |||fD                       rdS t          j        ||||          \  }}|r||v r2|j                             ||j                                                    |s|
                    d           dS dS )Nr   )s   keep   keep-merge3   keep-mergediffs   premerger#      , c                     g | ]
}d |z   d z   S )   'r:   )r   r   s     r!   r   z_premerge.<locals>.<listcomp>  s      D D DQD D D Dr#   s6   %s.premerge not valid ('%s' is neither boolean nor %s)ri   r   	   mergediffr      merge3c              3   b   K   | ]*}t          j        |                                          V  +d S r-   )r   r}   r   )r   r   s     r!   	<genexpr>z_premerge.<locals>.<genexpr>  sF       
 
05Jejjll++
 
 
 
 
 
r#   modes    premerge successful
r   )rG   rE   r   r&   r	   ConfigErrorr"   lowerjoinr   anyr   r   rJ   debug)r@   r   r   r   r   r   r   r}   r|   scriptfnr   	validkeeppremerge_validr   merged_text	conflictss                    r!   	_premerger     s   08-D(FGX %*%%'' 5:+>+>+@+@ q	B<<<I	R{J??   Bk377==??9$$ZZ D D) D D DEEF#KLL6*+   %$  (((DD''D 
 
:?u9M
 
 
 
 
 	 1!,!84T"
 "
 "
Y  	>H	11 J[%**:*:*<*<=== 	HH.///11s   A A=CCc                    |\  }}}}	}
t          j        |           }|	rI| j                            t	          d          | ||                                          fz             dS |                                s|                                rI| j                            t	          d          | ||                                          fz             dS dS )Ns2   warning: internal %s cannot merge symlinks for %s
Fs@   warning: internal %s cannot merge change/delete conflict for %s
T)r   r   r   rx   r   r8   rE   )r@   r   fcdfcofcar   r   r   r}   r|   r   r   s               r!   _mergecheckr     s    08-D(FGX"4((H DEEXXchhjj))*+	
 	
 	
 u
||~~  %  XXchhjj))*	+	
 	
 	
 u4r#   c                 B   | j         }	 t          ||           t          ||           t          ||           t          j        ||||          \  }}|j                            ||j                                                   d|dfS # t          j        $ r Y dS w xY w)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.r   TF)TTF)r   r   r   rG   r   rJ   r	   r   )r@   r   r   r   r   r   r   r   s           r!   _merger     s     
B&E2D"E2 "-!84T"
 "
 "
Y
 	
ej&6&6&8&8999Y%% ; ! ! !   !s   0B BB   unionsJ   warning: conflicts while merging %s! (edit, then use 'hg resolve --mark')
)precheckc                 (    t          | |||d          S )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.r   r   r@   r   r   r   r   r   r   s          r!   _iunionr    s     $udH555r#   ri   c                 (    t          | |||d          S )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.ri   r   r  s          r!   _imerger    s     $udH555r#   r   c                 (    t          | |||d          S )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.r   r   r  s          r!   _imerge3r    s     $udI666r#   s   merge3-lie-about-conflictsr#   c                  ,    t          | i |\  }}}|d|fS rM   )r  )r    kwargsb1junkb2s        r!   _imerge3alwaysgoodr  *  s*     T,V,,LBb ub=r#   r   c                 (    t          | |||d          S )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)r   r   r  s          r!   _imerge_diffr  =  s      $udL999r#   s   merge-localc                 (    t          | |||d          S )zg
    Like :merge, but resolve all conflicts non-interactively in favor
    of the local `p1()` changes.r   r   r  s          r!   _imergelocalr  P      
 $udH555r#   s   merge-otherc                 (    t          | |||d          S )zg
    Like :merge, but resolve all conflicts non-interactively in favor
    of the other `p2()` changes.r   r   r  s          r!   _imergeotherr  X  r  r#   s   tagmergesj   automatic tag merging of %s failed! (use 'hg resolve --tool :merge' or another merge tool of your choice)
c                 ^    t          j        | |j        |j        |j                  \  }}||dfS )z?
    Uses the internal tag merge algorithm (experimental).
    F)r   mergerG   )	r@   r   r   r   r   r   r   successstatuss	            r!   
_itagmerger  `  s0     nT5:uz49MMOGVFE!!r#   s   dumpT)r}   r|   c                 H   t          | |j                  }|j                                        }ddlm}	 t          |j        |	j                  rt          j        d          t          j
        |dz   |j                                                   |                     |dz   |j                                        |j                                                   |                     |dz   |j                                        |j                                                   dS )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.
    r   contexts0   in-memory merge does not support the :dump tool.s   .locals   .others   .base)Fr   F)_workingpathrG   r8    r  
isinstanceoverlayworkingfilectxr	   r   r   r   decodeddatawwriter>   rJ   )
r@   r   r   r   r   r   r   ar   r  s
             r!   _idumpr#  q  s     	T5:&&A			B%*g;<< 
/?
 
 	
 	N1y=%*"8"8":":;;;KKY
 1 15:3C3C3E3EFFFKKXty~~//1B1BCCC?r#   s	   forcedumpc           	      ,    t          | ||||||          S )zS
    Creates three versions of the files as same as :dump, but omits premerge.
    )r#  r  s          r!   
_forcedumpr%    s    
 $udHfEEEr#   c                 *    t          j        d          )Ns5   in-memory merge does not support external merge tools)r	   r   r  s          r!   
_xmergeimmr'    s     
+@  r#   c	                 |   |                      dd          }	|	sd S t          j        }
|                                t	          |          |                                 |
|                                |t	          |          t          d          d|                                v |d         d           |
|                                |t          d          d|                                v |d         d	           |
|                                |t          d
          d|                                v |d         d	          ||d}t          j	        |	          }	t          j        | |          }t          j        | |	t          j        |          }|                     |                    |                     d S )N   command-templatess   pre-merge-tool-outputr      l   HG_MY_LABEL)   ctx   fctx   node   name   islink   label   base   HG_BASE_LABEL)r,  r-  r/  r0  r1  r      HG_OTHER_LABEL)r,  r.  s   pathr   r2  r   s   toolpaths   toolargsdefaults	resources)r   r   mappingdictrF   r   r8   r   rJ   r   unquotestringr
   templateresourcesmaketemplaterr   keywordsr  renderdefault)r   r@   r   fclfcbr   envr   r    tmplr8  propstresr   s                 r!   _describemergerD    s   99)+CDDD *KV+V8399;;.n- 	
 	
 7399;;../ 
 
 +8399;;./0 
 
 C" "EJ "4((D &r400D
D:.$	 	 	A IIaooe$$%%%%%r#   c                 	   |j         }|j         }|j         }	|\  }
}}}}t          j        |           }|                                s|                                rI| j                            t          d          |
 ||                                          fz             dS t          | |          }t          | j        |
d          }d|	                                |	
                                fd|                                |
                                fg}d}d|v rw|}|                                }|                    d          r"t          j                            |          \  }}|                    d	||                                f           t!          |          5 }|d d
         \  }}t#          |          dk    r|d
         }d }|                                t%          |          t%          |                                                                          t%          |	                                                                          d|                                v d|                                v d|	                                v  ||           ||           ||          d
}| j        }|||| ||           ||           ||          d}t-          j        d||d           }t1          ||
d          rG| j                            t          d          |
 ||                                          fz             |[|dz   |z   }| j                            d|z             t7          || |||	||||	  	         |                    || j        |d          }n| j                            d||fz             d}	 ddlm} |                     |d|
z            } n2# tB          $ r% tE          j#        t          d          |z            w xY wtI          | |d           }!|!&tE          j#        t          d          ||fz            tK          j&        |          }"ddlm'}# |#(                    || d ||!d|"id!          \  }$}%|%rd}| j                            d"|z             d!|d#fcd d d            S # 1 swxY w Y   d S )$Ns7   warning: %s cannot merge change/delete conflict for %s
)Fr   Ns   argsr2  r   r#   s   $outputs   .origr   r      c                 @    | j         rd| j        | j         fz  S | j        S )Ns   %s: %s)label_detailr   )r   s    r!   format_labelz_xmerge.<locals>.format_label  s*    ! # EK1C#DDD{"r#   r*  )
s   HG_FILEs
   HG_MY_NODEs   HG_OTHER_NODEs   HG_BASE_NODEs   HG_MY_ISLINKs   HG_OTHER_ISLINKs   HG_BASE_ISLINKr+  r4  r3  )r   r2  r   s   outputs
   labellocals
   labelothers	   labelbase   \$c                 N    t          j        t          j        |                     S r-   r   r^   r   	localpathss    r!   <lambda>z_xmerge.<locals>.<lambda>  s    h)$.*;*;<< r#   rw   s"   running merge tool %s for file %s
    s   launching merge tool: %s
s	   mergetool)cwdr   
blockedtags%   launching python merge script: %s:%s
r   r   )
extensionss
   hgmerge.%ss&   loading python merge script failed: %ss   %s does not have function: %s)hookri   Ts   merge tool returned: %d
F))rG   r   r   rE   r   rx   r   r8   r  r"   r   endswithossplitextr   r>   _maketempfilesr   r   rF   noderJ   r   interpolater&   r  r   rD  systemr   r  rT  loadpath	Exceptionr	   r   r   r   
shellsplitrU  
pythonhook)&r@   r   r   r   r   r   r   r   r   r   r   r   r}   r|   r   r   rM  r    filesoutpathlocaloutputpathext	temppathsbasepath	otherpathrI  r@  r   r   r[   rrT  modmergefnargslistrU  retraiseds&                                         r!   _xmergern    s   
*C
*C
)C08-D(FGX"4((H
||~~  IJJXXchhjj))*+	
 	
 	
 ~T3''IDGT7++D 
#((**coo//0	388::s001E GT ++--##H-- 	E#%7#3#3O#D#D OSh?@@@			 Q)'m)y>>Q!!I	# 	# 	# 

 ==#CMMOO$8$8$:$:;;"3==??#7#7#9#9::!SYY[[0 $		 3#syy{{2(L//+|E22*l400
 
 W  '<..'<..&,t,,
 
 <<	
 
 Rv&& 	GNN899#((**--./   T/D(CGMM7#=>>>2tVS#sC4PPP		CL   AA GMM9Xx<PP   A(((((( ))(MD4HII   k?@@8K   c8T22Gk6778X:NN    *400H//D(Hg7JD KC  2Q6777Q~cQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Qs,   'H+S
O32S
3/P""BS

SSc                     | j                                         }|                                |                                }d|i}|                    |          }t          j        |          | _        dS )zAApplies the given template to the ctx and stores it in the input.Nr,  )rG   rF   rZ  p1r=  r   	firstlinerH  )r   templater1   rB  templateresults        r!   _populate_label_detailrt  K  se    
*


 
 C
xxzzffhhSME++E22N#-n==Er#   c                 (   | j         }|                    dd          }|t          ||d|          }t          j        |          }t          j        ||           }t          j        ||t          j	        |          }|D ]}t          ||           dS )z?Populates the label details using the conflict marker template.r)  s   mergemarkerNs   mergemarkertemplater5  )r   r   r"   r   r9  r
   r:  r;  r   r<  rt  )r@   inputsr   r   rr  rC  rA  r   s           r!   _populate_label_detailsrw  V  s    	Byy-~>>HB&<hGG&x00H&r400D"
Hz2d  D  , ,ud++++, ,r#   c                 >    | dddS d| d         z  d| d         z  dS )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".
    Nr#   )r*     os    [%s]r   r   r:   )labelss    r!   r   r   f  sG    
 ~
 
 	
 ""  r#   c                    |                                 rdS ddlm} t          ||j                  rlt          j        d          \  }}t          j        |d          5 }|	                    |
                                           ddd           n# 1 swxY w Y   nMt          j        || |                                          }t          | |          }t          j        ||           |                    ||           S )a  Makes 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.
    Nr   r  s   hg-merge-backupwb)r@   )rE   r  r  r  r  r   mkstemprW  fdopenr   r>   r   
backuppathr8   r  r   copyfilearbitraryfilectx)r@   r   r   r  r   r   r2   r"  s           r!   _makebackupr  w  s.    ||~~ t #w455 !%&899
FYr4   	 AGGCHHJJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  #Bchhjj99s##a   ##F#666s   (BBBc              #      K   t          j        d          fd}g }| D ]&\  }}}|                     ||||                     '	 |V  t          j                   dS # t          j                   w xY w)zyCreates a temporary file for each (prefix, path, data) tuple in `files`,
    so an external merge tool may use them.
    s   hgmerge-)prefixc                    t           j                            |          \  }}dt           j                            |          | fz  }t           j                            |          }|r||z  }t          j        ||           |S )Ns   %s~%s)rW  r8   rX  basenamer   r   r   )r  r8   r>   fullbaserd  prenametmproots          r!   maketempfrompathz(_maketempfiles.<locals>.maketempfrompath  sx    ((..#"'**844f==w||GS)) 	CKDtT"""r#   N)r   mkdtempr   shutilrmtree)ra  r  
temp_filesr  r8   r>   r  s         @r!   rY  rY    s      
 k222G     J# @ @d**64>>????ggs   
A$ $A:c           
      H   | j         }|                                }	t          j        |           }
 |
|	          }|                                p'|                                p|                                }d|                                |                                z   v }|                                p|                                }t          | ||	|||          \  }}d}|t          v r,|	                    d          r|t          d          d         }|r|	                    d          rud}|                    d          dk    r0|d	d                             dd
          \  }}|sd}d|v sd|v rd}nd}|r$t          j        t          d          |z            |}|                    d||t#          j        |          t#          j        |          t#          j        |          fz             |t          v r%t          |         }|j        }|j        }|j        }d}n=|                                rt.          }nt0          }t2          }t          d          }d}d}|||||f}|sddg}t          |          dk     r|                    d           t7          j        ||d                   }t7          j        ||d
                   }t7          j        ||d                   }|t:          k    r || |||||          S ||                                k    rM|                    t          d           |
|           |
|                                          |fz             n%|                    t          d          |z             |                    d|||fz             |rT || |||||          sD|r@|                                rt          j        d          |                     ||z             dS tC          | ||          }d
}	 |"                    dd          }|rtG          ||d          } n|} |t2          k    rtI          | |||           d}!| dk    r|}!|dk    s| dk    rtK          | |||g|!           tM          | ||||          }|s|df|s||'                                 S S S d|_(        d|_(        d|_(        | dk    rtK          | |||g|            || ||||||          \  }"}}#|"rtS          | |||||          }|rQ|r@|                                rt          j        d          |                     ||z             tU          |           ||#f|s||'                                 S S S # |s||'                                 w w w xY w)a  perform 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.r*  N	   internal:s   internalrW   F   :r      r   T   \   /s   invalid 'python:' syntax: %ss?   picked tool '%s' for %s (binary %s symlink %s changedelete %s)
s   merging %s failed!
r   r   rF  r2  r   s   merging %s and %s to %s
s   merging %s
s   my %s other %s ancestor %s
s0   in-memory merge does not support merge conflictsr   r   s   mergemarkerss   basicrs   )+r   r8   r   r   rN   rJ   rE   r   rX   rY   r   countrsplitr	   r   r   r   r   r   rq   	onfailurer   r   r'  rn  	fullmerger   r   
MergeInputrr   r  r   rx   r  r   r"   _run_partial_resolution_toolsrw  r   r   rH  _check_onfilemergefailure)$r@   wctxr   origr   r   r   rz  r   r   r   fduipathr}   r|   r~   r   r   r   invalidsyntaxscriptfuncrq   r  r   
isexternalr   r   r   r   r   rh  internalmarkerstylemarkerstyle	labeltool	needcheckr   s$                                       r!   	filemerger    s    
B	B"4((Hx||H\\^^?s||~~?FciikkCIIKK//G<<>>3S\\^^LtRVWlKKND(HyT__\::C$$&&' H''
33 >>$1$$'|224;;FH % $  DH$4$4 $ M 	M+a ?@@8KLLLHHKV$$W%%\**
	
	 	 	 yN	N	=

?? 	DDD	-..	
Xvw8H &H%
6{{Qg"3q	22E"3q	22E!#vay11DGt
 
 	
 sxxzz
		*++x~~xx

33X>?	
 	
 	
 	

 			!O$$x/000HH,S#>??? vsChGG  	*   7G   GGI()))xr3''F	AF ii?? 	."2t_==KK-K	!!)$udCCC Ih&& !	"h..+2I2I'5%.Y     A   %xH  	V'MMOOOO	'C "&E!%E $D(""#D5%*>TJJJJ $!
 !
	1g  	7tQD#v66A 		$ .??$$ ;+  
 	H,---###'z 	V'MMOOOO	'q 	V'MMOOOO	's   BV 9B1V V!c                 d   | j         }|                    dd          rdS g }t                      }d}|                    |          D ]\  }}	|                    d          d         }
|
|v r&|                    |d|
z  g           }d}|rVt          j        | j        d	||j        	                                
          } ||j        
                                          }|r|                    |d|
z            r|                    |d|
z  d          }|                    |d|
z  |
          }|                    |d|
z            }|                    ||
||f           |sdS |                                 d|j        
                                |                                fd|j        
                                |                                fd|j        
                                |                                fg}t!          |          5 }|\  }}}|D ]\  }}
}}t#          j        |          }|||d}t'          j        d||d           }d||fz  }|                    || j        d          }|rt-          j        d|
|fz            t'          j        |          }t'          j        |          }||k    r n|                    |           |                    t'          j        |                     |                    |           ddd           dS # 1 swxY w Y   dS )zCRuns partial-resolution tools on the three inputs and updates them.ri   s   disable-partial-toolsNs   partial-merge-toolsr   r   s   %s.patternsTr#   )r1   s
   %s.disables   %s.orders   %s.executables   %s.argsr   r2  r   )r   r2  r   rJ  c                 N    t          j        t          j        |                     S r-   rL  rN  s    r!   rP  z/_run_partial_resolution_tools.<locals>.<lambda>  s    (-dnQ.?.?@@ r#   s   %s %ss   partial-mergetool)rR  rS  s)   partial merge tool %s exited with code %d)r   r%   r   r   r   r(   r   r   rG   rF   r8   	configintr   r   sortr   rY  r   r^   r   r[  r\  r	   
StateErrorr   set_text)r@   r   r   r   r   r   seensectionre   r   r  patternsis_matchmorder
executabler    ra  re  rM  rf  rg  r[   r   rh  
local_text
other_texts                              r!   r  r  _  s   	B	}}X788 E55D$Gw'' : :1wwt}}Q4<<==.4*?DD 	,	3ej.B.B.D.D  A q**++H 	:}}Wmd&:;; LL+*<a@@E7,<t,CTJJJ99Wj4&788DLL%z48999 	JJLLL 
5:??$$ejjll3	$)..""DIIKK0	5:??$$ejjll3E 
		 #))2&	8Y-2 	 	)E4T%j11C#!# G
 #@@	 D c4[(C		#499M	NNA &@D!9L   y11Jy11JZ'' ( 	z"""dmH--...z"""?# # # # # # # # # # # # # # # # # #s   DL%%L),L)c                  H    t          d          } t          j        |           )Ns0   merge halted after failed merge (see hg resolve))r   r	   InterventionRequired)r   s    r!   
_haltmerger    s!    
?
@
@C

$S
)
))r#   c                     |                      dd          }|dk    r7t          d          }|                     |d          dk    rt                       |dk    rt                       d S d S )Nri   s
   on-failurer   s,   continue merge operation (yn)?$$ &Yes $$ &Nor   r   s   halt)r   r   r   r  )r   actionr   s      r!   r  r    sp    YYx//F?@@??3""a''LLL r#   c                 \    t          t          j        d| t          j                            S )Ns   ^([<>=+|-])\1{6}( .*)$)boolresearch	MULTILINEr   s    r!   hasconflictmarkersr    s0    
 
	&L	
 	
  r#   c                    |                                 }t          j        |           }|sGt          ||d          sdt	          ||d          v r#t          |                                          rd}d}dt	          ||d          v r3d}|                    t          d           ||          z  d          rd}|sn|slt          ||d	          sd
t	          ||d          v rH|F|	                    |          s1|                    t          d           ||          z  d          rd}|/t          ||d          rt          t          | |          |           |S )Ns   checkconflictss	   conflictss   checkr   Fr   Ts0   was merge of '%s' successful (yn)?$$ &Yes $$ &Nos   checkchangeds   changedsJ    output file %s appears unchanged
was merge successful (yn)?$$ &Yes $$ &Nos   fixeol)r8   r   r   r&   r)   r  r>   r   r   rH   r   r  )	r@   rh  r   r   r   r   r   r   checkeds	            r!   r  r    s   	B"4((H "d-..9Rx8888chhjj)) 	AGIb$1111??ABBhrll
 
 	
 A  b$00	
 Yr4:::: cggfoo& 
 (2,,   	 iD)<<,tS))6222Hr#   c                 P    |                      |                                          S r-   )wjoinr8   )r@   r1   s     r!   r  r    s    ::chhjj!!!r#   c                    |j                                         D ]\  }}d|z   }|t          |<   |t          d|z   <   |t          |<   t	          d |j                                        D                       }|r<dd                    |          z  }|j        t          j	        d|z            z   |_        t          d           t          d           t          d	           d
S )z4Load internal merge tool from specified registrarobjr  r  c                     g | ]	\  }}||
S r:   r:   )r   re   r   s      r!   r   z%loadinternalmerge.<locals>.<listcomp>  s!    LLLTQ!LqLLLr#   s       (actual capabilities: %s)r   s   

%ss*       (actual capabilities: binary, symlink)s!       (actual capabilities: binary)s"       (actual capabilities: symlink)N)_tabler   rX   internalsdocr   rk   r   rS   r   sysstrr   )r   extnameregistrarobjr  r  fullnamerk   capdescs           r!   loadinternalmerger    s    ")//11 O O
d$;"	()-	,%&!%XLLT->-D-D-F-FLLLMM 	O6: : G  <(/)g:M*N*NNDL 3444 *+++ +,,,,,r#   r-   )T
contextlibrW  r  r  i18nr   rZ  r   r   r   r   r  r   r	   r
   r   r   r   r   r   r   r   r   r   utilsr   r   r"   r&   r)   rX   r  internalmergeinternaltoolrr   	mergeonlyr  r   r   r+   r\   r_   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r#  r%  r'  rD  rn  rt  rw  r   r  contextmanagerrY  r  r  r  r  r  r  r  r  valuesi18nfunctionsr:   r#   r!   <module>r     s       				 				                                                        @ @ @D D D= = = 	&y&(( 
"	"	  !q-      !q.    1 1 1 1 1 1 1 1h& & &$ $ $2 2 2n n nb
 
 
	. 	. 	. i!!0B 0B "!0Bf h  $ $ ! $
 h    !  gw
 
  
    ) ) )X  *& & &0 A	2    6 6 6 A	2    6 6 6 A	2    7 7 7 !	  
 
 
 A	2    : : : ni+>>>6 6 ?>6 ni+>>>6 6 ?>6 A	"  " " " gyt<<<  =<8 lIdDAAAF F BAF  3& 3& 3&ln n nb> > >, , , ,   "7 7 7<   0n n n nbF# F# F#R* * *
    , , ,^" " "- - -:  $l + + +   ""r#   