
    6hV                    T   S SK Jr  S SKrS SKrS SKrS SKrSSKJr  SSKJ	r	J
r
  SSKJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJrJr  S rS	 rS
 r0 r0 r \RB                  " 5       r"\"RF                  r#\"RH                  r$\"RJ                  r%\" S5      r&\" S5      r' " S S5      r(S r)S r*S r+S r,S r-S r.\"" S\#5      S 5       r/\"" S\#5      S 5       r0\"" S\#5      S 5       r1\"" S\#5      S 5       r2S r3S r4S r5S  r6S! r7\"" S"\%\" S#5      \6S$9S% 5       r8\"" S&\%\" S#5      \6S$9S' 5       r9\"" S(\%\" S#5      \6S$9S) 5       r:\"" S*\%\" S#5      \6S$9S+ 5       r;\"" S,\%S-\6S$9S. 5       r<\"" S/\%\" S#5      \6S$9S0 5       r=\"" S1\$\6S$9S2 5       r>\"" S3\$\6S$9S4 5       r?\"" S5\$\" S65      5      S7 5       r@\"" S8\%S9S9S:9S; 5       rA\"" S<\$S9S9S:9S= 5       rBS> rCS? rDS@ rESA rFSNSB jrGSC rHSD rI\R                  SE 5       rKSNSF jrLSG rMSH rNSI rOSJ rPSK rQSL rRSM rS\S" SS\"5        \R                  5       rUg)O    )annotationsN   )_)hexshort)encodingerror	formattermatchpycompat	registrarscmutilsimplemergetagmerge
templatekw	templatertemplateutilutil)procutil
stringutilc                6    U R                   " SUS-   U-   /UQ76 $ N   merge-tools   .)configuitoolpartargss       5/usr/lib/python3/dist-packages/mercurial/filemerge.py_toolstrr"   +   s!    99^TD[4%7?$??    c                6    U R                   " SUS-   U-   /UQ76 $ r   )
configboolr   s       r!   	_toolboolr&   /   s!    ==t);CdCCr#   c                2    U R                  SUS-   U-   5      $ r   )
configlist)r   r   r   s      r!   	_toollistr)   3   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                  ^    \ rS rSrSrS rS rS rS rS r	S r
S	rS
 rS rS rS rS rSrg)absentfilectxU   zRepresents 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                    Xl         X l        g N_ctx_f)selfctxfs      r!   __init__absentfilectx.__init__\   s    	r#   c                8    SU R                   U R                  4-  $ )Ns   absent file %s@%s)r1   r0   r2   s    r!   	__bytes__absentfilectx.__bytes__`   s    #tww		&:::r#   c                    U R                   $ r.   )r1   r8   s    r!   pathabsentfilectx.pathc   s    wwr#   c                    g r.    r8   s    r!   sizeabsentfilectx.sizef       r#   c                    g r.   r?   r8   s    r!   dataabsentfilectx.datai   rB   r#   c                J    U R                   R                  5       R                  $ r.   )r0   reponullidr8   s    r!   filenodeabsentfilectx.filenodel   s    yy~~&&&r#   Tc                    UR                  5       =(       aI    UR                  5       U R                  5       :H  =(       a!    UR                  5       U R                  5       :H  (       + $ )zFcompare with other file context

returns True if different from fctx.
isabsent	changectxr<   )r2   fctxs     r!   cmpabsentfilectx.cmpq   sK     MMO + DNN$44+		tyy{*
 	
r#   c                    g)Nr#   r?   r8   s    r!   flagsabsentfilectx.flags|   s    r#   c                    U R                   $ r.   )r0   r8   s    r!   rN   absentfilectx.changectx   s    yyr#   c                    gNFr?   r8   s    r!   isbinaryabsentfilectx.isbinary   s    r#   c                    g)NTr?   r8   s    r!   rM   absentfilectx.isabsent   rB   r#   r/   N)__name__
__module____qualname____firstlineno____doc__r5   r9   r<   r@   rD   rI   
_customcmprP   rS   rN   rY   rM   __static_attributes__r?   r#   r!   r+   r+   U   sF    I;' J	
r#   r+   c                z    U[         ;   a  U$ [        XSU5      nUR                  S5      (       a  U$ [        X5      $ )N
   executable   python:)	internalsr"   
startswithfindexternaltool)r   r   cmds      r!   	_findtoolrk      s<    y
2]D
1C
~~j!!
B%%r#   c                ^    U R                  S5      (       a  U $ [        R                  " U 5      $ )Nrf   )rh   r   
shellquote)rj   s    r!   _quotetoolpathrn      s'    
~~j!!
s##r#   c           	     \   S Hp  n[        XU5      nU(       d  M  [        R                  " U[        XS5      5      nU(       d  MB  [        R                  " U[        XS5      -   5      nU(       d  Mn  Us  $    [        XSU5      n[        R                  " [        R
                  " U5      5      $ )N)s   regkeys	   regkeyalts   regnames	   regappendre   )r"   r   	lookupregr   findexe
