
    6h!-                    N    S SK Jr  SSKJr  SSKJrJr  SS jrS r	S r
S rS	 rg
)    )annotations   )_)tagsutilc           	         [         R                  " XX#SSS9S   nUR                  5        H  u  pgU(       a  M  U H  nSUS'   M
     M     U$ )zread 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   S   sZ     ##
%t4	H %NN,|1  - O    c                   SnU  H  u  p#UnUc  M    O   Uc  SU  Vs/ s H  oDS   PM	     sn//$ XS   S'   U/ //nUnU  HA  u  p#Ub  X6-
  S:  a  UR                  U/ /5        US   S   R                  U5        Uc  M?  UnMC     U$ s  snf )ak  
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]]
Nr   r   )append)tagnodesfirstlinenumhexnodelinenumr   groupednodesprevlinenums          r   grouptagnodesbyliner#   d   s      L$# % 1"11233!QKN!2&'LK$7#81#<".R""7+!K %  2s   Bc                   [        UR                  5       5       H  u  p#[        U5      X'   M     S n/ nUR                  5        H!  u  p&U H  nU" US   U5      US'   M     XV-  nM#     UR                  S S9  SR	                  U VVs/ s H  u  pU(       d  M  UPM     snn5      n	U R                  U	S-   U R                  5       5        gs  snnf )aT  
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                X    SR                  U  Vs/ s H	  nSX!4-  PM     sn5      $ s  snf )N   
s   %s %s)join)tlisttnamer   s      r   taglist2string'writemergedtags.<locals>.taglist2string   s+    zzeLe78w&66eLMMLs   'r   c                    U S   c  S$ U S   $ )Nr   r    )xs    r   <lambda>!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/8
 3
N I!'')E%eAh6E!H 	 * NN=N> jj!K:4d$!KLOIIo%syy{3 "Ls   
C
C
c                V   U(       d  U $ U (       d  U$ U S   S   nUS   S   nX#:w  a  [        U 5      [        U5      :X  a  g[        U 5      [        U5      :  a  XpTOXpT[        U5      n[        [        U5      5       H#  nXG   S   XW   S   :w  a  Un  OX   S   XW   S'   M%     XTU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   singletagmergerI      s      BKNMBKNM%#g,#g,*F 7|s7|#"" GI3w< :a=GJqM)I
1
1	 ! YZ(((r   c           	        U R                   n[        X@UR                  5       R                  5       SSS9n[        X@UR                  5       R                  5       SSS9n[        X@UR                  5       R                  5       SSS9n[	        U5      n[        XV45       Hp  u  p[	        U
5      nX-
  nU HV  nX}   X'   X   S   S   U R                  R                  :w  d  M-  X   R                  U R                  R                  S	/5        MX     Mr     / n[        R                  " U5      nUR                  5        H?  u  nnUU;  a  UUU'   M  UU   n[        UU5      nUc  UR                  U5        M:  UUU'   MA     U(       aC  [        U5      nUR                  [        S
5      USR!                  [#        U5      5      4-  5        g[%        X5        UR'                  [        S5      5        g)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   rI   r?   warnr   r'   sortedr=   note)r   r6   fcofcar   p1tagsp2tagsbasetags
basetagsetrH   pntagspntagsetpnlosttagsettconflictedtagsr7   r)   rB   rA   mergednodesnumconflictss                        r   mergerb      s   
 
B 
#((*'')jtF 
#((*'')juF  
#((*'')lH XJ/0	v;!,A FIy}Q4#5#5#=#==	  $"4"4"<"<d!CD  1 Nv&J ,,.w
" 'JuU#$Wg6!!%('
5 ) >*
? UZZ~(>?@	A	
 C$GGA./0r   N)r   F)
__future__r   i18nr    r   r   r   r   r#   r=   rI   rb   r-   r   r   <module>rf      s/   T # " F!4H+)\8r   