
    q&f,                     @    d dl mZ d dlmZmZ d	dZd Zd Zd Z	d Z
y)
   )_)tagsutilc                     t        j                  | |||dd      d   }|j                         D ]  \  }}|r	|D ]  }d|d<   	  |S )a  read the .hgtags file into a structure that is suitable for merging

    Depending on the keeplinenums flag, clear the line numbers associated
    with each tag. This is done because only the line numbers of the first
    parent are useful for merging.
    NT)fnrecodecalcnodelinesr   )tagsmod_readtaghistitems)	uirepolinesr   keeplinenumsfiletagstagnametaginfoels	            4/usr/lib/python3/dist-packages/mercurial/tagmerge.pyreadtagsformerger   R   sh     ##
D%Bt4	H %NN,  1 O    c                    d}| D ]  \  }}|}| n |d| D cg c]  }|d   	 c}ggS || d   d<   |g gg}|}| D ]>  \  }}|||z
  dkD  r|j                  |g g       |d   d   j                  |       |=|}@ |S c c}w )a  
    Group nearby nodes (i.e. those that must be written next to each other)

    The input is a list of [node, position] pairs, corresponding to a given tag
    The position is the line number where the node was found on the first parent
    .hgtags file, or None for those nodes that came from the base or the second
    parent .hgtags files.

    This function groups those [node, position] pairs, returning a list of
    groups of nodes that must be written next to each other because their
    positions are consecutive or have no position preference (because their
    position is None).

    The result is a list of [position, [consecutive node list]]
    N    r   )append)tagnodesfirstlinenumhexnodelinenumr   groupednodesprevlinenums          r   grouptagnodesbyliner"   c   s      L$ # 1"11233!HQKN!2&'LK$ "7[#81#<".R""7+!K"  2s   A?c                    t        |j                               D ]  \  }}t        |      ||<    d }g }|j                         D ]   \  }}|D ]  } ||d   |      |d<    ||z  }" |j                  d        dj	                  |D cg c]
  \  }}|s	| c}}      }	| j                  |	dz   | j                                yc c}}w )al  
    write the merged tags while trying to minimize the diff to the first parent

    This function uses the ordering info stored on the merged tags dict to
    generate an .hgtags file which is correct (in the sense that its contents
    correspond to the result of the tag merge) while also being as close as
    possible to the first parent's .hgtags file.
    c                 T    dj                  | D cg c]	  }d||fz   c}      S c c}w )N   
s   %s %s)join)tlisttnamer   s      r   taglist2stringz'writemergedtags.<locals>.taglist2string   s)    zzeL78w&66LMMLs   %r   c                     | d   dS | d   S )Nr   r    )xs    r   <lambda>z!writemergedtags.<locals>.<lambda>   s    qt| 1 r   )keyr%   N)listr   r"   sortr&   writeflags)
fcd
mergedtagsr(   taglistr)   	finaltagsr   blockrankmergedtagstrings
             r   writemergedtagsr:      s     z//12 9w/8
59
N I!'') t 	7E%eAh6E!H	7T	 NN=N> jj!K:4d$!KLOIIo%syy{3 "Ls   
C
C
c                 J   |s| S | s|S | d   d   }|d   d   }||k7  rt        |       t        |      k(  ryt        |       t        |      k\  r| |}}n|| }}t        |      }t        t        |            D ]%  }||   d   ||   d   k7  r|} n| |   d   ||   d<   ' |||d z   S )z
    merge the nodes corresponding to a single tag

    Note that the inputs are lists of node-linenum pairs (i.e. not just lists
    of nodes)
    r   r   Nr   )lenrange)p1nodesp2nodesp1currentnodep2currentnodehrnodeslrnodes	commonidxns           r   singletagmergerF      s      BKNMBKNM%#g,#g,*F 7|s7|#"G"G GI3w<  &1:a=GAJqM)I
1
1	& WYZ(((r   c           	         | j                   }t        || |j                         j                         dd      }t        || |j                         j                         dd      }t        || |j                         j                         dd      }t	        |      }t        ||f      D ]q  \  }	}
t	        |
      }||z
  }|D ]W  }||   |
|<   |
|   d   d   | j                  j                  k7  s.|
|   j                  | j                  j                  d	g       Y s g }t        j                  |      }|j                         D ]9  \  }}||vr|||<   ||   }t        ||      }||j                  |       5|||<   ; |rCt        |      }|j                  t        d
      |dj!                  t#        |            fz         yt%        ||       |j'                  t        d             y)z
    Merge the tags of two revisions, taking into account the base tags
    Try to minimize the diff between the merged tags and the first parent tags
    s   p1 tagsT)r   r   s   p2 tagsFs	   base tagsr   r   NsI   automatic .hgtags merge failed
the following %d tags are in conflict: %s
s   , )Tr   s   .hgtags merged successfully
)Fr   )r   r   data
splitlinesset	enumeratenodeconstantsnullhexr   r   sortdictr   rF   r<   warnr   r&   sortedr:   note)r   r3   fcofcar   p1tagsp2tagsbasetags
basetagsetrE   pntagspntagsetpnlosttagsettconflictedtagsr4   r(   r?   r>   mergednodesnumconflictss                        r   merger_      s   
 
B 
D#((*'')jtF 
D#((*'')juF  
D#((*'')lH XJ/0 E	6v;!H, 	EA F1Iay}Q4#5#5#=#==q	  $"4"4"<"<d!CD	EE Nv&J ,,. 	(w
" 'JuU#$Wg6!!%('
5	( >*
? UZZ~(>?@	A	
 C$GGA./0r   N)r   F)i18nr    r   r
   r   r   r"   r:   rF   r_   r+   r   r   <module>rb      s,   V " F!4H+)\8r   