expandpath)r   r   knkpexes         r!   ri   ri      s    'Rr"NN1hr<=1  Xb%E!EFAq ( 2]D
1CDOOC011r#   c                  ^^^^ TR                  SS5      mSU4S jjmS mUUUU4S jnTR                  SS5      nU(       a8  [        TU5      nU(       a  T" U5      (       d  gU(       a  U[        U5      4$ Xw4$ [        R
                  R                  S	5      n	U	(       a  U(       a  T" U	5      (       d  gX4$ U=(       a    Tn
TR                  S
5       H  u  p[        R                  " U R                  SU/5      nU" U5      (       d  M7  U" XXJU5      (       d  MH  U(       aT  T" USSS9(       dG  TR                  [        S5      [        R                  " U5      [        R                  " U5      4-  5        [        TU5      nU[        U5      4s  $    0 n[        5       nTR                  S5       H^  u  nnUR                  S5      S   nUU;  a  [!        [#        TUS5      5      UU'   [%        TUS5      (       d  MM  UR'                  U5        M`     UR)                  5       n[+        UR-                  5        VVs/ s H  u  nnX;  d  M  U* U4PM     snn5      nTR                  SS5      nU(       a4  U" UX$X55      (       a%  UU;  a  U(       d  UU4$ UR/                  SS U45        UR1                  S5        U H1  u  nnU" US XCU5      (       d  M  [        TU5      nU[        U5      4s  $    U(       d  U(       d  U(       a5  U(       d-  [3        U5      (       a  TR                  [        S5      U-  5        ggs  snnf )N   merges   strict-capability-checkc                   > U [         ;   a+  U=(       a"    [         U    R                  R                  U5      $ [        TX5      $ r.   )rg   capabilitiesgetr&   )r   
capabilitystrictr   s      r!   hascapability _picktool.<locals>.hascapability   s8    9Jio::>>zJJT..r#   c                V    U [         ;   =(       a    [         U    R                  [        :H  $ r.   )rg   	mergetypenomerger   s    r!   
supportscd_picktool.<locals>.supportscd   s!    y IYt_%>%>'%IIr#   c                p  > U nU(       a  [        S5      X4-  n[        T	U 5      (       dD  U(       a  T	R                  [        S5      U-  5        g
T	R                  [        S5      U-  5         g
U(       a-  T" U ST5      (       d  T	R                  [        S5      U-  5        g
U(       a-  T" U ST5      (       d  T	R                  [        S5      U-  5        g
U(       a  T" U 5      (       d   g
[        R
                  " 5       (       d0  [        T	U S5      (       a  T	R                  [        S5      U-  5        g
g	)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   rk   warnnoter   guir&   )
r   patsymlinkbinarychangedeletetmsgr~   strictcheckr   r   s
         r!   check_picktool.<locals>.check   s   +,{:DT"":;dBC  :;dBC  ]4[IIGGA89D@A  M$	;GGGGA67$>?  *T"2"2 
 	 Ib$$?$?GGA12T9:  r#      uis
   forcemerge)s   :promptNs   HGMERGEs   merge-patternsr#   r   T)r}   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   disabled)Ns   hgmerges   no tool found to merge %s
)s   :mergeN)F)r%   r   rk   rn   r   environr{   configitemsr   rootr   r   r   bytestrsetsplitintr"   r&   addkeyssorteditemsinsertappendlen)rG   r   r<   r   r   r   r   forcetoolpathhgmerge	binarycapr   r   mftoolsdisabledrt   vtnamesru   uimerger~   r   r   s    `                    @@@r!   	_picktoolr      s   --*DEK/
J 2 IIe]+ER'
8 4 4#~h788 ~% "":.G
7 3 3#%%
 &;I^^$56	[[C#/d88d\JJmD)DI;  ''-x/?/?/EFG !T*H.233 7" EuH~.1GGDM!E>8B;78E!HRK((LLO / JJLE#(;;=I=aD4H1"d=IE iix(G $>>e#L))LLT7O,	LL#$1D'<88 Q'H~h/00  &LE

GGA45<=- 	Js   =L>
	L>
c                <    SU ;   a  gSU ;   a  gSU ;   a  gSU ;   a  gg)zGuess the EOL type of a file    Ns   
      
r?   rD   s    r!   _eoltyper     s-    }$}}r#   c                    [        UR                  5       5      nU(       aW  [        R                  " U 5      n[        U5      nU(       a.  UR	                  XB5      nXS:w  a  [        R
                  " X5        gggg)z/Convert EOL markers in a file to match origfileN)r   rD   r   readfilereplace	writefile)filebackuptostylerD   stylenewdatas         r!   	_matcheolr   $  s]    v{{}%G}}T"ll52Gt-   r#      promptc           	        U R                   nUR                  R                  5       n[        R                  " U 5      nUR                  R                  5       R                  5       (       a  [        R                  " S5      e[        UR                  UR                  /5      n	U" U5      U	S'    UR                  R                  5       (       a!  UR                  [        U	-  S5      n
/ SQU
   nOeUR                  R                  5       (       a!  UR                  [        U	-  S5      n
/ SQU
   nO%UR                  [        S5      U	-  S5      n
/ SQU
   nUS:X  a  [!        XX#XE5      $ US:X  a  [#        XX#XE5      $ US	:X  a  [%        XX#XE5      $ g! [        R&                   a!    UR)                  S
5        [%        XX#XE5      s $ f = f)zbAsks 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   rO   r<   r   getuipathfnrN   
isinmemoryr	   InMemoryMergeConflictsError
partextraslabelrM   promptchoice_localchangedotherdeletedmsg_otherchangedlocaldeletedmsgr   _iother_ilocal_ifailResponseExpectedwrite)rG   mynodelocalotherbasetoolconfr   fduipathfnpromptsindexchoices               r!   _ipromptr   0  s    
B		B""4(H zz((**//>
 	
 %++u{{34Gb\GEN B::  OO$@7$JANE8?FZZ  ""OO$@7$JANE8?F
 OO:  
E 9?FX4tFFx4tFF}$$dEE %!! B
dE$AABs   -B7F %F 8F 2G Gr   c                :    SUR                   R                  5       4$ )z=Uses the local `p1()` version of files as the merged version.r   )rO   rM   rG   r   r   r   r   r   s         r!   r   r   d  s     ejj!!###r#   r   c                H   UR                   R                  5       (       a)  [        UR                   5      R                  5         SnSU4$ [        UR                   5      R	                  UR                   R                  5       UR                   R                  5       5        SnSU4$ )z=Uses the other `p2()` version of files as the merged version.TFr   )rO   rM   _underlyingfctxifabsentremover   rD   rS   )rG   r   r   r   r   r   deleteds          r!   r   r   j  s     zz

+224 g:	 	 

+11JJOOuzz//1	
 g:r#   s   failc                    UR                   R                  5       (       aU  [        UR                   5      R                  UR                   R	                  5       UR                   R                  5       5        g)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)rO   rM   r   r   rD   rS   r   s         r!   r   r   y  sP     zz

+11JJOOuzz//1	
 r#   c                r    U R                  5       (       a!  U R                  5       U R                  5          $ U $ )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.
rL   )filectxs    r!   r   r     s2    
   "7<<>22r#   c                   [         R                  " U R                  5       5      (       aY  [        S5      U R                  R                  5       -  nUR                  [        S5      U-  5        [        R                  " U5      eg)z verifies that text is non-binarys   %s looks like a binary file.s   warning: %s
N)	r   r   textr   rO   r<   r   r	   Abort)inputr   msgs      r!   _verifytextr     s_    &&/05::??3DD
"#c)*kk# 'r#   c                F   Uu  pVpxn	U(       d>  UR                   R                  5       (       d  UR                   R                  5       (       a  gU R                  n
/ SQn [        XSU(       + 5      nU(       a  SnUS	:X  a  S
nOUS:X  a  Sn[        S XU4 5       5      (       a  g[        R                  " XX/S9u  nnU(       a  X;   a4  UR                   R                  UUR                   R                  5       5        U(       d  U
R                  S5        gg! [        R
                   av    [        XSS5      R                  5       nX;  aR  SR                  U Vs/ s H  nSU-   S-   PM     Os  snf sn5      n[        R
                  " [        S5      X\U4-  5      e GN/f = f)Nr   )s   keep   keep-merge3   keep-mergediffs   premerger#      ,    's6   %s.premerge not valid ('%s' is neither boolean nor %s)rx   r   	   mergediffr      merge3c              3  j   #    U  H)  n[         R                  " UR                  5       5      v   M+     g 7fr.   )r   r   r   ).0r   s     r!   	<genexpr>_premerge.<locals>.<genexpr>  s(      
9MJejjl++9Ms   13)modes    premerge successful
r   )rO   rM   r   r&   r	   ConfigErrorr"   lowerjoinr   anyr   r   rS   debug)rG   r   r   r   r   r   r   r   r   scriptfnr   	validkeeppremerger   _validr   merged_text	conflictss                     r!   	_premerger    s   08-DFX%**%%''5::+>+>+@+@	B<I	R{J? ((D'D 
:?u9M
 
 
 !,!8!8"
Y H1 JJ[%***:*:*<=HH./;  Bk37==?$ZZ) D)QD) DEF##KL6*+  %s   D AF E,
+1F F c                   Uu  pgpn
[         R                  " U 5      nU	(       a=  U R                  R                  [	        S5      Xk" UR                  5       5      4-  5        gUR                  5       (       d  UR                  5       (       a=  U R                  R                  [	        S5      Xk" UR                  5       5      4-  5        gg)Ns2   warning: internal %s cannot merge symlinks for %s
Fs@   warning: internal %s cannot merge change/delete conflict for %s
T)r   r   r   r   r   r<   rM   )rG   r   fcdfcofcar   r   r   r   r   r   r   s               r!   _mergecheckr	    s    08-DFX""4(HDEXchhj)*+	
 
||~~% Xchhj)*	+	
 r#   c                Z   U R                   nUR                  SS5      n [        X5        [        X55        [        X%5        [        R                  " UUUUUS9u  pxUR                  R                  XqR                  R                  5       5        SUS4$ ! [        R                   a     gf = f)a0  
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' or 'union-other-first' which
suppresses the markers.s   experimentals   relaxed-block-sync-merge)r   relaxed_syncTF)TTF)	r   r%   r   r   rO   r   rS   r	   r   )	rG   r   r   r   r   r   r  r  r  s	            r!   _merger    s     
B==2MNL&EDE "-!8!8%"
 	

jj&6&6&89Y%% ;; ! !s   !B B*)B*   unionsJ   warning: conflicts while merging %s! (edit, then use 'hg resolve --mark')
)precheckc                    [        XX4S5      $ )z
Uses the internal non-interactive simple merge algorithm for merging
files. It will use both local and other sides for conflict regions by
adding local on top of other.
No markers are inserted.r  r  rG   r   r   r   r   r   r   s          r!   _iunionr         $uH55r#      union-other-firstc                    [        XX4S5      $ )z,
Like :union, but add other on top of local.r  r  r  s          r!   _iunion_other_firstr    s     $u,@AAr#   rx   c                    [        XX4S5      $ )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.rx   r  r  s          r!   _imerger    r  r#   r   c                    [        XX4S5      $ )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     $uI66r#   s   merge3-lie-about-conflictsr#   c                 (    [        U 0 UD6u  p#nUSU4$ rX   )r  )r    kwargsb1junkb2s        r!   _imerge3alwaysgoodr   ?  s%     T,V,LBb ub=r#   r   c                    [        XX4S5      $ )aS  
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"  R  s      $uL99r#   s   merge-localc                    [        XX4S5      $ )z_
Like :merge, but resolve all conflicts non-interactively in favor
of the local `p1()` changes.r   r  r  s          r!   _imergelocalr$  e      
 $uH55r#   s   merge-otherc                    [        XX4S5      $ )z_
Like :merge, but resolve all conflicts non-interactively in favor
of the other `p2()` changes.r   r  r  s          r!   _imergeotherr'  m  r%  r#   s   tagmergesj   automatic tag merging of %s failed! (use 'hg resolve --tool :merge' or another merge tool of your choice)
c                z    [         R                  " XR                  UR                  UR                  5      u  pxXxS4$ )z7
Uses the internal tag merge algorithm (experimental).
F)r   mergerO   )	rG   r   r   r   r   r   r   successstatuss	            r!   
_itagmerger,  u  s/     nnT::uzz499MOGE!!r#   s   dumpT)r   r   c                `   [        XR                  5      nUR                  R                  5       nSSKJn	  [        UR                  U	R                  5      (       a  [        R                  " S5      e[        R                  " US-   UR                  R                  5       5        U R                  US-   UR                  R                  5       UR                  R                  5       5        U R                  US-   UR                  R                  5       UR                  R                  5       5        g)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)_workingpathrO   r<    r/  
isinstanceoverlayworkingfilectxr	   r   r   r   decodeddatawwriterD   rS   )
rG   r   r   r   r   r   r   ar   r/  s
             r!   _idumpr7    s     	T::&A		B%**g;;<<//?
 	
 	NN1y=%**"8"8":;KKY

 15::3C3C3EFKKXtyy~~/1BCr#   s	   forcedumpc           	         [        XX#XEU5      $ )zK
Creates three versions of the files as same as :dump, but omits premerge.
)r7  r  s          r!   
_forcedumpr9    s    
 $dfEEr#   c                .    [         R                  " S5      e)Ns5   in-memory merge does not support external merge tools)r	   r   r  s          r!   
_xmergeimmr;    s     
+
+@ r#   c	                   U R                  SS5      n	U	(       d  g [        R                  n
UR                  5       [	        U5      UR                  5       U
" UR                  5       U[	        U5      [        S5      SUR                  5       ;   US   S.5      U
" UR                  5       U[        S5      SUR                  5       ;   US   S	.5      U
" UR                  5       U[        S
5      SUR                  5       ;   US   S	.5      UUS.n[        R                  " U	5      n	[        R                  " X5      n[        R                  " X	[        R                  US9nU R                  UR!                  U5      5        g )N   command-templatess   pre-merge-tool-outputr      l   HG_MY_LABEL)   ctx   fctx   node   name   islink   label   base   HG_BASE_LABEL)r@  rA  rC  rD  rE  r      HG_OTHER_LABEL)r@  rB  s   pathr   rF  r   s   toolpaths   toolargsdefaults	resources)r   r   mappingdictrN   r   r<   r   rS   r   unquotestringr
   templateresourcesmaketemplaterr   keywordsr+  renderdefault)r   rG   r   fclfcbr  envr   r    tmplrL  propstresr   s                 r!   _describemergerX    sV   99)+CDD**KVV8399;.n-	
 7399;../
 8399;./0
 C"EJ ""4(D &&r0D
:..$	A IIaooe$%r#   c                	   UR                   nUR                   nUR                   n	Uu  ppn[        R                  " U 5      nUR                  5       (       d  UR                  5       (       a=  U R                  R                  [        S5      X" UR                  5       5      4-  5        g[        X5      n[        U R                  U
S5      nSU	R                  5       U	R                  5       4SUR                  5       UR                  5       4/nSnSU;   al  UnUR                  5       nUR                  S5      (       a"  [        R                  R                  U5      u  nnUR                  S	UUR                  5       45        [!        U5       nUS S
 u  nn[#        U5      S:X  a  US
   nS nUR                  5       [%        U5      [%        UR'                  5       R)                  5       5      [%        U	R'                  5       R)                  5       5      SUR+                  5       ;   SUR+                  5       ;   SU	R+                  5       ;   U" U5      U" U5      U" U5      S.
nU R                  nUUUUU" U5      U" U5      U" U5      S.n[,        R.                  " SUUS 5      n[1        UU
S5      (       a<  U R                  R3                  [        S5      X" UR                  5       5      4-  5        UcT  US-   U-   nU R                  R5                  SU-  5        [7        UXXyUUUU5	        UR9                  UU R:                  USS9nOU R                  R5                  SX4-  5        Sn SSKJn  S[@        RB                  " U
5      -  n URE                  UU 5      n![M        U![@        RB                  " U5      S 5      n"U"c#  [H        RJ                  " [        S5      X4-  5      e[N        RP                  " U5      n#SSKJ)n$  U$RU                  UU S UU"SU#0S!5      u  n%n&U&(       a  SnU R                  R5                  S"U-  5        S!US#4sS S S 5        $ ! [F         a#    [H        RJ                  " [        S5      U-  5      ef = f! , (       d  f       g = f)$Ns7   warning: %s cannot merge change/delete conflict for %s
)Fr   Ns   argsrF  r   r#   s   $outputs   .origr   r      c                r    U R                   (       a  SU R                  U R                   4-  $ U R                  $ )Ns   %s: %s)label_detailr   )r   s    r!   format_label_xmerge.<locals>.format_label  s/    !! EKK1C1C#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?  rH  rG  )r   rF  r   s   outputs
   labellocals
   labelothers	   labelbase   \$c                V    [         R                  " [        R                  " U 5      5      $ r.   r   rm   r   	localpathss    r!   <lambda>_xmerge.<locals>.<lambda>2  s    h))$..*;<r#   r   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   )
extensionsz
hgmerge.%ss&   loading python merge script failed: %ss   %s does not have function: %s)hookrx   Ts   merge tool returned: %d
F)+rO   r   r   rM   r   r   r   r<   r0  r"   r4  endswithossplitextr   rD   _maketempfilesr   r   rN   noderS   r   interpolater&   r+  r   rX  systemr   r1  rj  r   sysstrloadpath	Exceptionr	   r   getattrr   
shellsplitrk  
pythonhook)'rG   r   r   r   r   r   r   r  r  r  r   r   r   r   r   r   rb  r    filesoutpathlocaloutputpathext	temppathsbasepath	otherpathr]  rT  r   r   rj   rrj  mod_namemodmergefnargslistrk  retraiseds'                                          r!   _xmerger    s'   
**C
**C
))C08-DFX""4(H
||~~IJXchhj)*+	
 T'IDGGT7+D 
#((*coo/0	388:s01E GT ++-##H--#%77#3#3O#D OSh?@		)'m)y>Q!!I	# 
 =#CMMO$8$8$:;"3==?#7#7#9:!SYY[0 $		 3#syy{2(/+E2*40
 WW  '.'.&t,
 <	
 Rv&&GGNN89#((*-./ T/D(CGGMM7#=>2tSsC4P		CL  A GGMM9X<PP A	('(//$*?? ))(H=
 c8??8#<dCGkk678:NN   **40H//D(Hg7JDKC 2Q67Q~e 
	~  kk?@8K  
	s&   GQ<'1QB*Q<-Q99Q<<
R
c                    U R                   R                  5       nUR                  5       c  UR                  5       nSU0nUR	                  U5      n[
        R                  " U5      U l        g)zAApplies the given template to the ctx and stores it in the input.Nr@  )rO   rN   rp  p1rQ  r   	firstliner\  )r   templater3   rV  templateresults        r!   _populate_label_detailr  a  sW    
**


 C
xxzffhSME++E2N#--n=Er#   c                (   U R                   nUR                  SS5      nUb  [        X2SU5      n[        R                  " U5      n[
        R                  " X05      n[
        R                  " X4[        R                  US9nU H  n[        Xv5        M     g)z?Populates the label details using the conflict marker template.r=  s   mergemarkerNs   mergemarkertemplaterI  )r   r   r"   r   rM  r
   rN  rO  r   rP  r  )rG   inputsr   r   r  rW  rU  r   s           r!   _populate_label_detailsr  l  s    	Byy-~>HB&<hG&&x0H&&r0D""
z22dD u+ r#   c                4    U c  SSS.$ SU S   -  SU S   -  S.$ )z{Return a dictionary of extra labels for use in prompts to the user

Intended use is in strings of the form "(l)ocal%(l)s".
r#   )r>     os    [%s]r   r   r?   )labelss    r!   r   r   |  s=    
 ~
 	
 "" r#   c                   UR                  5       (       a  gSSKJn  [        X#R                  5      (       aX  [
        R                  " S5      u  pE[        R                  " US5       nUR                  UR                  5       5        SSS5        OF[        R                  " XUR                  5       5      n[        X5      n[        R                   " Xu5        UR#                  XPS9$ ! , (       d  f       N= f)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)rG   )rM   r1  r/  r2  r3  r   mkstemprm  fdopenr   rD   r   
backuppathr<   r0  r   copyfilearbitraryfilectx)rG   r   r  r/  r   r   r4   r6  s           r!   _makebackupr    s     ||~~ #4455%%&89
YYr4 AGGCHHJ !  ##Bchhj9#a ##F#66 ! s   & C$$
C2c              #     ^#    [         R                  " SS9mU4S jn/ nU  H  u  p4nUR                  U" X4U5      5        M       Uv   [        R                  " T5        g! [        R                  " T5        f = f7f)zqCreates a temporary file for each (prefix, path, data) tuple in `files`,
so an external merge tool may use them.
s   hgmerge-)prefixc                  > [         R                  R                  U5      u  p4S[         R                  R                  U5      U 4-  n[         R                  R	                  TU5      nU(       a  Xd-  n[
        R                  " Xb5        U$ )Ns   %s~%s)rm  r<   rn  basenamer   r   r   )r  r<   rD   fullbaser|  prenametmproots          r!   maketempfrompath(_maketempfiles.<locals>.maketempfrompath  sf    ((."''**84f==ww||GS)KDt"r#   N)r   mkdtempr   shutilrmtree)ry  r  
temp_filesr  r<   rD   r  s         @r!   ro  ro    sl     
 k2G J#d*6>? $ggs   AA;A  	A; A88A;c           
     
   U R                   nUR                  5       n	[        R                  " U 5      n
U
" U	5      nUR	                  5       =(       d'    UR	                  5       =(       d    UR	                  5       nSUR                  5       UR                  5       -   ;   nUR                  5       =(       d    UR                  5       n[        XXX5      u  nnSnU[        ;   a$  UR                  S5      (       a  U[        S5      S nU(       a  UR                  S5      (       at  SnUR                  S5      S:  a0  US	S R                  SS
5      u  nnU(       d  SnSU;   d  SU;   a  SnOSnU(       a"  [        R                  " [        S5      U-  5      eWnUR!                  SUU["        R$                  " U5      ["        R$                  " U5      ["        R$                  " U5      4-  5        U[        ;   a0  [        U   nUR&                  nUR(                  nUR*                  nSnO7UR-                  5       (       a  [.        nO[0        n[2        n[        S5      nSnSnUUXU4nU(       d  SS/n[        U5      S:  a  UR5                  S5        [6        R8                  " XGS   5      n[6        R8                  " XWS
   5      n[6        R8                  " XgS   5      nU[:        :X  a  U" U UUUUU5      $ X5R                  5       :w  a;  UR=                  [        S5      U
" U5      U
" UR                  5       5      U4-  5        OUR=                  [        S5      U-  5        UR!                  SXEU4-  5        U(       aW  U" XXEUU5      (       dG  U(       a?  UR-                  5       (       a  [        R>                  " S5      eURA                  UU-  5        g[C        XU5      nS
n URE                  SS5      nU(       a  [G        XS5      n OUn U[2        :X  a}  [I        U UUU5        Sn!U S:w  a  Un!US:w  d  U S:w  a  [K        U UUU/U!S9  [M        U UUUU5      nU(       d   US4U(       d  Ub  URO                  5         $ $ $ SUl(        SUl(        SUl(        U S:w  a  [K        U UUU/US9  U" U UUUUUU5      u  n"nn#U"(       a  [S        U UXUU5      nU(       aQ  U(       a?  UR-                  5       (       a  [        R>                  " S5      eURA                  UU-  5        [U        U5        UU#4U(       d  Ub  URO                  5         $ $ $ ! U(       d  Ub  URO                  5         f f f = f)ap  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   internalrf   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   rZ  rF  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   basicr   )+r   r<   r   r   rY   rS   rM   r   rg   rh   r   countrsplitr	   r   r   r   r   r   r   	onfailurer  r   r;  r  	fullmerger   r   
MergeInputr   r+  r   r   r  r   r"   _run_partial_resolution_toolsr  r  r   r\  _check_onfilemergefailure)$rG   wctxr   origr  r  r  r  r   r   r   fduipathr   r   r   r   r   r   invalidsyntaxscriptfuncr   r  r  
isexternalr   r   r   r   r   r  internalmarkerstylemarkerstyle	labeltool	needcheckr   s$                                       r!   	filemerger    s    
B	B""4(H|H\\^?s||~?FciikCIIK//G<<>3S\\^LtWKND(HyT__\::C$&'H''
33>>$1$'|224;FH $ DH$4 $ M++a ?@8KLLHHKV$W%\*
	
	 yNN	NN	==
??DD	-.	
Xv8HH%
6{Qg""3q	2E""3q	2E!!#ay1DG
 	
 xxz
		*+~x
3X>?	

 			!O$x/0HH,#>?shGG  77G  GGI()3'F	AF ii?"2_=K-K	!)$udC Ih& !	"h.+2I'5%.Y A %xH V'MMO (qC "&E!%E $D("#D5%*>TJ $!
	1g tQ#v6A??$$;;+ 
 	H,-#'zV'MMO (qqV'MMO (qs   A=T? 6B,T? ?Uc                B   U R                   nUR                  SS5      (       a  g/ n[        5       nSnUR                  U5       GH  u  pUR	                  S5      S   n
X;   a  M!  UR                  USU
-  / 5      nSnU(       aX  [        R                  " U R                  S	XR                  R                  5       S
9nU" UR                  R                  5       5      nU(       d  M  UR                  USU
-  5      (       a  M  UR                  USU
-  S5      nUR                  USU
-  U
5      nUR                  USU
-  5      nUR                  XUU45        GM     U(       d  gUR                  5         SUR                  R                  5       UR                  5       4SUR                  R                  5       UR                  5       4SUR                  R                  5       UR                  5       4/n[!        U5       nUu  nnnU H  u  pnn["        R$                  " U5      nUUUS.n[&        R(                  " SUUS 5      nSUU4-  nUR+                  UU R                  SS9nU(       a  [,        R.                  " SU
U4-  5      e[&        R0                  " U5      n[&        R0                  " U5      nUU:X  d  M    O   UR3                  W5        UR3                  [&        R0                  " U5      5        UR3                  W5        SSS5        g! , (       d  f       g= f)zCRuns partial-resolution tools on the three inputs and updates them.rx   s   disable-partial-toolsNs   partial-merge-toolsr   r   s   %s.patternsTr#   )r3   s
   %s.disables   %s.orders   %s.executables   %s.argsr   rF  r   )r   rF  r   r_  c                V    [         R                  " [        R                  " U 5      5      $ r.   ra  rc  s    r!   re  /_run_partial_resolution_tools.<locals>.<lambda>  s    (--dnnQ.?@r#   s   %s %ss   partial-mergetool)rh  ri  s)   partial merge tool %s exited with code %d)r   r%   r   r   r   r(   r   r   rO   rN   r<   	configintr   r   sortr   ro  r   rm   r   rq  rr  r	   
StateErrorr   set_text)rG   r   r   r   r   r   seensectionrt   r   r  patternsis_matchmorder
executabler    ry  r}  rb  r~  r  rj   r   r  
local_text
other_texts                              r!   r  r  u  s   	B	}}X788E5D$Gw'wwt}Q<==.4*?D		3jj.B.B.DA *+H8}}Wmd&:;;LL+*<a@E7,<t,CTJJ99Wj4&78DLL%z489# (& 	JJL 
5::??$ejjl3	$)).."DIIK0	5::??$ejjl3E 
	))2&	8Y-2)ET%%j1C#!#G
 ##@	D c4[(C		#4999M	NA&&@D!9L  y1Jy1JZ'1 .34 	z"dmmH-.z"? 
		s   >B:L<AL
Lc                 D    [        S5      n [        R                  " U 5      e)Ns0   merge halted after failed merge (see hg resolve))r   r	   InterventionRequired)r   s    r!   
_haltmerger    s    
?
@C

$
$S
))r#   c                    U R                  SS5      nUS:X  a+  [        S5      nU R                  US5      S:X  a
  [        5         US:X  a  [        5         g g )Nrx   s
   on-failurer   s,   continue merge operation (yn)?$$ &Yes $$ &Nor   r   s   halt)r   r   r   r  )r   actionr   s      r!   r  r    sO    YYx/F?@??3"a'L r#   c                `    [        [        R                  " SU [        R                  5      5      $ )Ns   ^([<>=+|-])\1{6}( .*)$)boolresearch	MULTILINEr   s    r!   hasconflictmarkersr    s*    
 
		&LL	
 r#   c                   UR                  5       n[        R                  " U 5      nU(       dA  [        X#S5      (       d  S[	        X#S5      ;   a   [        UR                  5       5      (       a  SnSnS[	        X#S5      ;   a-  SnUR                  [        S5      U" U5      -  S5      (       a  SnU(       dl  U(       de  [        X#S	5      (       d  S
[	        X#S5      ;   aD  UbA  UR                  U5      (       d+  UR                  [        S5      U" U5      -  S5      (       a  SnUb&  [        X#S5      (       a  [        [        X5      U5        U$ )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)r<   r   r   r&   r)   r  rD   r   r   rP   r   r0  )	rG   r  r   r   r  r   r   r   checkeds	            r!   r  r    s2   	B""4(H"-..9Rx88chhj))AGIb11??ABrl
 

 A b00Yr:: cggfoo&
 2,   i)<<,t)62Hr#   c                @    U R                  UR                  5       5      $ r.   )wjoinr<   )rG   r3   s     r!   r0  r0    s    ::chhj!!r#   c           	        UR                   R                  5        H  u  p4SU-   nU[        U'   U[        SU-   '   U[        U'   [	        UR
                  R                  5        VVs/ s H  u  pgU(       d  M  UPM     snn5      nU(       d  Mr  SSR                  U5      -  n	UR                  [        R                  " SU	-  5      -   Ul        M     [        S5        [        S5        [        S5        g	s  snnf )
z4Load internal merge tool from specified registrarobjr  r  s       (actual capabilities: %s)r   s   

%ss*       (actual capabilities: binary, symlink)s!       (actual capabilities: binary)s"       (actual capabilities: symlink)N)_tabler   rg   internalsdocr   rz   r   ra   r   rs  r   )
r   extnameregistrarobjr  r  fullnamert   r   rz   capdescs
             r!   loadinternalmerger    s    "))//1
$;"	()-	,%&!%XT->->-D-D-FL-FTQ!q-FLM<6: G  <<(//)g:M*NNDL 2" 34 *+ +,# Ms   %C26C2r.   )V
__future__r   
contextlibrm  r  r  i18nr   rp  r   r   r1  r   r	   r
   r   r   r   r   r   r   r   r   r   r   utilsr   r   r"   r&   r)   rg   r  internalmergeinternaltoolr   	mergeonlyr  r   r   r+   rk   rn   ri   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r   r"  r$  r'  r,  r7  r9  r;  rX  r  r  r  r   r  contextmanagerro  r  r  r  r  r  r  r0  r  valuesi18nfunctionsr?   r#   r!   <module>r     s   #  	 	  
    @D= 	&&( 

""	""	  !-    !.  1 1h&$2nb
	. i!0B "0Bf h $ !$
 h  ! gw
  
)X*&> 	2 66 	2 BB 	2 66 	2 77 !	

 	2 :: ni+>6 ?6 ni+>6 ?6 	""" gyt< =8 lIdDAF BF3&lod>, "7<  0nbF#R*
,^"-: $l +   "r#   